Delete app.py
Browse files
app.py
DELETED
@@ -1,144 +0,0 @@
|
|
1 |
-
import gradio as gr
|
2 |
-
# import os
|
3 |
-
# import sys
|
4 |
-
# from pathlib import Path
|
5 |
-
import time
|
6 |
-
|
7 |
-
models =[
|
8 |
-
"digiplay/polla_mix_2.3D",
|
9 |
-
"kayteekay/jordan-generator-v1",
|
10 |
-
"Meina/Unreal_V4.1",
|
11 |
-
"Meina/MeinaMix_V11",
|
12 |
-
"Erlalex/dominikof-v1-5-1",
|
13 |
-
"hearmeneigh/sd21-e621-rising-v1",
|
14 |
-
"Anna11/heera",
|
15 |
-
"kanu03/my-cat",
|
16 |
-
"Kernel/sd-nsfw",
|
17 |
-
"lodestones/P.A.W.F.E.C.T-Alpha",
|
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 |
-
return None
|
29 |
-
model_functions[model_idx] = gr.Interface(fn=the_fn, inputs=["text"], outputs=["image"])
|
30 |
-
model_idx+=1
|
31 |
-
|
32 |
-
|
33 |
-
def send_it_idx(idx):
|
34 |
-
def send_it_fn(prompt):
|
35 |
-
output = (model_functions.get(str(idx)) or model_functions.get(str(1)))(prompt)
|
36 |
-
return output
|
37 |
-
return send_it_fn
|
38 |
-
|
39 |
-
def get_prompts(prompt_text):
|
40 |
-
return prompt_text
|
41 |
-
|
42 |
-
def clear_it(val):
|
43 |
-
if int(val) != 0:
|
44 |
-
val = 0
|
45 |
-
else:
|
46 |
-
val = 0
|
47 |
-
pass
|
48 |
-
return val
|
49 |
-
|
50 |
-
def all_task_end(cnt,t_stamp):
|
51 |
-
to = t_stamp + 60
|
52 |
-
et = time.time()
|
53 |
-
if et > to and t_stamp != 0:
|
54 |
-
d = gr.update(value=0)
|
55 |
-
tog = gr.update(value=1)
|
56 |
-
#print(f'to: {to} et: {et}')
|
57 |
-
else:
|
58 |
-
if cnt != 0:
|
59 |
-
d = gr.update(value=et)
|
60 |
-
else:
|
61 |
-
d = gr.update(value=0)
|
62 |
-
tog = gr.update(value=0)
|
63 |
-
#print (f'passing: to: {to} et: {et}')
|
64 |
-
pass
|
65 |
-
return d, tog
|
66 |
-
|
67 |
-
def all_task_start():
|
68 |
-
print("\n\n\n\n\n\n\n")
|
69 |
-
t = time.gmtime()
|
70 |
-
t_stamp = time.time()
|
71 |
-
current_time = time.strftime("%H:%M:%S", t)
|
72 |
-
return gr.update(value=t_stamp), gr.update(value=t_stamp), gr.update(value=0)
|
73 |
-
|
74 |
-
def clear_fn():
|
75 |
-
nn = len(models)
|
76 |
-
return tuple([None, *[None for _ in range(nn)]])
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
with gr.Blocks(title="SD Models") as my_interface:
|
81 |
-
with gr.Column(scale=12):
|
82 |
-
# with gr.Row():
|
83 |
-
# gr.Markdown("""- Primary prompt: 你想画的内容(英文单词,如 a cat, 加英文逗号效果更好;点 Improve 按钮进行完善)\n- Real prompt: 完善后的提示词,出现后再点右边的 Run 按钮开始运行""")
|
84 |
-
with gr.Row():
|
85 |
-
with gr.Row(scale=6):
|
86 |
-
primary_prompt=gr.Textbox(label="Prompt", value="")
|
87 |
-
# real_prompt=gr.Textbox(label="Real prompt")
|
88 |
-
with gr.Row(scale=6):
|
89 |
-
# improve_prompts_btn=gr.Button("Improve")
|
90 |
-
with gr.Row():
|
91 |
-
run=gr.Button("Run",variant="primary")
|
92 |
-
clear_btn=gr.Button("Clear")
|
93 |
-
with gr.Row():
|
94 |
-
sd_outputs = {}
|
95 |
-
model_idx = 1
|
96 |
-
for model_path in models:
|
97 |
-
with gr.Column(scale=3, min_width=320):
|
98 |
-
with gr.Box():
|
99 |
-
sd_outputs[model_idx] = gr.Image(label=model_path)
|
100 |
-
pass
|
101 |
-
model_idx += 1
|
102 |
-
pass
|
103 |
-
pass
|
104 |
-
|
105 |
-
with gr.Row(visible=False):
|
106 |
-
start_box=gr.Number(interactive=False)
|
107 |
-
end_box=gr.Number(interactive=False)
|
108 |
-
tog_box=gr.Textbox(value=0,interactive=False)
|
109 |
-
|
110 |
-
start_box.change(
|
111 |
-
all_task_end,
|
112 |
-
[start_box, end_box],
|
113 |
-
[start_box, tog_box],
|
114 |
-
every=1,
|
115 |
-
show_progress=False)
|
116 |
-
|
117 |
-
primary_prompt.submit(all_task_start, None, [start_box, end_box, tog_box])
|
118 |
-
run.click(all_task_start, None, [start_box, end_box, tog_box])
|
119 |
-
runs_dict = {}
|
120 |
-
model_idx = 1
|
121 |
-
for model_path in models:
|
122 |
-
runs_dict[model_idx] = run.click(model_functions[model_idx], inputs=[primary_prompt], outputs=[sd_outputs[model_idx]])
|
123 |
-
model_idx += 1
|
124 |
-
pass
|
125 |
-
pass
|
126 |
-
|
127 |
-
# improve_prompts_btn_clicked=improve_prompts_btn.click(
|
128 |
-
# get_prompts,
|
129 |
-
# inputs=[primary_prompt],
|
130 |
-
# outputs=[primary_prompt],
|
131 |
-
# cancels=list(runs_dict.values()))
|
132 |
-
clear_btn.click(
|
133 |
-
clear_fn,
|
134 |
-
None,
|
135 |
-
[primary_prompt, *list(sd_outputs.values())],
|
136 |
-
cancels=[*list(runs_dict.values())])
|
137 |
-
tog_box.change(
|
138 |
-
clear_it,
|
139 |
-
tog_box,
|
140 |
-
tog_box,
|
141 |
-
cancels=[*list(runs_dict.values())])
|
142 |
-
|
143 |
-
my_interface.queue(concurrency_count=600, status_update_rate=1)
|
144 |
-
my_interface.launch(inline=True, show_api=False)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|