lalashechka commited on
Commit
2e45bdb
1 Parent(s): 8c6bc0c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +59 -11
app.py CHANGED
@@ -97,17 +97,65 @@ def flip_text(prompt, negative_prompt, task, steps, sampler, cfg_scale, seed):
97
  photo = Image.open(io.BytesIO(base64.decodebytes(bytes(photo, "utf-8"))))
98
  return photo
99
  except:
100
- with closing(create_connection(f"{url_sd4}", timeout=30)) as conn:
101
- conn.send('{"fn_index":0,"session_hash":""}')
102
- conn.send(f'{{"data":["{prompt}","[deformed | disfigured], poorly drawn, [bad : wrong] anatomy, [extra | missing | floating | disconnected] limb, (mutated hands and fingers), blurry","dreamshaperXL10_alpha2.safetensors [c8afe2ef]",30,"DPM++ 2M Karras",7,1024,1024,-1],"event_data":null,"fn_index":0,"session_hash":""}}')
103
- conn.recv()
104
- conn.recv()
105
- conn.recv()
106
- conn.recv()
107
- photo = json.loads(conn.recv())['output']['data'][0]
108
- photo = photo.replace('data:image/jpeg;base64,', '').replace('data:image/png;base64,', '')
109
- photo = Image.open(io.BytesIO(base64.decodebytes(bytes(photo, "utf-8"))))
110
- return photo
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
111
 
112
  #except:
113
  # try:
 
97
  photo = Image.open(io.BytesIO(base64.decodebytes(bytes(photo, "utf-8"))))
98
  return photo
99
  except:
100
+ try:
101
+ with closing(create_connection(f"{url_sd3}", timeout=30)) as conn:
102
+ conn.send('{"fn_index":3,"session_hash":""}')
103
+ conn.send(f'{{"data":["{prompt}, 4k photo","[deformed | disfigured], poorly drawn, [bad : wrong] anatomy, [extra | missing | floating | disconnected] limb, (mutated hands and fingers), blurry",7.5,"(No style)"],"event_data":null,"fn_index":3,"session_hash":""}}')
104
+ c = 0
105
+ while c < 60:
106
+ status = json.loads(conn.recv())['msg']
107
+ if status == 'estimation':
108
+ c += 1
109
+ time.sleep(1)
110
+ continue
111
+ if status == 'process_starts':
112
+ break
113
+ photo = json.loads(conn.recv())['output']['data'][0][0]
114
+ photo = photo.replace('data:image/jpeg;base64,', '').replace('data:image/png;base64,', '')
115
+ photo = Image.open(io.BytesIO(base64.decodebytes(bytes(photo, "utf-8"))))
116
+ return photo
117
+
118
+ except:
119
+ try:
120
+ with closing(create_connection("wss://ashrafb-arpr.hf.space/queue/join", timeout=60)) as conn:
121
+ conn.send('{"fn_index":0,"session_hash":""}')
122
+ conn.send(f'{{"fn_index":0,"data":["{prompt}"],"session_hash":""}}')
123
+ conn.recv()
124
+ conn.recv()
125
+ conn.recv()
126
+ conn.recv()
127
+ a = conn.recv()
128
+ print(">> A:", a)
129
+ photo = json.loads(a)['output']['data'][0]
130
+ photo = photo.replace('data:image/jpeg;base64,', '').replace('data:image/png;base64,', '')
131
+ photo = Image.open(io.BytesIO(base64.decodebytes(bytes(photo, "utf-8"))))
132
+ return photo
133
+ except:
134
+ with closing(create_connection("wss://ashrafb-arv3s.hf.space/queue/join", timeout=60)) as conn:
135
+ conn.send('{"fn_index":0,"session_hash":""}')
136
+ conn.send(f'{{"fn_index":0,"data":["{prompt}", 0, "No style"],"session_hash":""}}')
137
+ conn.recv()
138
+ conn.recv()
139
+ conn.recv()
140
+ conn.recv()
141
+ a = conn.recv()
142
+ print(">> A:", a)
143
+ photo = json.loads(a)['output']['data'][0]
144
+ photo = photo.replace('data:image/jpeg;base64,', '').replace('data:image/png;base64,', '')
145
+ photo = Image.open(io.BytesIO(base64.decodebytes(bytes(photo, "utf-8"))))
146
+ return photo
147
+
148
+ #with closing(create_connection(f"{url_sd4}", timeout=30)) as conn:
149
+ # conn.send('{"fn_index":0,"session_hash":""}')
150
+ # conn.send(f'{{"data":["{prompt}","[deformed | disfigured], poorly drawn, [bad : wrong] anatomy, [extra | missing | floating | disconnected] limb, (mutated hands and fingers), blurry","dreamshaperXL10_alpha2.safetensors [c8afe2ef]",30,"DPM++ 2M Karras",7,1024,1024,-1],"event_data":null,"fn_index":0,"session_hash":""}}')
151
+ # conn.recv()
152
+ # conn.recv()
153
+ # conn.recv()
154
+ # conn.recv()
155
+ # photo = json.loads(conn.recv())['output']['data'][0]
156
+ # photo = photo.replace('data:image/jpeg;base64,', '').replace('data:image/png;base64,', '')
157
+ # photo = Image.open(io.BytesIO(base64.decodebytes(bytes(photo, "utf-8"))))
158
+ # return photo
159
 
160
  #except:
161
  # try: