Spaces:
Build error
Build error
hugforziio
commited on
Commit
·
77a862a
1
Parent(s):
923bcf3
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,147 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
# import os
|
3 |
+
# import sys
|
4 |
+
# from pathlib import Path
|
5 |
+
import time
|
6 |
+
|
7 |
+
models =[
|
8 |
+
"CompVis/stable-diffusion-v1-4",
|
9 |
+
"runwayml/stable-diffusion-v1-5",
|
10 |
+
"prompthero/openjourney",
|
11 |
+
"stabilityai/stable-diffusion-2-1",
|
12 |
+
"stabilityai/stable-diffusion-2-1-base",
|
13 |
+
"andite/anything-v4.0",
|
14 |
+
"Linaqruf/anything-v3.0",
|
15 |
+
"eimiss/EimisAnimeDiffusion_1.0v",
|
16 |
+
"nitrosocke/Nitro-Diffusion",
|
17 |
+
"wavymulder/portraitplus",
|
18 |
+
"22h/vintedois-diffusion-v0-1",
|
19 |
+
"dreamlike-art/dreamlike-photoreal-2.0",
|
20 |
+
"dreamlike-art/dreamlike-diffusion-1.0",
|
21 |
+
"wavymulder/Analog-Diffusion",
|
22 |
+
"nitrosocke/redshift-diffusion",
|
23 |
+
"claudfuen/photorealistic-fuen-v1",
|
24 |
+
"prompthero/openjourney-v2",
|
25 |
+
"johnslegers/epic-diffusion",
|
26 |
+
"nitrosocke/Arcane-Diffusion",
|
27 |
+
"darkstorm2150/Protogen_x5.8_Official_Release",
|
28 |
+
]
|
29 |
+
|
30 |
+
|
31 |
+
interfaces = {}
|
32 |
+
model_idx = 1
|
33 |
+
for model_path in models:
|
34 |
+
interfaces[model_idx] = gr.Interface.load(f"models/{model_path}", live=False, preprocess=True, postprocess=False)
|
35 |
+
model_idx+=1
|
36 |
+
|
37 |
+
|
38 |
+
def send_it_idx(idx):
|
39 |
+
def send_it_fn(prompt):
|
40 |
+
output = (interfaces.get(str(idx)) or interfaces.get(str(1)))(prompt)
|
41 |
+
return output
|
42 |
+
return send_it_fn
|
43 |
+
|
44 |
+
def get_prompts(prompt_text):
|
45 |
+
return prompt_text
|
46 |
+
|
47 |
+
def clear_it(val):
|
48 |
+
if int(val) != 0:
|
49 |
+
val = 0
|
50 |
+
else:
|
51 |
+
val = 0
|
52 |
+
pass
|
53 |
+
return val
|
54 |
+
|
55 |
+
def all_task_end(cnt,t_stamp):
|
56 |
+
to = t_stamp + 60
|
57 |
+
et = time.time()
|
58 |
+
if et > to and t_stamp != 0:
|
59 |
+
d = gr.update(value=0)
|
60 |
+
tog = gr.update(value=1)
|
61 |
+
#print(f'to: {to} et: {et}')
|
62 |
+
else:
|
63 |
+
if cnt != 0:
|
64 |
+
d = gr.update(value=et)
|
65 |
+
else:
|
66 |
+
d = gr.update(value=0)
|
67 |
+
tog = gr.update(value=0)
|
68 |
+
#print (f'passing: to: {to} et: {et}')
|
69 |
+
pass
|
70 |
+
return d, tog
|
71 |
+
|
72 |
+
def all_task_start():
|
73 |
+
t = time.gmtime()
|
74 |
+
t_stamp = time.time()
|
75 |
+
current_time = time.strftime("%H:%M:%S", t)
|
76 |
+
return gr.update(value=t_stamp), gr.update(value=t_stamp), gr.update(value=0)
|
77 |
+
|
78 |
+
def clear_fn():
|
79 |
+
nn = len(models)
|
80 |
+
return tuple([None for _ in range(nn)])
|
81 |
+
|
82 |
+
|
83 |
+
|
84 |
+
with gr.Blocks() as my_interface:
|
85 |
+
with gr.Column(scale=12):
|
86 |
+
with gr.Row():
|
87 |
+
gr.Markdown("""- Primary prompt: 你想画的内容(英文单词,如 a cat, 加英文逗号效果更好;点 Improve 按钮进行完善)\n- Real prompt: 完善后的提示词,出现后再点右边的 Run 按钮开始运行""")
|
88 |
+
with gr.Row():
|
89 |
+
with gr.Column(scale=6):
|
90 |
+
primary_prompt=gr.Textbox(label="Primary prompt")
|
91 |
+
real_prompt=gr.Textbox(label="Real prompt")
|
92 |
+
with gr.Column(scale=6):
|
93 |
+
improve_prompts_btn=gr.Button("Improve")
|
94 |
+
with gr.Row():
|
95 |
+
run=gr.Button("Run")
|
96 |
+
clear_btn=gr.Button("Clear")
|
97 |
+
with gr.Row():
|
98 |
+
sd_outputs = {}
|
99 |
+
model_idx = 1
|
100 |
+
for model_path in models:
|
101 |
+
with gr.Column(scale=3, min_width=320):
|
102 |
+
with gr.Box():
|
103 |
+
sd_outputs[model_idx] = gr.Image(label=model_path)
|
104 |
+
pass
|
105 |
+
model_idx += 1
|
106 |
+
pass
|
107 |
+
pass
|
108 |
+
|
109 |
+
with gr.Row(visible=False):
|
110 |
+
start_box=gr.Number(interactive=False)
|
111 |
+
end_box=gr.Number(interactive=False)
|
112 |
+
tog_box=gr.Textbox(value=0,interactive=False)
|
113 |
+
|
114 |
+
start_box.change(
|
115 |
+
all_task_end,
|
116 |
+
[start_box, end_box],
|
117 |
+
[start_box, tog_box],
|
118 |
+
every=1,
|
119 |
+
show_progress=False)
|
120 |
+
|
121 |
+
run.click(all_task_start, None, [start_box, end_box, tog_box])
|
122 |
+
runs_dict = {}
|
123 |
+
model_idx = 1
|
124 |
+
for model_path in models:
|
125 |
+
runs_dict[model_idx] = run.click(interfaces[model_idx], inputs=[real_prompt], outputs=[sd_outputs[model_idx]])
|
126 |
+
model_idx += 1
|
127 |
+
pass
|
128 |
+
pass
|
129 |
+
|
130 |
+
improve_prompts_btn_clicked=improve_prompts_btn.click(
|
131 |
+
get_prompts,
|
132 |
+
inputs=[primary_prompt],
|
133 |
+
outputs=[real_prompt],
|
134 |
+
cancels=list(runs_dict.values()))
|
135 |
+
clear_btn.click(
|
136 |
+
clear_fn,
|
137 |
+
None,
|
138 |
+
[primary_prompt, real_prompt, *list(sd_outputs.values())],
|
139 |
+
cancels=[improve_prompts_btn_clicked, *list(runs_dict.values())])
|
140 |
+
tog_box.change(
|
141 |
+
clear_it,
|
142 |
+
tog_box,
|
143 |
+
tog_box,
|
144 |
+
cancels=[*list(runs_dict.values()), improve_prompts_btn_clicked])
|
145 |
+
|
146 |
+
my_interface.queue(concurrency_count=600, status_update_rate=1)
|
147 |
+
my_interface.launch(inline=True, show_api=False)
|