Brian Watson commited on
Commit
d4d7ead
1 Parent(s): 22efa4c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +142 -100
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
- models = [
7
- {"name": "Claudfuen 1", "url": "sd-concepts-library/ahx-model-6"},
8
- {"name": "Deliberate", "url": "Masagin/Deliberate"},
9
- {"name": "Seek Art Mega", "url": "coreco/seek.art_MEGA"},
10
- {"name": "Realistic Vision 1.4", "url": "SG161222/Realistic_Vision_V1.4"},
11
- {"name": "Dreamshaper", "url": "Lykon/DreamShaper"},
 
 
 
 
 
 
 
 
 
 
12
  ]
13
 
14
- current_model = models[0]
15
 
16
- text_gen = gr.Interface.load("spaces/Omnibus/MagicPrompt-Stable-Diffusion_link")
17
-
18
- models2 = []
19
- for model in models:
20
- model_url = f"models/{model['url']}"
21
- loaded_model = gr.Interface.load(model_url, live=True, preprocess=True)
22
- models2.append(loaded_model)
23
-
24
-
25
- def text_it(inputs, text_gen=text_gen):
26
- return text_gen(inputs)
27
-
28
-
29
- def set_model(current_model_index):
30
- global current_model
31
- current_model = models[current_model_index]
32
- return gr.update(value=f"{current_model['name']}")
33
-
34
-
35
- def send_it(inputs, model_choice):
36
- proc = models2[model_choice]
37
- return proc(inputs)
38
-
39
-
40
- with gr.Blocks() as myface:
41
- gr.HTML(
42
-
43
- )
44
-
45
- with gr.Row():
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
46
  with gr.Row():
47
- input_text = gr.Textbox(label="Prompt idea", lines=1)
48
- # Model selection dropdown
49
- model_name1 = gr.Dropdown(
50
- label="Choose Model",
51
- choices=[m["name"] for m in models],
52
- type="index",
53
- value=current_model["name"],
54
- interactive=True,
55
- )
56
  with gr.Row():
57
- see_prompts = gr.Button("Generate Prompts")
58
- run = gr.Button("Generate Images", variant="primary")
59
-
60
- with gr.Row():
61
- output1 = gr.Image(label="")
62
- output2 = gr.Image(label="")
63
- with gr.Row():
64
- magic1 = gr.Textbox(lines=2)
65
- magic2 = gr.Textbox(lines=2)
66
- with gr.Row():
67
- output3 = gr.Image(label="")
68
- output4 = gr.Image(label="")
69
- with gr.Row():
70
- magic3 = gr.Textbox(lines=2)
71
- magic4 = gr.Textbox(lines=2)
72
- with gr.Row():
73
- output5 = gr.Image(label="")
74
- output6 = gr.Image(label="")
75
- with gr.Row():
76
- magic5 = gr.Textbox(lines=2)
77
- magic6 = gr.Textbox(lines=2)
78
- with gr.Row():
79
- output7 = gr.Image(label="")
80
- output8 = gr.Image(label="")
81
- with gr.Row():
82
- magic7 = gr.Textbox(lines=2)
83
- magic8 = gr.Textbox(lines=2)
84
-
85
- model_name1.change(set_model, inputs=model_name1, outputs=[output1, output2, output3, output4, output5, output6, output7, output8])
86
-
87
- run.click(send_it, inputs=[magic1, model_name1], outputs=[output1])
88
- run.click(send_it, inputs=[magic2, model_name1], outputs=[output2])
89
- run.click(send_it, inputs=[magic3, model_name1], outputs=[output3])
90
- run.click(send_it, inputs=[magic4, model_name1], outputs=[output4])
91
- run.click(send_it, inputs=[magic5, model_name1], outputs=[output5])
92
- run.click(send_it, inputs=[magic6, model_name1], outputs=[output6])
93
- run.click(send_it, inputs=[magic7, model_name1], outputs=[output7])
94
- run.click(send_it, inputs=[magic8, model_name1], outputs=[output8])
95
-
96
- see_prompts.click(text_it, inputs=[input_text], outputs=[magic1])
97
- see_prompts.click(text_it, inputs=[input_text], outputs=[magic2])
98
- see_prompts.click(text_it, inputs=[input_text], outputs=[magic3])
99
- see_prompts.click(text_it, inputs=[input_text], outputs=[magic4])
100
- see_prompts.click(text_it, inputs=[input_text], outputs=[magic5])
101
- see_prompts.click(text_it, inputs=[input_text], outputs=[magic6])
102
- see_prompts.click(text_it, inputs=[input_text], outputs=[magic7])
103
- see_prompts.click(text_it, inputs=[input_text], outputs=[magic8])
104
-
105
- myface.queue(concurrency_count=200)
106
- myface.launch(inline=True, show_api=False, max_threads=400)
 
 
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)