Spaces:
Running
Running
lalashechka
commited on
Commit
•
7dd17d6
1
Parent(s):
22d4eb1
Update app.py
Browse files
app.py
CHANGED
@@ -7,6 +7,9 @@ from websocket import create_connection
|
|
7 |
from deep_translator import GoogleTranslator
|
8 |
from langdetect import detect
|
9 |
import os
|
|
|
|
|
|
|
10 |
|
11 |
|
12 |
def flip_text(prompt, negative_prompt, task, steps, sampler, cfg_scale, seed):
|
@@ -27,38 +30,56 @@ def flip_text(prompt, negative_prompt, task, steps, sampler, cfg_scale, seed):
|
|
27 |
height = 1024
|
28 |
url_sd1 = os.getenv("url_sd1")
|
29 |
url_sd2 = os.getenv("url_sd2")
|
|
|
30 |
|
31 |
print(task)
|
32 |
-
|
33 |
-
if task == 'Stable Diffusion XL 1.0':
|
34 |
-
model = 'sd_xl_base_1.0'
|
35 |
-
if task == 'Crystal Clear XL':
|
36 |
-
model = '[3d] crystalClearXL_ccxl_97637'
|
37 |
-
if task == 'Juggernaut XL':
|
38 |
-
model = '[photorealistic] juggernautXL_version2_113240'
|
39 |
-
if task == 'DreamShaper XL':
|
40 |
-
model = '[base model] dreamshaperXL09Alpha_alpha2Xl10_91562'
|
41 |
-
if task == 'SDXL Niji':
|
42 |
-
model = '[midjourney] sdxlNijiV51_sdxlNijiV51_112807'
|
43 |
-
if task == 'Cinemax SDXL':
|
44 |
-
model = '[movie] cinemaxAlphaSDXLCinema_alpha1_107473'
|
45 |
-
if task == 'NightVision XL':
|
46 |
-
model = '[photorealistic] nightvisionXLPhotorealisticPortrait_beta0702Bakedvae_113098'
|
47 |
-
|
48 |
-
negative = negative_prompt
|
49 |
-
|
50 |
try:
|
51 |
-
|
52 |
-
|
53 |
-
conn.send(
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
60 |
except:
|
61 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
62 |
|
63 |
css = """
|
64 |
#generate {
|
|
|
7 |
from deep_translator import GoogleTranslator
|
8 |
from langdetect import detect
|
9 |
import os
|
10 |
+
from PIL import Image
|
11 |
+
import io
|
12 |
+
import base64
|
13 |
|
14 |
|
15 |
def flip_text(prompt, negative_prompt, task, steps, sampler, cfg_scale, seed):
|
|
|
30 |
height = 1024
|
31 |
url_sd1 = os.getenv("url_sd1")
|
32 |
url_sd2 = os.getenv("url_sd2")
|
33 |
+
url_sd3 = os.getenv("url_sd3")
|
34 |
|
35 |
print(task)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
36 |
try:
|
37 |
+
print('n_1')
|
38 |
+
with closing(create_connection(f"{url_sd3}", timeout=60)) as conn:
|
39 |
+
conn.send('{"fn_index":3,"session_hash":""}')
|
40 |
+
conn.send(f'{{"data":["{text}, 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":""}}')
|
41 |
+
while True:
|
42 |
+
status = json.loads(conn.recv())['msg']
|
43 |
+
print(status)
|
44 |
+
if status == 'estimation':
|
45 |
+
continue
|
46 |
+
if status == 'process_starts':
|
47 |
+
break
|
48 |
+
photo = json.loads(conn.recv())['output']['data'][0][0]
|
49 |
+
photo = photo.replace('data:image/jpeg;base64,', '').replace('data:image/png;base64,', '')
|
50 |
+
photo = Image.open(io.BytesIO(base64.decodebytes(bytes(photo, "utf-8"))))
|
51 |
+
return photo
|
52 |
except:
|
53 |
+
print(n_2)
|
54 |
+
if task == 'Stable Diffusion XL 1.0':
|
55 |
+
model = 'sd_xl_base_1.0'
|
56 |
+
if task == 'Crystal Clear XL':
|
57 |
+
model = '[3d] crystalClearXL_ccxl_97637'
|
58 |
+
if task == 'Juggernaut XL':
|
59 |
+
model = '[photorealistic] juggernautXL_version2_113240'
|
60 |
+
if task == 'DreamShaper XL':
|
61 |
+
model = '[base model] dreamshaperXL09Alpha_alpha2Xl10_91562'
|
62 |
+
if task == 'SDXL Niji':
|
63 |
+
model = '[midjourney] sdxlNijiV51_sdxlNijiV51_112807'
|
64 |
+
if task == 'Cinemax SDXL':
|
65 |
+
model = '[movie] cinemaxAlphaSDXLCinema_alpha1_107473'
|
66 |
+
if task == 'NightVision XL':
|
67 |
+
model = '[photorealistic] nightvisionXLPhotorealisticPortrait_beta0702Bakedvae_113098'
|
68 |
+
|
69 |
+
negative = negative_prompt
|
70 |
+
|
71 |
+
try:
|
72 |
+
with closing(create_connection(f"{url_sd1}")) as conn:
|
73 |
+
conn.send('{"fn_index":231,"session_hash":""}')
|
74 |
+
conn.send(f'{{"data":["task()","{prompt}","{negative}",[],{steps},"{sampler}",false,false,1,1,{cfg},{seed},-1,0,0,0,false,{width},{height},false,0.7,2,"Lanczos",0,0,0,"Use same sampler","","",[],"None",true,"{model}","Automatic",null,null,null,false,false,"positive","comma",0,false,false,"","Seed","",[],"Nothing","",[],"Nothing","",[],true,false,false,false,0,null,null,false,null,null,false,null,null,false,50,[],"","",""],"event_data":null,"fn_index":231,"session_hash":""}}')
|
75 |
+
print(conn.recv())
|
76 |
+
print(conn.recv())
|
77 |
+
print(conn.recv())
|
78 |
+
print(conn.recv())
|
79 |
+
photo = f"{url_sd2}" + str(json.loads(conn.recv())['output']['data'][0][0]["name"])
|
80 |
+
return photo
|
81 |
+
except:
|
82 |
+
return None
|
83 |
|
84 |
css = """
|
85 |
#generate {
|