aexyb commited on
Commit
674ff96
1 Parent(s): e519c57

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +291 -0
app.py ADDED
@@ -0,0 +1,291 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ # import os
3
+ # import sys
4
+ # from pathlib import Path
5
+ import time
6
+
7
+ models =[
8
+ "John6666/ultimate-realistic-mix-v2-sdxl",
9
+ "SG161222/RealVisXL_V3.0_Turbo",
10
+ "Yntec/DegreesOfFreedom",
11
+ "Yntec/UltraHighDefinition",
12
+ "John6666/9527-detail-realistic-xl-v55mix-sdxl",
13
+ "mann-e/Mann-E_Dreams",
14
+ "John6666/wai-real-mix-v8-sdxl",
15
+ "John6666/real-vis-xl-v40-sdxl",
16
+ "Yntec/BeautyFoolRemix",
17
+ ]
18
+
19
+ model_functions = {}
20
+ model_idx = 1
21
+ for model_path in models:
22
+ try:
23
+ model_functions[model_idx] = gr.Interface.load(f"models/{model_path}", live=False, preprocess=True, postprocess=False)
24
+ except Exception as error:
25
+ def the_fn(txt):
26
+
27
+ return None
28
+ model_functions[model_idx] = gr.Interface(fn=the_fn, inputs=["text"], outputs=["image"])
29
+
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
+
41
+ text_gen1=gr.Interface.load("spaces/phenomenon1981/MagicPrompt-Stable-Diffusion")
42
+ return prompt_text
43
+
44
+ def clear_it(val):
45
+ if int(val) != 0:
46
+ val = 0
47
+ else:
48
+ val = 0
49
+ pass
50
+ return val
51
+
52
+ def all_task_end(cnt,t_stamp):
53
+ to = t_stamp + 360
54
+ et = time.time()
55
+ if et > to and t_stamp != 0:
56
+ d = gr.update(value=0)
57
+ tog = gr.update(value=1)
58
+ #print(f'to: {to} et: {et}')
59
+ else:
60
+ if cnt != 0:
61
+ d = gr.update(value=et)
62
+ else:
63
+ d = gr.update(value=0)
64
+ tog = gr.update(value=0)
65
+ #print (f'passing: to: {to} et: {et}')
66
+ pass
67
+ return d, tog
68
+
69
+ def all_task_start():
70
+ print("\n\n\n\n\n\n\n")
71
+ t = time.gmtime()
72
+ t_stamp = time.time()
73
+ current_time = time.strftime("%H:%M:%S", t)
74
+ return gr.update(value=t_stamp), gr.update(value=t_stamp), gr.update(value=0)
75
+
76
+ def clear_fn():
77
+ nn = len(models)
78
+ return tuple([None, *[None for _ in range(nn)]])
79
+
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
+ import gradio as gr
129
+ # import os
130
+ # import sys
131
+ # from pathlib import Path
132
+ import time
133
+
134
+ models =[
135
+ "John6666/ultimate-realistic-mix-v2-sdxl",
136
+ "SG161222/RealVisXL_V3.0_Turbo",
137
+ "Yntec/DegreesOfFreedom",
138
+ "Yntec/UltraHighDefinition",
139
+ "John6666/9527-detail-realistic-xl-v55mix-sdxl",
140
+ "mann-e/Mann-E_Dreams",
141
+ "John6666/wai-real-mix-v8-sdxl",
142
+ "John6666/real-vis-xl-v40-sdxl",
143
+ "Yntec/BeautyFoolRemix",
144
+ ]
145
+
146
+ model_functions = {}
147
+ model_idx = 1
148
+ for model_path in models:
149
+ try:
150
+ model_functions[model_idx] = gr.Interface.load(f"models/{model_path}", live=False, preprocess=True, postprocess=False)
151
+ except Exception as error:
152
+ def the_fn(txt):
153
+
154
+ return None
155
+ model_functions[model_idx] = gr.Interface(fn=the_fn, inputs=["text"], outputs=["image"])
156
+
157
+ model_idx+=1
158
+
159
+
160
+ def send_it_idx(idx):
161
+ def send_it_fn(prompt):
162
+ output = (model_functions.get(str(idx)) or model_functions.get(str(1)))(prompt)
163
+ return output
164
+ return send_it_fn
165
+
166
+ def get_prompts(prompt_text):
167
+
168
+ text_gen1=gr.Interface.load("spaces/phenomenon1981/MagicPrompt-Stable-Diffusion")
169
+ return prompt_text
170
+
171
+ def clear_it(val):
172
+ if int(val) != 0:
173
+ val = 0
174
+ else:
175
+ val = 0
176
+ pass
177
+ return val
178
+
179
+ def all_task_end(cnt,t_stamp):
180
+ to = t_stamp + 360
181
+ et = time.time()
182
+ if et > to and t_stamp != 0:
183
+ d = gr.update(value=0)
184
+ tog = gr.update(value=1)
185
+ #print(f'to: {to} et: {et}')
186
+ else:
187
+ if cnt != 0:
188
+ d = gr.update(value=et)
189
+ else:
190
+ d = gr.update(value=0)
191
+ tog = gr.update(value=0)
192
+ #print (f'passing: to: {to} et: {et}')
193
+ pass
194
+ return d, tog
195
+
196
+ def all_task_start():
197
+ print("\n\n\n\n\n\n\n")
198
+ t = time.gmtime()
199
+ t_stamp = time.time()
200
+ current_time = time.strftime("%H:%M:%S", t)
201
+ return gr.update(value=t_stamp), gr.update(value=t_stamp), gr.update(value=0)
202
+
203
+ def clear_fn():
204
+ nn = len(models)
205
+ return tuple([None, *[None for _ in range(nn)]])
206
+
207
+
208
+
209
+ with gr.Blocks(title="SD Models") as my_interface:
210
+ with gr.Column(scale=12):
211
+ # with gr.Row():
212
+ # gr.Markdown("""- Primary prompt: 你想画的内容(英文单词,如 a cat, 加英文逗号效果更好;点 Improve 按钮进行完善)\n- Real prompt: 完善后的提示词,出现后再点右边的 Run 按钮开始运行""")
213
+ with gr.Row():
214
+ with gr.Row(scale=6):
215
+ primary_prompt=gr.Textbox(label="Prompt", value="")
216
+ # real_prompt=gr.Textbox(label="Real prompt")
217
+ with gr.Row(scale=6):
218
+ # improve_prompts_btn=gr.Button("Improve")
219
+ with gr.Row():
220
+ run=gr.Button("Run",variant="primary")
221
+ clear_btn=gr.Button("Clear")
222
+ with gr.Row():
223
+ sd_outputs = {}
224
+ model_idx = 1
225
+ for model_path in models:
226
+ with gr.Column(scale=3, min_width=320):
227
+ with gr.Box():
228
+ sd_outputs[model_idx] = gr.Image(label=model_path)
229
+ pass
230
+ model_idx += 1
231
+ pass
232
+ pass
233
+
234
+ with gr.Row(visible=False):
235
+ start_box=gr.Number(interactive=False)
236
+ end_box=gr.Number(interactive=False)
237
+ tog_box=gr.Textbox(value=0,interactive=False)
238
+
239
+ start_box.change(
240
+ all_task_end,
241
+ [start_box, end_box],
242
+ [start_box, tog_box],
243
+ every=1,
244
+ show_progress=True)
245
+
246
+ primary_prompt.submit(all_task_start, None, [start_box, end_box, tog_box])
247
+ run.click(all_task_start, None, [start_box, end_box, tog_box])
248
+ runs_dict = {}
249
+ model_idx = 1
250
+ for model_path in models:
251
+ runs_dict[model_idx] = run.click(model_functions[model_idx], inputs=[primary_prompt], outputs=[sd_outputs[model_idx]])
252
+ model_idx += 1
253
+ pass
254
+ text_gen1=gr.Interface.load("spaces/phenomenon1981/MagicPrompt-Stable-Diffusion")
255
+
256
+ # improve_prompts_btn_clicked=improve_prompts_btn.click(
257
+ # get_prompts,
258
+ # inputs=[primary_prompt],
259
+ # outputs=[primary_prompt],
260
+ # cancels=list(runs_dict.values()))
261
+ clear_btn.click(
262
+ clear_fn,
263
+ None,
264
+ [primary_prompt, *list(sd_outputs.values())],
265
+ cancels=[*list(runs_dict.values())])
266
+ tog_box.change(
267
+ clear_it,
268
+ tog_box,
269
+ tog_box,
270
+ cancels=[*list(runs_dict.values())])
271
+
272
+ my_interface.queue(concurrency_count=600, status_update_rate=1)
273
+
274
+
275
+ # improve_prompts_btn_clicked=improve_prompts_btn.click(
276
+ # get_prompts,
277
+ # inputs=[primary_prompt],
278
+ # outputs=[primary_prompt],
279
+ # cancels=list(runs_dict.values()))
280
+ clear_btn.click(
281
+ clear_fn,
282
+ None,
283
+ [primary_prompt, *list(sd_outputs.values())],
284
+ cancels=[*list(runs_dict.values())])
285
+ tog_box.change(
286
+ clear_it,
287
+ tog_box,
288
+ tog_box,
289
+ cancels=[*list(runs_dict.values())])
290
+
291
+ my_interface.queue(concurrency_count=600, status_update_rate=1)