lalashechka commited on
Commit
f783c38
1 Parent(s): f43caa4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +75 -14
app.py CHANGED
@@ -12,6 +12,9 @@ import io
12
  import base64
13
  import re
14
  from gradio_client import Client
 
 
 
15
 
16
  def flip_text(prompt, negative_prompt, task, steps, sampler, cfg_scale, seed):
17
  result = {"prompt": prompt,"negative_prompt": negative_prompt,"task": task,"steps": steps,"sampler": sampler,"cfg_scale": cfg_scale,"seed": seed}
@@ -93,6 +96,64 @@ def flip_text(prompt, negative_prompt, task, steps, sampler, cfg_scale, seed):
93
  photo = photo.replace('data:image/jpeg;base64,', '').replace('data:image/png;base64,', '')
94
  photo = Image.open(io.BytesIO(base64.decodebytes(bytes(photo, "utf-8"))))
95
  return photo
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
96
  #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}}
97
  #response = requests.post(f'{url_sd5}', json=data)
98
  #print(response.text)
@@ -100,20 +161,20 @@ def flip_text(prompt, negative_prompt, task, steps, sampler, cfg_scale, seed):
100
  #file_name = response.json()['image']['file_name']
101
  #photo = f"{url_sd6}{file_name}.png"
102
  #return photo
103
- except Exception as e:
104
- print("e: --> ",e)
105
- with closing(create_connection(f"{url_sd4}")) as conn:
106
- conn.send('{"fn_index":0,"session_hash":""}')
107
- 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":""}}')
108
- conn.recv()
109
- conn.recv()
110
- conn.recv()
111
- conn.recv()
112
- photo = json.loads(conn.recv())['output']['data'][0]
113
- photo = photo.replace('data:image/jpeg;base64,', '').replace('data:image/png;base64,', '')
114
- photo = Image.open(io.BytesIO(base64.decodebytes(bytes(photo, "utf-8"))))
115
- return photo
116
-
117
  #except:
118
  # try:
119
  # client = Client("https://prodia-sdxl-stable-diffusion-xl.hf.space")
 
12
  import base64
13
  import re
14
  from gradio_client import Client
15
+ from fake_useragent import UserAgent
16
+ import random
17
+
18
 
19
  def flip_text(prompt, negative_prompt, task, steps, sampler, cfg_scale, seed):
20
  result = {"prompt": prompt,"negative_prompt": negative_prompt,"task": task,"steps": steps,"sampler": sampler,"cfg_scale": cfg_scale,"seed": seed}
 
96
  photo = photo.replace('data:image/jpeg;base64,', '').replace('data:image/png;base64,', '')
97
  photo = Image.open(io.BytesIO(base64.decodebytes(bytes(photo, "utf-8"))))
98
  return photo
99
+ except:
100
+ try:
101
+ ua = UserAgent()
102
+ headers = {
103
+ 'authority': 'ehristoforu-dalle-3-xl-lora-v2.hf.space',
104
+ 'accept': 'text/event-stream',
105
+ 'accept-language': 'ru,en;q=0.9,la;q=0.8,ja;q=0.7',
106
+ 'cache-control': 'no-cache',
107
+ 'referer': 'https://ehristoforu-dalle-3-xl-lora-v2.hf.space/?__theme=light',
108
+ 'sec-ch-ua': '"Not_A Brand";v="8", "Chromium";v="120", "YaBrowser";v="24.1", "Yowser";v="2.5"',
109
+ 'sec-ch-ua-mobile': '?0',
110
+ 'sec-ch-ua-platform': '"Windows"',
111
+ 'sec-fetch-dest': 'empty',
112
+ 'sec-fetch-mode': 'cors',
113
+ 'sec-fetch-site': 'same-origin',
114
+ 'user-agent': f'{ua.random}'
115
+ }
116
+ client = Client("ehristoforu/dalle-3-xl-lora-v2", headers=headers)
117
+ result = client.predict(prompt,"(deformed, distorted, disfigured:1.3), poorly drawn, bad anatomy, wrong anatomy, extra limb, missing limb, floating limbs, (mutated hands and fingers:1.4), disconnected limbs, mutation, mutated, ugly, disgusting, blurry, amputation",True,0,1024,1024,6,True, api_name='/run')
118
+ return result[0][0]['image']
119
+ except:
120
+ try:
121
+ headers = {
122
+ 'authority': 'nymbo-sd-xl.hf.space',
123
+ 'accept': 'text/event-stream',
124
+ 'accept-language': 'ru,en;q=0.9,la;q=0.8,ja;q=0.7',
125
+ 'cache-control': 'no-cache',
126
+ 'referer': 'https://nymbo-sd-xl.hf.space/?__theme=light',
127
+ 'sec-ch-ua': '"Not_A Brand";v="8", "Chromium";v="120", "YaBrowser";v="24.1", "Yowser";v="2.5"',
128
+ 'sec-ch-ua-mobile': '?0',
129
+ 'sec-ch-ua-platform': '"Windows"',
130
+ 'sec-fetch-dest': 'empty',
131
+ 'sec-fetch-mode': 'cors',
132
+ 'sec-fetch-site': 'same-origin',
133
+ 'user-agent': f'{ua.random}'
134
+ }
135
+ client = Client("Nymbo/SD-XL", headers=headers)
136
+ result = client.predict(prompt,negative_prompt,"","",True,False,False,0,1024,1024,7,1,25,25,False,api_name="/run")
137
+ return result
138
+ except:
139
+ headers = {
140
+ 'authority': 'radames-real-time-text-to-image-sdxl-lightning.hf.space',
141
+ 'accept': 'text/event-stream',
142
+ 'accept-language': 'ru,en;q=0.9,la;q=0.8,ja;q=0.7',
143
+ 'cache-control': 'no-cache',
144
+ 'referer': 'https://radames-real-time-text-to-image-sdxl-lightning.hf.space/?__theme=light',
145
+ 'sec-ch-ua': '"Not_A Brand";v="8", "Chromium";v="120", "YaBrowser";v="24.1", "Yowser";v="2.5"',
146
+ 'sec-ch-ua-mobile': '?0',
147
+ 'sec-ch-ua-platform': '"Windows"',
148
+ 'sec-fetch-dest': 'empty',
149
+ 'sec-fetch-mode': 'cors',
150
+ 'sec-fetch-site': 'same-origin',
151
+ 'user-agent': f'{ua.random}'
152
+ }
153
+ client = Client("radames/Real-Time-Text-to-Image-SDXL-Lightning", headers=headers)
154
+ result = client.predict(prompt, [], 0, random.randint(1, 999999), fn_index=0)
155
+ return result
156
+
157
  #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}}
158
  #response = requests.post(f'{url_sd5}', json=data)
159
  #print(response.text)
 
161
  #file_name = response.json()['image']['file_name']
162
  #photo = f"{url_sd6}{file_name}.png"
163
  #return photo
164
+ #except Exception as e:
165
+ # print("e: --> ",e)
166
+ # with closing(create_connection(f"{url_sd4}")) as conn:
167
+ # conn.send('{"fn_index":0,"session_hash":""}')
168
+ # 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":""}}')
169
+ # conn.recv()
170
+ # conn.recv()
171
+ # conn.recv()
172
+ # conn.recv()
173
+ # photo = json.loads(conn.recv())['output']['data'][0]
174
+ # photo = photo.replace('data:image/jpeg;base64,', '').replace('data:image/png;base64,', '')
175
+ # photo = Image.open(io.BytesIO(base64.decodebytes(bytes(photo, "utf-8"))))
176
+ # return photo
177
+
178
  #except:
179
  # try:
180
  # client = Client("https://prodia-sdxl-stable-diffusion-xl.hf.space")