Dagfinn1962 commited on
Commit
11d50d8
1 Parent(s): c22268b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +49 -191
app.py CHANGED
@@ -13,108 +13,34 @@ from pathlib import Path
13
  # ]
14
 
15
  models = [
16
- "",
17
- "runwayml/stable-diffusion-v1-5",
18
- "CompVis/stable-diffusion-v1-4",
19
- "claudfuen/photorealistic-fuen-v1",
20
- "andite/anything-v4.0",
21
- "naclbit/trinart_stable_diffusion_v2",
22
- "nitrosocke/Arcane-Diffusion",
23
- "nitrosocke/archer-diffusion",
24
- "nitrosocke/elden-ring-diffusion",
25
- "nitrosocke/redshift-diffusion",
26
- "nitrosocke/spider-verse-diffusion",
27
- "nitrosocke/mo-di-diffusion",
28
- "nitrosocke/classic-anim-diffusion",
29
- "dreamlike-art/dreamlike-photoreal-1.0",
30
- "dreamlike-art/dreamlike-photoreal-2.0",
31
- "wavymulder/wavyfusion",
32
- "wavymulder/Analog-Diffusion",
33
- "prompthero/midjourney-v4-diffusion",
34
- "prompthero/openjourney",
35
- "dallinmackay/Van-Gogh-diffusion",
36
- "hakurei/waifu-diffusion",
37
- "DGSpitzer/Cyberpunk-Anime-Diffusion",
38
- "Fictiverse/Stable_Diffusion_BalloonArt_Model",
39
- "dallinmackay/Tron-Legacy-diffusion",
40
- "AstraliteHeart/pony-diffusion",
41
- "nousr/robo-diffusion",
42
- "Linaqruf/anything-v3",
43
- "Omnibus/maximum_diffusion_fast",
44
- "",
45
- ]
46
- model_1=models[1]
47
- model_2=models[2]
48
- model_3=models[3]
49
- model_4=models[4]
50
-
51
- model_5=models[5]
52
- model_6=models[6]
53
- model_7=models[9]
54
- model_8=models[13]
55
-
56
- model_9=models[14]
57
- model_10=models[15]
58
- model_11=models[16]
59
- model_12=models[17]
60
-
61
- text_gen=gr.Interface.load("spaces/Omnibus/MagicPrompt-Stable-Diffusion_link",live=True, preprocess=True)
62
-
63
- proc1=gr.Interface.load(f"models/{model_1}",live=False,preprocess=True, postprocess=False)
64
- proc2=gr.Interface.load(f"models/{model_2}",live=False,preprocess=True, postprocess=False)
65
- proc3=gr.Interface.load(f"models/{model_3}",live=False,preprocess=True, postprocess=False)
66
- proc4=gr.Interface.load(f"models/{model_4}",live=False,preprocess=True, postprocess=False)
67
-
68
- proc5=gr.Interface.load(f"models/{model_5}",live=False,preprocess=True, postprocess=False)
69
- proc6=gr.Interface.load(f"models/{model_6}",live=False,preprocess=True, postprocess=False)
70
- proc7=gr.Interface.load(f"models/{model_7}",live=False,preprocess=True, postprocess=False)
71
- proc8=gr.Interface.load(f"models/{model_8}",live=False,preprocess=True, postprocess=False)
72
-
73
- proc9=gr.Interface.load(f"models/{model_9}",live=False,preprocess=True, postprocess=False)
74
- proc10=gr.Interface.load(f"models/{model_10}",live=False,preprocess=True, postprocess=False)
75
- proc11=gr.Interface.load(f"models/{model_11}",live=False,preprocess=True, postprocess=False)
76
- proc12=gr.Interface.load(f"models/{model_12}",live=False,preprocess=True, postprocess=False)
77
-
78
- def get_prompts(prompt_text):
79
- return text_gen(prompt_text)
80
- def send_it1(inputs,proc1=proc1):
81
- output1=proc1(inputs)
82
- return(output1)
83
- def send_it2(inputs,proc2=proc2):
84
- output2=proc2(inputs)
85
- return(output2)
86
- def send_it3(inputs,proc3=proc3):
87
- output3=proc3(inputs)
88
- return(output3)
89
- def send_it4(inputs,proc4=proc4):
90
- output4=proc4(inputs)
91
- return(output4)
92
-
93
- def send_it5(inputs,proc5=proc5):
94
- output5=proc5(inputs)
95
- return(output5)
96
- def send_it6(inputs,proc6=proc6):
97
- output6=proc6(inputs)
98
- return(output6)
99
- def send_it7(inputs,proc7=proc7):
100
- output7=proc7(inputs)
101
- return(output7)
102
- def send_it8(inputs,proc8=proc8):
103
- output8=proc8(inputs)
104
- return(output8)
105
-
106
- def send_it9(inputs,proc9=proc9):
107
- output9=proc9(inputs)
108
- return(output9)
109
- def send_it10(inputs,proc10=proc10):
110
- output10=proc10(inputs)
111
- return(output10)
112
- def send_it11(inputs,proc11=proc11):
113
- output11=proc11(inputs)
114
- return(output11)
115
- def send_it12(inputs,proc12=proc12):
116
- output12=proc12(inputs)
117
- return(output12)
118
 
119
 
120
  with gr.Blocks (css = 'main.css') as myface:
@@ -137,92 +63,24 @@ with gr.Blocks (css = 'main.css') as myface:
137
 
138
  with gr.Row():
139
  output1 = gr.Image(label="")
140
-
141
- with gr.Row():
142
- magic1 = gr.Textbox(label="2. GENERATE IMAGE HERE ! ", lines=2)
143
-
144
- with gr.Row():
145
- with gr.Column():
146
- input_text=gr.Textbox(label="Short Prompt")
147
- prompt=gr.Textbox(label="Text to Image")
148
- with gr.Column():
149
- see_prompts=gr.Button("Magic Prompt")
150
- with gr.Row():
151
- run=gr.Button("Launch")
152
- clear_btn=gr.Button("Clear")
153
-
154
- with gr.Row():
155
- output1=gr.Image(label=(f"{model_1}"),visible=True)
156
- output2=gr.Image(label=(f"{model_2}"),visible=True)
157
- output3=gr.Image(label=(f"{model_3}"),visible=True)
158
- output4=gr.Image(label=(f"{model_4}"),visible=True)
159
- with gr.Row():
160
- output5=gr.Image(label=(f"{model_5}"),visible=True)
161
- output6=gr.Image(label=(f"{model_6}"),visible=True)
162
- output7=gr.Image(label=(f"{model_7}"),visible=True)
163
- output8=gr.Image(label=(f"{model_8}"),visible=True)
164
- with gr.Row():
165
- output9=gr.Image(label=(f"{model_9}"),visible=True)
166
- output10=gr.Image(label=(f"{model_10}"),visible=True)
167
- output11=gr.Image(label=(f"{model_11}"),visible=True)
168
- output12=gr.Image(label=(f"{model_12}"),visible=True)
169
- with gr.Row(visible=True):
170
- start_box=gr.Number(interactive=False)
171
- end_box=gr.Number(interactive=False)
172
- tog_box=gr.Textbox(value=0,interactive=False)
173
-
174
-
175
-
176
- def clear_it(val):
177
- if int(val) != 0:
178
- val = 0
179
- else:
180
- val = 0
181
- pass
182
- return val
183
- def sesh_end(cnt,t_stamp):
184
- to = t_stamp + 120
185
- et = time.time()
186
- if et > to and t_stamp != 0:
187
- d=gr.update(value=0)
188
- tog=gr.update(value=1)
189
- #print(f'to: {to} et: {et}')
190
- else:
191
- if cnt != 0:
192
- d=gr.update(value=et)
193
- else:
194
- d=gr.update(value=0)
195
- tog=gr.update(value=0)
196
- #print (f'passing: to: {to} et: {et}')
197
- pass
198
- return d,tog
199
- def sesh_start():
200
- t = time.gmtime()
201
- t_stamp = time.time()
202
- current_time = time.strftime("%H:%M:%S", t)
203
- return gr.update(value=t_stamp),gr.update(value=t_stamp),gr.update(value=0)
204
- def clear_fn():
205
- return None,None,None,None,None,None,None,None,None,None,None,None,None,None
206
-
207
- start_box.change(sesh_end,[start_box,end_box],[start_box,tog_box],show_progress=False)
208
- run.click(sesh_start,None,[start_box,end_box,tog_box])
209
- run1=run.click(send_it1, inputs=[prompt], outputs=[output1])
210
- run2=run.click(send_it2, inputs=[prompt], outputs=[output2])
211
- run3=run.click(send_it3, inputs=[prompt], outputs=[output3])
212
- run4=run.click(send_it4, inputs=[prompt], outputs=[output4])
213
- run5=run.click(send_it5, inputs=[prompt], outputs=[output5])
214
- run6=run.click(send_it6, inputs=[prompt], outputs=[output6])
215
- run7=run.click(send_it7, inputs=[prompt], outputs=[output7])
216
- run8=run.click(send_it8, inputs=[prompt], outputs=[output8])
217
- run9=run.click(send_it9, inputs=[prompt], outputs=[output9])
218
- run10=run.click(send_it10, inputs=[prompt], outputs=[output10])
219
- run11=run.click(send_it11, inputs=[prompt], outputs=[output11])
220
- run12=run.click(send_it12, inputs=[prompt], outputs=[output12])
221
- prompt1=see_prompts.click(get_prompts, inputs=[input_text], outputs=[prompt],cancels=[run,run1,run2,run3,run4,run5,run6,run7,run8,run9,run10,run11,run12])
222
- tog_box.change(clear_it,tog_box,tog_box,cancels=[run1,run2,run3,run4,run5,run6,run7,run8,run9,run10,run11,run12,prompt1])
223
- clear_btn.click(clear_fn, None,
224
- [input_text,prompt,output1,output2,output3,output4,output5,output6,output7,output8,output9,output10,output11,output12],
225
- cancels=[prompt1,run1,run2,run3,run4,run5,run6,run7,run8,run9,run10,run11,run12])
226
-
227
- myface.queue(concurrency_count=600,status_update_rate=1)
228
- myface.launch(enable_queue=True,inline=True,max_threads=600, show_api=False)
 
13
  # ]
14
 
15
  models = [
16
+ {"name": "Stable Diffusion 1.4","url": "CompVis/stable-diffusion-v1-4"},
17
+ {"name": "Stable Diffusion 1.5","url": "runwayml/stable-diffusion-v1-5"},
18
+ ]
19
+
20
+ current_model = models[0]
21
+
22
+ text_gen = gr.Interface.load("spaces/daspartho/prompt-extend")
23
+
24
+ models2 = []
25
+ for model in models:
26
+ model_url = f"models/{model['url']}"
27
+ loaded_model = gr.Interface.load(model_url, live=True, preprocess=True)
28
+ models2.append(loaded_model)
29
+
30
+
31
+ def text_it(inputs, text_gen=text_gen):
32
+ return text_gen(inputs)
33
+
34
+
35
+ def set_model(current_model_index):
36
+ global current_model
37
+ current_model = models[current_model_index]
38
+ return gr.update(value=f"{current_model['name']}")
39
+
40
+
41
+ def send_it(inputs, model_choice):
42
+ proc = models2[model_choice]
43
+ return proc(inputs)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
44
 
45
 
46
  with gr.Blocks (css = 'main.css') as myface:
 
63
 
64
  with gr.Row():
65
  output1 = gr.Image(label="")
66
+ output2 = gr.Image(label="")
67
+ output3 = gr.Image(label="")
68
+ with gr.Row():
69
+ magic1 = gr.Textbox(label="Generated Prompt", lines=2)
70
+ magic2 = gr.Textbox(label="Generated Prompt", lines=2)
71
+ magic3 = gr.Textbox(label="Generated Prompt", lines=2)
72
+
73
+ model_name1.change(set_model, inputs=model_name1, outputs=[output1, output2, output3,])
74
+
75
+ run.click(send_it, inputs=[magic1, model_name1], outputs=[output1])
76
+ run.click(send_it, inputs=[magic2, model_name1], outputs=[output2])
77
+ run.click(send_it, inputs=[magic3, model_name1], outputs=[output3])
78
+
79
+
80
+ see_prompts.click(text_it, inputs=[input_text], outputs=[magic1])
81
+ see_prompts.click(text_it, inputs=[input_text], outputs=[magic2])
82
+ see_prompts.click(text_it, inputs=[input_text], outputs=[magic3])
83
+
84
+
85
+ myface.queue(concurrency_count=200)
86
+ myface.launch(inline=True, show_api=False, max_threads=400)