Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,17 +1,147 @@
|
|
1 |
-
import gradio as gr
|
2 |
-
import
|
3 |
-
|
4 |
-
#
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
# import os
|
3 |
+
# import sys
|
4 |
+
# from pathlib import Path
|
5 |
+
import time
|
6 |
+
|
7 |
+
models =[
|
8 |
+
"XLabs-AI/flux-RealismLora",
|
9 |
+
"adirik/flux-cinestill",
|
10 |
+
"VideoAditor/Flux-Lora-Realism",
|
11 |
+
"black-forest-labs/FLUX.1-schnell",
|
12 |
+
"John6666/3x3x3mixxl-v2-sdxl",
|
13 |
+
"John6666/epicrealism-xl-v8kiss-sdxl",
|
14 |
+
"alvdansen/flux-koda",
|
15 |
+
"fluently/Fluently-XL-Final",
|
16 |
+
"ByteDance/Hyper-SD",
|
17 |
+
|
18 |
+
]
|
19 |
+
|
20 |
+
|
21 |
+
model_functions = {}
|
22 |
+
model_idx = 1
|
23 |
+
for model_path in models:
|
24 |
+
try:
|
25 |
+
model_functions[model_idx] = gr.Interface.load(f"models/{model_path}", live=False, preprocess=True, postprocess=False)
|
26 |
+
except Exception as error:
|
27 |
+
def the_fn(txt):
|
28 |
+
|
29 |
+
return None
|
30 |
+
model_functions[model_idx] = gr.Interface(fn=the_fn, inputs=["text"], outputs=["image"])
|
31 |
+
|
32 |
+
model_idx+=1
|
33 |
+
|
34 |
+
|
35 |
+
def send_it_idx(idx):
|
36 |
+
def send_it_fn(prompt):
|
37 |
+
output = (model_functions.get(str(idx)) or model_functions.get(str(1)))(prompt)
|
38 |
+
return output
|
39 |
+
return send_it_fn
|
40 |
+
|
41 |
+
def get_prompts(prompt_text):
|
42 |
+
|
43 |
+
return prompt_text
|
44 |
+
|
45 |
+
def clear_it(val):
|
46 |
+
if int(val) != 0:
|
47 |
+
val = 0
|
48 |
+
else:
|
49 |
+
val = 0
|
50 |
+
pass
|
51 |
+
return val
|
52 |
+
|
53 |
+
def all_task_end(cnt,t_stamp):
|
54 |
+
to = t_stamp + 360
|
55 |
+
et = time.time()
|
56 |
+
if et > to and t_stamp != 0:
|
57 |
+
d = gr.update(value=0)
|
58 |
+
tog = gr.update(value=1)
|
59 |
+
#print(f'to: {to} et: {et}')
|
60 |
+
else:
|
61 |
+
if cnt != 0:
|
62 |
+
d = gr.update(value=et)
|
63 |
+
else:
|
64 |
+
d = gr.update(value=0)
|
65 |
+
tog = gr.update(value=0)
|
66 |
+
#print (f'passing: to: {to} et: {et}')
|
67 |
+
pass
|
68 |
+
return d, tog
|
69 |
+
|
70 |
+
def all_task_start():
|
71 |
+
print("\n\n\n\n\n\n\n")
|
72 |
+
t = time.gmtime()
|
73 |
+
t_stamp = time.time()
|
74 |
+
current_time = time.strftime("%H:%M:%S", t)
|
75 |
+
return gr.update(value=t_stamp), gr.update(value=t_stamp), gr.update(value=0)
|
76 |
+
|
77 |
+
def clear_fn():
|
78 |
+
nn = len(models)
|
79 |
+
return tuple([None, *[None for _ in range(nn)]])
|
80 |
+
|
81 |
+
|
82 |
+
with gr.Blocks(title="SD Models") as my_interface:
|
83 |
+
with gr.Column(scale=12):
|
84 |
+
# with gr.Row():
|
85 |
+
# gr.Markdown("""- Primary prompt: 你想画的内容(英文单词,如 a cat, 加英文逗号效果更好;点 Improve 按钮进行完善)\n- Real prompt: 完善后的提示词,出现后再点右边的 Run 按钮开始运行""")
|
86 |
+
with gr.Row():
|
87 |
+
with gr.Row(scale=6):
|
88 |
+
primary_prompt=gr.Textbox(label="Prompt", value="")
|
89 |
+
# real_prompt=gr.Textbox(label="Real prompt")
|
90 |
+
with gr.Row(scale=6):
|
91 |
+
# improve_prompts_btn=gr.Button("Improve")
|
92 |
+
with gr.Row():
|
93 |
+
run=gr.Button("Run",variant="primary")
|
94 |
+
clear_btn=gr.Button("Clear")
|
95 |
+
with gr.Row():
|
96 |
+
sd_outputs = {}
|
97 |
+
model_idx = 1
|
98 |
+
for model_path in models:
|
99 |
+
with gr.Column(scale=3, min_width=320):
|
100 |
+
with gr.Box():
|
101 |
+
sd_outputs[model_idx] = gr.Image(label=model_path)
|
102 |
+
pass
|
103 |
+
model_idx += 1
|
104 |
+
pass
|
105 |
+
pass
|
106 |
+
|
107 |
+
with gr.Row(visible=False):
|
108 |
+
start_box=gr.Number(interactive=False)
|
109 |
+
end_box=gr.Number(interactive=False)
|
110 |
+
tog_box=gr.Textbox(value=0,interactive=False)
|
111 |
+
|
112 |
+
start_box.change(
|
113 |
+
all_task_end,
|
114 |
+
[start_box, end_box],
|
115 |
+
[start_box, tog_box],
|
116 |
+
every=1,
|
117 |
+
show_progress=True)
|
118 |
+
|
119 |
+
primary_prompt.submit(all_task_start, None, [start_box, end_box, tog_box])
|
120 |
+
run.click(all_task_start, None, [start_box, end_box, tog_box])
|
121 |
+
runs_dict = {}
|
122 |
+
model_idx = 1
|
123 |
+
for model_path in models:
|
124 |
+
runs_dict[model_idx] = run.click(model_functions[model_idx], inputs=[primary_prompt], outputs=[sd_outputs[model_idx]])
|
125 |
+
model_idx += 1
|
126 |
+
pass
|
127 |
+
pass
|
128 |
+
|
129 |
+
# improve_prompts_btn_clicked=improve_prompts_btn.click(
|
130 |
+
# get_prompts,
|
131 |
+
# inputs=[primary_prompt],
|
132 |
+
# outputs=[primary_prompt],
|
133 |
+
# cancels=list(runs_dict.values()))
|
134 |
+
clear_btn.click(
|
135 |
+
clear_fn,
|
136 |
+
None,
|
137 |
+
[primary_prompt, *list(sd_outputs.values())],
|
138 |
+
cancels=[*list(runs_dict.values())])
|
139 |
+
tog_box.change(
|
140 |
+
clear_it,
|
141 |
+
tog_box,
|
142 |
+
tog_box,
|
143 |
+
cancels=[*list(runs_dict.values())])
|
144 |
+
text_gen1=gr.Interface.load("spaces/phenomenon1981/MagicPrompt-Stable-Diffusion")
|
145 |
+
|
146 |
+
my_interface.queue(concurrency_count=600, status_update_rate=1)
|
147 |
+
my_interface.launch(inline=True, show_api=True)
|