Spaces:
Runtime error
Runtime error
Brian Watson
commited on
Commit
•
d4d7ead
1
Parent(s):
22efa4c
Update app.py
Browse files
app.py
CHANGED
@@ -1,106 +1,148 @@
|
|
1 |
import gradio as gr
|
2 |
-
import os
|
3 |
-
import sys
|
4 |
-
from pathlib import Path
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
12 |
]
|
13 |
|
14 |
-
current_model = models[0]
|
15 |
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
def
|
30 |
-
|
31 |
-
|
32 |
-
return
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
46 |
with gr.Row():
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
)
|
56 |
with gr.Row():
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
|
|
|
1 |
import gradio as gr
|
2 |
+
# import os
|
3 |
+
# import sys
|
4 |
+
# from pathlib import Path
|
5 |
+
import time
|
6 |
+
|
7 |
+
models =[
|
8 |
+
"stablediffusionapi/all-526-animated",
|
9 |
+
"kubanemil/AnyLORA",
|
10 |
+
"andite/anything-v4.0",
|
11 |
+
"stablediffusionapi/anything-v5",
|
12 |
+
"gsdf/Counterfeit-V2.0",
|
13 |
+
"dreamlike-art/dreamlike-anime-1.0",
|
14 |
+
"eimiss/EimisAnimeDiffusion_1.0v",
|
15 |
+
"DucHaiten/DucHaitenAnime",
|
16 |
+
"xiaolxl/GuoFeng3",
|
17 |
+
"andite/pastel-mix",
|
18 |
+
"prompthero/openjourney-v4",
|
19 |
+
"aipicasso/picasso-diffusion-1-1",
|
20 |
+
"stablediffusionapi/rev-anim",
|
21 |
+
"coreml/coreml-ReV-Animated",
|
22 |
]
|
23 |
|
|
|
24 |
|
25 |
+
model_functions = {}
|
26 |
+
model_idx = 1
|
27 |
+
for model_path in models:
|
28 |
+
try:
|
29 |
+
model_functions[model_idx] = gr.Interface.load(f"models/{model_path}", live=False, preprocess=True, postprocess=False)
|
30 |
+
except Exception as error:
|
31 |
+
def the_fn(txt):
|
32 |
+
return None
|
33 |
+
model_functions[model_idx] = gr.Interface(fn=the_fn, inputs=["text"], outputs=["image"])
|
34 |
+
model_idx+=1
|
35 |
+
|
36 |
+
|
37 |
+
def send_it_idx(idx):
|
38 |
+
def send_it_fn(prompt):
|
39 |
+
output = (model_functions.get(str(idx)) or model_functions.get(str(1)))(prompt)
|
40 |
+
return output
|
41 |
+
return send_it_fn
|
42 |
+
|
43 |
+
def get_prompts(prompt_text):
|
44 |
+
return prompt_text
|
45 |
+
|
46 |
+
def clear_it(val):
|
47 |
+
if int(val) != 0:
|
48 |
+
val = 0
|
49 |
+
else:
|
50 |
+
val = 0
|
51 |
+
pass
|
52 |
+
return val
|
53 |
+
|
54 |
+
def all_task_end(cnt,t_stamp):
|
55 |
+
to = t_stamp + 60
|
56 |
+
et = time.time()
|
57 |
+
if et > to and t_stamp != 0:
|
58 |
+
d = gr.update(value=0)
|
59 |
+
tog = gr.update(value=1)
|
60 |
+
#print(f'to: {to} et: {et}')
|
61 |
+
else:
|
62 |
+
if cnt != 0:
|
63 |
+
d = gr.update(value=et)
|
64 |
+
else:
|
65 |
+
d = gr.update(value=0)
|
66 |
+
tog = gr.update(value=0)
|
67 |
+
#print (f'passing: to: {to} et: {et}')
|
68 |
+
pass
|
69 |
+
return d, tog
|
70 |
+
|
71 |
+
def all_task_start():
|
72 |
+
print("\n\n\n\n\n\n\n")
|
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, *[None for _ in range(nn)]])
|
81 |
+
|
82 |
+
|
83 |
+
|
84 |
+
with gr.Blocks(title="SD Models") 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.Row(scale=6):
|
90 |
+
primary_prompt=gr.Textbox(label="Prompt", value="")
|
91 |
+
# real_prompt=gr.Textbox(label="Real prompt")
|
92 |
+
with gr.Row(scale=6):
|
93 |
+
# improve_prompts_btn=gr.Button("Improve")
|
94 |
+
with gr.Row():
|
95 |
+
run=gr.Button("Run",variant="primary")
|
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 |
+
primary_prompt.submit(all_task_start, None, [start_box, end_box, tog_box])
|
122 |
+
run.click(all_task_start, None, [start_box, end_box, tog_box])
|
123 |
+
runs_dict = {}
|
124 |
+
model_idx = 1
|
125 |
+
for model_path in models:
|
126 |
+
runs_dict[model_idx] = run.click(model_functions[model_idx], inputs=[primary_prompt], outputs=[sd_outputs[model_idx]])
|
127 |
+
model_idx += 1
|
128 |
+
pass
|
129 |
+
pass
|
130 |
+
|
131 |
+
# improve_prompts_btn_clicked=improve_prompts_btn.click(
|
132 |
+
# get_prompts,
|
133 |
+
# inputs=[primary_prompt],
|
134 |
+
# outputs=[primary_prompt],
|
135 |
+
# cancels=list(runs_dict.values()))
|
136 |
+
clear_btn.click(
|
137 |
+
clear_fn,
|
138 |
+
None,
|
139 |
+
[primary_prompt, *list(sd_outputs.values())],
|
140 |
+
cancels=[*list(runs_dict.values())])
|
141 |
+
tog_box.change(
|
142 |
+
clear_it,
|
143 |
+
tog_box,
|
144 |
+
tog_box,
|
145 |
+
cancels=[*list(runs_dict.values())])
|
146 |
+
|
147 |
+
my_interface.queue(concurrency_count=600, status_update_rate=1)
|
148 |
+
my_interface.launch(inline=True, show_api=False)
|