aexyb commited on
Commit
063b292
1 Parent(s): 0039b84

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +147 -0
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
+ "John6666/ultimate-realistic-mix-v2-sdxl",
9
+ "Yntec/ChickFlick",
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
+
20
+ model_functions = {}
21
+ model_idx = 1
22
+ for model_path in models:
23
+ try:
24
+ model_functions[model_idx] = gr.Interface.load(f"models/{model_path}", live=False, preprocess=True, postprocess=False)
25
+ except Exception as error:
26
+ def the_fn(txt):
27
+
28
+ return None
29
+ model_functions[model_idx] = gr.Interface(fn=the_fn, inputs=["text"], outputs=["image"])
30
+
31
+ model_idx+=1
32
+
33
+
34
+ def send_it_idx(idx):
35
+ def send_it_fn(prompt):
36
+ output = (model_functions.get(str(idx)) or model_functions.get(str(1)))(prompt)
37
+ return output
38
+ return send_it_fn
39
+
40
+ def get_prompts(prompt_text):
41
+
42
+ text_gen1=gr.Interface.load("spaces/phenomenon1981/MagicPrompt-Stable-Diffusion")
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
+
83
+ with gr.Blocks(title="SD Models") as my_interface:
84
+ with gr.Column(scale=12):
85
+ # with gr.Row():
86
+ # gr.Markdown("""- Primary prompt: 你想画的内容(英文单词,如 a cat, 加英文逗号效果更好;点 Improve 按钮进行完善)\n- Real prompt: 完善后的提示词,出现后再点右边的 Run 按钮开始运行""")
87
+ with gr.Row():
88
+ with gr.Row(scale=6):
89
+ primary_prompt=gr.Textbox(label="Prompt", value="")
90
+ # real_prompt=gr.Textbox(label="Real prompt")
91
+ with gr.Row(scale=6):
92
+ # improve_prompts_btn=gr.Button("Improve")
93
+ with gr.Row():
94
+ run=gr.Button("Run",variant="primary")
95
+ clear_btn=gr.Button("Clear")
96
+ with gr.Row():
97
+ sd_outputs = {}
98
+ model_idx = 1
99
+ for model_path in models:
100
+ with gr.Column(scale=3, min_width=320):
101
+ with gr.Box():
102
+ sd_outputs[model_idx] = gr.Image(label=model_path)
103
+ pass
104
+ model_idx += 1
105
+ pass
106
+ pass
107
+
108
+ with gr.Row(visible=False):
109
+ start_box=gr.Number(interactive=False)
110
+ end_box=gr.Number(interactive=False)
111
+ tog_box=gr.Textbox(value=0,interactive=False)
112
+
113
+ start_box.change(
114
+ all_task_end,
115
+ [start_box, end_box],
116
+ [start_box, tog_box],
117
+ every=1,
118
+ show_progress=True)
119
+
120
+ primary_prompt.submit(all_task_start, None, [start_box, end_box, tog_box])
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(model_functions[model_idx], inputs=[primary_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=[primary_prompt],
134
+ # cancels=list(runs_dict.values()))
135
+ clear_btn.click(
136
+ clear_fn,
137
+ None,
138
+ [primary_prompt, *list(sd_outputs.values())],
139
+ cancels=[*list(runs_dict.values())])
140
+ tog_box.change(
141
+ clear_it,
142
+ tog_box,
143
+ tog_box,
144
+ cancels=[*list(runs_dict.values())])
145
+
146
+ my_interface.queue(concurrency_count=600, status_update_rate=1)
147
+ my_interface.launch(inline=True, show_api=False)