lalashechka commited on
Commit
e626c73
1 Parent(s): c7fa2d8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +42 -35
app.py CHANGED
@@ -37,42 +37,49 @@ def flip_text(prompt, negative_prompt, task, steps, sampler, cfg_scale, seed):
37
  url_sd3 = os.getenv("url_sd3")
38
  url_sd4 = os.getenv("url_sd4")
39
 
40
- print(task)
 
41
 
42
- try:
43
- print('n_1')
44
- with closing(create_connection(f"{url_sd3}", timeout=60)) as conn:
45
- conn.send('{"fn_index":3,"session_hash":""}')
46
- 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":""}}')
47
- while True:
48
- status = json.loads(conn.recv())['msg']
49
- if status == 'estimation':
50
- continue
51
- if status == 'process_starts':
52
- break
53
- photo = json.loads(conn.recv())['output']['data'][0][0]
54
- photo = photo.replace('data:image/jpeg;base64,', '').replace('data:image/png;base64,', '')
55
- photo = Image.open(io.BytesIO(base64.decodebytes(bytes(photo, "utf-8"))))
56
- return photo
57
- except:
58
- try:
59
- client = Client("https://prodia-sdxl-stable-diffusion-xl.hf.space")
60
- result = client.predict(prompt,"[deformed | disfigured], poorly drawn, [bad : wrong] anatomy, [extra | missing | floating | disconnected] limb, (mutated hands and fingers), blurry","sd_xl_base_1.0.safetensors [be9edd61]",25,"DPM++ 2M Karras",7,1024,1024,-1,fn_index=0)
61
- return result
62
- except:
63
- print("n_2")
64
- print(url_sd4)
65
- with closing(create_connection(f"{url_sd4}", timeout=60)) as conn:
66
- conn.send('{"fn_index":0,"session_hash":""}')
67
- 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":""}}')
68
- conn.recv()
69
- conn.recv()
70
- conn.recv()
71
- conn.recv()
72
- photo = json.loads(conn.recv())['output']['data'][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
 
77
 
78
  def flipp():
 
37
  url_sd3 = os.getenv("url_sd3")
38
  url_sd4 = os.getenv("url_sd4")
39
 
40
+ url_sd5 = os.getenv("url_sd5")
41
+ url_sd6 = os.getenv("url_sd6")
42
 
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
+
51
+ #with closing(create_connection(f"{url_sd3}", timeout=60)) as conn:
52
+ # conn.send('{"fn_index":3,"session_hash":""}')
53
+ # 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":""}}')
54
+ # while True:
55
+ # status = json.loads(conn.recv())['msg']
56
+ # if status == 'estimation':
57
+ # continue
58
+ # if status == 'process_starts':
59
+ # break
60
+ # photo = json.loads(conn.recv())['output']['data'][0][0]
61
+ # photo = photo.replace('data:image/jpeg;base64,', '').replace('data:image/png;base64,', '')
62
+ # photo = Image.open(io.BytesIO(base64.decodebytes(bytes(photo, "utf-8"))))
63
+ # return photo
64
+ #except:
65
+ # try:
66
+ # client = Client("https://prodia-sdxl-stable-diffusion-xl.hf.space")
67
+ # result = client.predict(prompt,"[deformed | disfigured], poorly drawn, [bad : wrong] anatomy, [extra | missing | floating | disconnected] limb, (mutated hands and fingers), blurry","sd_xl_base_1.0.safetensors [be9edd61]",25,"DPM++ 2M Karras",7,1024,1024,-1,fn_index=0)
68
+ # return result
69
+ # except:
70
+ # print("n_2")
71
+ # print(url_sd4)
72
+ # with closing(create_connection(f"{url_sd4}", timeout=60)) as conn:
73
+ # conn.send('{"fn_index":0,"session_hash":""}')
74
+ # 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":""}}')
75
+ # conn.recv()
76
+ # conn.recv()
77
+ # conn.recv()
78
+ # conn.recv()
79
+ # photo = json.loads(conn.recv())['output']['data'][0]
80
+ # photo = photo.replace('data:image/jpeg;base64,', '').replace('data:image/png;base64,', '')
81
+ # photo = Image.open(io.BytesIO(base64.decodebytes(bytes(photo, "utf-8"))))
82
+ # return photo
83
 
84
 
85
  def flipp():