lalashechka commited on
Commit
0496224
1 Parent(s): 061c8b7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +60 -51
app.py CHANGED
@@ -35,15 +35,7 @@ def flip_text(prompt, negative_prompt, task, steps, sampler, cfg_scale, seed):
35
 
36
  width = 1024
37
  height = 1024
38
- #url_sd1 = os.getenv("url_sd1")
39
- #url_sd2 = os.getenv("url_sd2")
40
-
41
- #url_sd3 = os.getenv("url_sd3")
42
- #url_sd4 = os.getenv("url_sd4")
43
-
44
- #url_sd5 = os.getenv("url_sd5")
45
- #url_sd6 = os.getenv("url_sd6")
46
- #hf_token = os.getenv("hf_token")
47
  if task == "Playground v2":
48
  playground = str(os.getenv("playground"))
49
  with closing(create_connection("wss://ashrafb-arpr.hf.space/queue/join", timeout=60)) as conn:
@@ -75,35 +67,32 @@ def flip_text(prompt, negative_prompt, task, steps, sampler, cfg_scale, seed):
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
  try:
80
- ua = UserAgent()
81
- headers = {
82
- 'authority': 'ehristoforu-dalle-3-xl-lora-v2.hf.space',
83
- 'accept': 'text/event-stream',
84
- 'accept-language': 'ru,en;q=0.9,la;q=0.8,ja;q=0.7',
85
- 'cache-control': 'no-cache',
86
- 'referer': 'https://ehristoforu-dalle-3-xl-lora-v2.hf.space/?__theme=light',
87
- 'sec-ch-ua': '"Not_A Brand";v="8", "Chromium";v="120", "YaBrowser";v="24.1", "Yowser";v="2.5"',
88
- 'sec-ch-ua-mobile': '?0',
89
- 'sec-ch-ua-platform': '"Windows"',
90
- 'sec-fetch-dest': 'empty',
91
- 'sec-fetch-mode': 'cors',
92
- 'sec-fetch-site': 'same-origin',
93
- 'user-agent': f'{ua.random}'
94
- }
95
- client = Client("ehristoforu/dalle-3-xl-lora-v2", headers=headers)
96
- 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')
97
- return result[0][0]['image']
98
  except:
99
  try:
100
  ua = UserAgent()
101
  headers = {
102
- 'authority': 'nymbo-sd-xl.hf.space',
103
  'accept': 'text/event-stream',
104
  'accept-language': 'ru,en;q=0.9,la;q=0.8,ja;q=0.7',
105
  'cache-control': 'no-cache',
106
- 'referer': 'https://nymbo-sd-xl.hf.space/?__theme=light',
107
  'sec-ch-ua': '"Not_A Brand";v="8", "Chromium";v="120", "YaBrowser";v="24.1", "Yowser";v="2.5"',
108
  'sec-ch-ua-mobile': '?0',
109
  'sec-ch-ua-platform': '"Windows"',
@@ -112,28 +101,48 @@ def flip_text(prompt, negative_prompt, task, steps, sampler, cfg_scale, seed):
112
  'sec-fetch-site': 'same-origin',
113
  'user-agent': f'{ua.random}'
114
  }
115
- client = Client("Nymbo/SD-XL", headers=headers)
116
- result = client.predict(prompt,negative_prompt,"","",True,False,False,0,1024,1024,7,1,25,25,False,api_name="/run")
117
- return result
118
  except:
119
- ua = UserAgent()
120
- headers = {
121
- 'authority': 'radames-real-time-text-to-image-sdxl-lightning.hf.space',
122
- 'accept': 'text/event-stream',
123
- 'accept-language': 'ru,en;q=0.9,la;q=0.8,ja;q=0.7',
124
- 'cache-control': 'no-cache',
125
- 'referer': 'https://radames-real-time-text-to-image-sdxl-lightning.hf.space/?__theme=light',
126
- 'sec-ch-ua': '"Not_A Brand";v="8", "Chromium";v="120", "YaBrowser";v="24.1", "Yowser";v="2.5"',
127
- 'sec-ch-ua-mobile': '?0',
128
- 'sec-ch-ua-platform': '"Windows"',
129
- 'sec-fetch-dest': 'empty',
130
- 'sec-fetch-mode': 'cors',
131
- 'sec-fetch-site': 'same-origin',
132
- 'user-agent': f'{ua.random}'
133
- }
134
- client = Client("radames/Real-Time-Text-to-Image-SDXL-Lightning", headers=headers)
135
- result = client.predict(prompt, [], 0, random.randint(1, 999999), fn_index=0)
136
- return result
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
137
 
138
 
139
  def mirror(image_output, scale_by, method, gfpgan, codeformer):
 
35
 
36
  width = 1024
37
  height = 1024
38
+
 
 
 
 
 
 
 
 
39
  if task == "Playground v2":
40
  playground = str(os.getenv("playground"))
41
  with closing(create_connection("wss://ashrafb-arpr.hf.space/queue/join", timeout=60)) as conn:
 
67
  photo = photo.replace('data:image/jpeg;base64,', '').replace('data:image/png;base64,', '')
68
  photo = Image.open(io.BytesIO(base64.decodebytes(bytes(photo, "utf-8"))))
69
  return photo
 
70
  try:
71
+ with closing(create_connection(f"{url_sd3}")) as conn:
72
+ conn.send('{"fn_index":3,"session_hash":""}')
73
+ 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":""}}')
74
+ c = 0
75
+ while c < 60:
76
+ status = json.loads(conn.recv())['msg']
77
+ if status == 'estimation':
78
+ c += 1
79
+ time.sleep(1)
80
+ continue
81
+ if status == 'process_starts':
82
+ break
83
+ photo = json.loads(conn.recv())['output']['data'][0][0]
84
+ photo = photo.replace('data:image/jpeg;base64,', '').replace('data:image/png;base64,', '')
85
+ photo = Image.open(io.BytesIO(base64.decodebytes(bytes(photo, "utf-8"))))
86
+ return photo
 
 
87
  except:
88
  try:
89
  ua = UserAgent()
90
  headers = {
91
+ 'authority': 'ehristoforu-dalle-3-xl-lora-v2.hf.space',
92
  'accept': 'text/event-stream',
93
  'accept-language': 'ru,en;q=0.9,la;q=0.8,ja;q=0.7',
94
  'cache-control': 'no-cache',
95
+ 'referer': 'https://ehristoforu-dalle-3-xl-lora-v2.hf.space/?__theme=light',
96
  'sec-ch-ua': '"Not_A Brand";v="8", "Chromium";v="120", "YaBrowser";v="24.1", "Yowser";v="2.5"',
97
  'sec-ch-ua-mobile': '?0',
98
  'sec-ch-ua-platform': '"Windows"',
 
101
  'sec-fetch-site': 'same-origin',
102
  'user-agent': f'{ua.random}'
103
  }
104
+ client = Client("ehristoforu/dalle-3-xl-lora-v2", headers=headers)
105
+ 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')
106
+ return result[0][0]['image']
107
  except:
108
+ try:
109
+ ua = UserAgent()
110
+ headers = {
111
+ 'authority': 'nymbo-sd-xl.hf.space',
112
+ 'accept': 'text/event-stream',
113
+ 'accept-language': 'ru,en;q=0.9,la;q=0.8,ja;q=0.7',
114
+ 'cache-control': 'no-cache',
115
+ 'referer': 'https://nymbo-sd-xl.hf.space/?__theme=light',
116
+ 'sec-ch-ua': '"Not_A Brand";v="8", "Chromium";v="120", "YaBrowser";v="24.1", "Yowser";v="2.5"',
117
+ 'sec-ch-ua-mobile': '?0',
118
+ 'sec-ch-ua-platform': '"Windows"',
119
+ 'sec-fetch-dest': 'empty',
120
+ 'sec-fetch-mode': 'cors',
121
+ 'sec-fetch-site': 'same-origin',
122
+ 'user-agent': f'{ua.random}'
123
+ }
124
+ client = Client("Nymbo/SD-XL", headers=headers)
125
+ result = client.predict(prompt,negative_prompt,"","",True,False,False,0,1024,1024,7,1,25,25,False,api_name="/run")
126
+ return result
127
+ except:
128
+ ua = UserAgent()
129
+ headers = {
130
+ 'authority': 'radames-real-time-text-to-image-sdxl-lightning.hf.space',
131
+ 'accept': 'text/event-stream',
132
+ 'accept-language': 'ru,en;q=0.9,la;q=0.8,ja;q=0.7',
133
+ 'cache-control': 'no-cache',
134
+ 'referer': 'https://radames-real-time-text-to-image-sdxl-lightning.hf.space/?__theme=light',
135
+ 'sec-ch-ua': '"Not_A Brand";v="8", "Chromium";v="120", "YaBrowser";v="24.1", "Yowser";v="2.5"',
136
+ 'sec-ch-ua-mobile': '?0',
137
+ 'sec-ch-ua-platform': '"Windows"',
138
+ 'sec-fetch-dest': 'empty',
139
+ 'sec-fetch-mode': 'cors',
140
+ 'sec-fetch-site': 'same-origin',
141
+ 'user-agent': f'{ua.random}'
142
+ }
143
+ client = Client("radames/Real-Time-Text-to-Image-SDXL-Lightning", headers=headers)
144
+ result = client.predict(prompt, [], 0, random.randint(1, 999999), fn_index=0)
145
+ return result
146
 
147
 
148
  def mirror(image_output, scale_by, method, gfpgan, codeformer):