lalashechka commited on
Commit
c1df027
·
1 Parent(s): 5fc0193

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +35 -28
app.py CHANGED
@@ -40,34 +40,41 @@ def flip_text(prompt, negative_prompt, task, steps, sampler, cfg_scale, seed):
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
- print("n_2")
59
- print(url_sd4)
60
- with closing(create_connection(f"{url_sd4}", timeout=60)) as conn:
61
- conn.send('{"fn_index":0,"session_hash":""}')
62
- 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":""}}')
63
- conn.recv()
64
- conn.recv()
65
- conn.recv()
66
- conn.recv()
67
- photo = json.loads(conn.recv())['output']['data'][0]
68
- photo = photo.replace('data:image/jpeg;base64,', '').replace('data:image/png;base64,', '')
69
- photo = Image.open(io.BytesIO(base64.decodebytes(bytes(photo, "utf-8"))))
70
- return photo
 
 
 
 
 
 
 
71
 
72
 
73
  def flipp():
 
40
  print(task)
41
 
42
  try:
43
+ data = f'{"inputs": {prompt},"style":"(No style)"}'
44
+ response = requests.post('https://enzostvs-stable-diffusion-tpu.hf.space/api', data=data)
45
+ file_name = response.json()['image']['file_name']
46
+ photo = f"https://huggingface.co/datasets/enzostvs/stable-diffusion-tpu-generations/resolve/main/images/{file_name}.png"
47
+ return photo
48
+ except:
49
+ try:
50
+ print('n_1')
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
+ print("n_2")
66
+ print(url_sd4)
67
+ with closing(create_connection(f"{url_sd4}", timeout=60)) as conn:
68
+ conn.send('{"fn_index":0,"session_hash":""}')
69
+ 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":""}}')
70
+ conn.recv()
71
+ conn.recv()
72
+ conn.recv()
73
+ conn.recv()
74
+ photo = json.loads(conn.recv())['output']['data'][0]
75
+ photo = photo.replace('data:image/jpeg;base64,', '').replace('data:image/png;base64,', '')
76
+ photo = Image.open(io.BytesIO(base64.decodebytes(bytes(photo, "utf-8"))))
77
+ return photo
78
 
79
 
80
  def flipp():