lalashechka commited on
Commit
834c592
1 Parent(s): cc8776c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -20
app.py CHANGED
@@ -40,13 +40,26 @@ def flip_text(prompt, negative_prompt, task, steps, sampler, cfg_scale, seed):
40
  url_sd5 = os.getenv("url_sd5")
41
  url_sd6 = os.getenv("url_sd6")
42
  try:
43
- data = {"inputs":f"{prompt}, 4k photo","options":{"negative_prompt":"[deformed | disfigured], poorly drawn, [bad : wrong] anatomy, [extra | missing | floating | disconnected] limb, (mutated hands and fingers), blurry","width":1024,"height":1024,"guidance_scale":7,"num_inference_steps":35}}
44
- response = requests.post(f'{url_sd5}', json=data)
45
- print(response.text)
46
- print(response.json()['image']['file_name'])
47
- file_name = response.json()['image']['file_name']
48
- photo = f"{url_sd6}{file_name}.png"
49
- return photo
 
 
 
 
 
 
 
 
 
 
 
 
 
50
  except:
51
  with closing(create_connection(f"{url_sd4}", timeout=60)) as conn:
52
  conn.send('{"fn_index":0,"session_hash":""}')
@@ -60,19 +73,6 @@ def flip_text(prompt, negative_prompt, task, steps, sampler, cfg_scale, seed):
60
  photo = Image.open(io.BytesIO(base64.decodebytes(bytes(photo, "utf-8"))))
61
  return photo
62
 
63
- #with closing(create_connection(f"{url_sd3}", timeout=60)) as conn:
64
- # conn.send('{"fn_index":3,"session_hash":""}')
65
- # 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":""}}')
66
- # while True:
67
- # status = json.loads(conn.recv())['msg']
68
- # if status == 'estimation':
69
- # continue
70
- # if status == 'process_starts':
71
- # break
72
- # photo = json.loads(conn.recv())['output']['data'][0][0]
73
- # photo = photo.replace('data:image/jpeg;base64,', '').replace('data:image/png;base64,', '')
74
- # photo = Image.open(io.BytesIO(base64.decodebytes(bytes(photo, "utf-8"))))
75
- # return photo
76
  #except:
77
  # try:
78
  # client = Client("https://prodia-sdxl-stable-diffusion-xl.hf.space")
 
40
  url_sd5 = os.getenv("url_sd5")
41
  url_sd6 = os.getenv("url_sd6")
42
  try:
43
+ with closing(create_connection(f"{url_sd3}", timeout=60)) as conn:
44
+ conn.send('{"fn_index":3,"session_hash":""}')
45
+ 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":""}}')
46
+ while True:
47
+ status = json.loads(conn.recv())['msg']
48
+ if status == 'estimation':
49
+ continue
50
+ if status == 'process_starts':
51
+ break
52
+ photo = json.loads(conn.recv())['output']['data'][0][0]
53
+ photo = photo.replace('data:image/jpeg;base64,', '').replace('data:image/png;base64,', '')
54
+ photo = Image.open(io.BytesIO(base64.decodebytes(bytes(photo, "utf-8"))))
55
+ return photo
56
+ #data = {"inputs":f"{prompt}, 4k photo","options":{"negative_prompt":"[deformed | disfigured], poorly drawn, [bad : wrong] anatomy, [extra | missing | floating | disconnected] limb, (mutated hands and fingers), blurry","width":1024,"height":1024,"guidance_scale":7,"num_inference_steps":35}}
57
+ #response = requests.post(f'{url_sd5}', json=data)
58
+ #print(response.text)
59
+ #print(response.json()['image']['file_name'])
60
+ #file_name = response.json()['image']['file_name']
61
+ #photo = f"{url_sd6}{file_name}.png"
62
+ #return photo
63
  except:
64
  with closing(create_connection(f"{url_sd4}", timeout=60)) as conn:
65
  conn.send('{"fn_index":0,"session_hash":""}')
 
73
  photo = Image.open(io.BytesIO(base64.decodebytes(bytes(photo, "utf-8"))))
74
  return photo
75
 
 
 
 
 
 
 
 
 
 
 
 
 
 
76
  #except:
77
  # try:
78
  # client = Client("https://prodia-sdxl-stable-diffusion-xl.hf.space")