leonel1122 commited on
Commit
b6b68b0
1 Parent(s): fc55fa3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +3 -414
app.py CHANGED
@@ -1,415 +1,4 @@
1
- import gradio as gr
2
- import os
3
- import sys
4
- from pathlib import Path
5
- import time
6
-
7
-
8
- text_gen=gr.Interface.load("spaces/Omnibus/MagicPrompt-Stable-Diffusion",live=True, preprocess=True)
9
-
10
-
11
- proc1=gr.Interface.load("models/nitrosocke/Arcane-Diffusion", live=True, every=5,preprocess=True, postprocess=False)
12
- proc2=gr.Interface.load("models/naclbit/trinart_stable_diffusion_v2", live=False, preprocess=True, postprocess=False)
13
- proc3=gr.Interface.load("models/nitrosocke/redshift-diffusion", live=False, preprocess=True, postprocess=False)
14
- proc4=gr.Interface.load("models/runwayml/stable-diffusion-v1-5", live=False, preprocess=True, postprocess=False)
15
-
16
- proc5=gr.Interface.load("models/claudfuen/photorealistic-fuen-v1", live=False, preprocess=True, postprocess=False)
17
- proc6=gr.Interface.load("models/CompVis/stable-diffusion-v1-4", live=False, preprocess=True, postprocess=False)
18
- proc7=gr.Interface.load("models/Linaqruf/anything-v3.0", live=False, preprocess=True, postprocess=False)
19
- proc8=gr.Interface.load("models/andite/anything-v4.0", live=False, preprocess=True, postprocess=False)
20
-
21
- proc9=gr.Interface.load("models/dreamlike-art/dreamlike-photoreal-1.0", live=False, preprocess=True, postprocess=False)
22
- proc10=gr.Interface.load("models/prompthero/openjourney", live=False, preprocess=True, postprocess=False)
23
- proc11=gr.Interface.load("models/prompthero/midjourney-v4-diffusion", live=False, preprocess=True, postprocess=False)
24
- proc12=gr.Interface.load("models/wavymulder/Analog-Diffusion", live=False, preprocess=True, postprocess=False)
25
-
26
-
27
- #proc13=gr.Interface.load("models/dreamlike-art/dreamlike-photoreal-2.0")
28
- #proc14=gr.Interface.load("models/wavymulder/Analog-Diffusion")
29
- #proc15=gr.Interface.load("models/nitrosocke/redshift-diffusion")
30
- #proc16=gr.Interface.load("models/prompthero/midjourney-v4-diffusion")
31
- # Import the library signal
32
- #import signal
33
- # Define an alarm clock for delivery of signal
34
- #signal.signal(signal.SIGALRM, lambda signum,frame: print('\nYour time got over'))
35
-
36
-
37
- def get_prompts(prompt_text):
38
- return text_gen(prompt_text)
39
-
40
-
41
-
42
- # Import the libraries
43
- from threading import Timer
44
- # Take seconds as integer input
45
- # for the time limit per question
46
- input_time = 5
47
- # Set the timer for the specified time and call the
48
- # function to print the message when time is over
49
- t = Timer(input_time, lambda: print("\nYour writing time is over!!\nEnter / to quit the program"))
50
 
51
-
52
- def send_it1(inputs,proc1=proc1):
53
- #############
54
- output1=None
55
- # Start the timer
56
- t.start()
57
- while t < input_time:
58
-
59
- output1=proc1(inputs)
60
- else:
61
- output1=None
62
- pass
63
- t.cancel()
64
-
65
- return output1
66
-
67
-
68
- def send_it2(inputs,proc2=proc2):
69
- timeout = time.time() + 60/5 # 5 minutes from now
70
- while True:
71
- output2=proc2(inputs)
72
- if time.time() > timeout:
73
- break
74
- return(output2)
75
- def send_it3(inputs,proc3=proc3):
76
- timeout = time.time() + 60/5 # 5 minutes from now
77
- while True:
78
- output3=proc3(inputs)
79
- if time.time() > timeout:
80
- break
81
- return(output3)
82
- def send_it4(inputs,proc4=proc4):
83
- timeout = time.time() + 60/5 # 5 minutes from now
84
- while True:
85
- output4=proc4(inputs)
86
- if time.time() > timeout:
87
- break
88
- return(output4)
89
-
90
- def send_it5(inputs,proc5=proc5):
91
- output5=proc5(inputs)
92
- return(output5)
93
- def send_it6(inputs,proc6=proc6):
94
- output6=proc6(inputs)
95
- return(output6)
96
- def send_it7(inputs,proc7=proc7):
97
- output7=proc7(inputs)
98
- return(output7)
99
- def send_it8(inputs,proc8=proc8):
100
- output8=proc8(inputs)
101
- return(output8)
102
-
103
- def send_it9(inputs,proc9=proc9):
104
- output9=proc9(inputs)
105
- return(output9)
106
- def send_it10(inputs,proc10=proc10):
107
- output10=proc10(inputs)
108
- return(output10)
109
- def send_it11(inputs,proc11=proc11):
110
- output11=proc11(inputs)
111
- return(output11)
112
- def send_it12(inputs,proc12=proc12):
113
- output12=proc12(inputs)
114
- return(output12)
115
-
116
- '''
117
- def up_it1(inputs,proc1=proc1):
118
- output1=proc1(inputs)
119
- return(output1)
120
- def up_it2(inputs,proc2=proc2):
121
- output2=proc2(inputs)
122
- return(output2)
123
- def up_it3(inputs,proc3=proc3):
124
- output3=proc3(inputs)
125
- return(output3)
126
- def up_it4(inputs,proc4=proc4):
127
- output4=proc4(inputs)
128
- return(output4)
129
-
130
- def up_it5(inputs,proc5=proc5):
131
- output5=proc5(inputs)
132
- return(output5)
133
- def up_it6(inputs,proc6=proc6):
134
- output6=proc6(inputs)
135
- return(output6)
136
- def up_it7(inputs,proc7=proc7):
137
- output7=proc7(inputs)
138
- return(output7)
139
- def up_it8(inputs,proc8=proc8):
140
- output8=proc8(inputs)
141
- return(output8)
142
-
143
- def up_it9(inputs,proc9=proc9):
144
- output9=proc9(inputs)
145
- return(output9)
146
- def up_it10(inputs,proc10=proc10):
147
- output10=proc10(inputs)
148
- return(output10)
149
- def up_it11(inputs,proc11=proc11):
150
- output11=proc11(inputs)
151
- return(output11)
152
- def up_it12(inputs,proc12=proc12):
153
- output12=proc12(inputs)
154
- return(output12)
155
-
156
- #def send_it13(inputs,proc13=proc13):
157
- # output13=proc13(inputs)
158
- # return(output13)
159
- #def send_it14(inputs,proc14=proc14):
160
- # output14=proc14(inputs)
161
- # return(output14)
162
- #def send_it15(inputs,proc15=proc15):
163
- # output15=proc15(inputs)
164
- # return(output15)
165
- #def send_it16(inputs,proc16=proc16):
166
- # output16=proc16(inputs)
167
- # return(output16)
168
-
169
- '''
170
- def main():
171
- #test = 0
172
-
173
-
174
-
175
- #batch=True, max_batch_size=30
176
- #max_batch_size=20
177
- with gr.Blocks(batch=False) as myface:
178
- with gr.Row():
179
- with gr.Tab("Title"):
180
- gr.HTML(""" <title>Maximum Diffusion</title><div style="text-align: center; max-width: 1500px; margin: 0 auto;">
181
- <div
182
- style="
183
- display: inline-flex;
184
- align-items: center;
185
- gap: 0.8rem;
186
- font-size: 1.75rem;
187
- margin-bottom: 10px;
188
- line-height: 1em;
189
- "
190
- >
191
- <h1 style="font-weight: 1200; margin-top: 9px;">
192
- Maximum Diffusion
193
- </h1>
194
- </div>
195
- <br>
196
- <br>
197
- <p style="margin-bottom: 10px;font-size: 94%;font-weight: 100;line-height: 1.5em;">
198
- Text to Image Model Comparison Space - CPU
199
- </p><br><br>
200
- <p style="margin-bottom: 10px;font-size: 94%;font-weight: 100;line-height: 1.5em;">
201
- Freaky Fast, when it's fresh<br>
202
- Try a Mirror, or DIY for Maximum Diffusion in minimum time.
203
- </p><br>
204
-
205
-
206
- </div>
207
- """)
208
-
209
-
210
-
211
- with gr.Tab("Description"):
212
- gr.HTML("""<div style="text-align:center;">
213
- <h4>Enter your Prompt into the "Short Prompt" box and click "Magic Prompt" to load a prettified version of your prompt<br>
214
- When you are satisfied with the prompt that is in the "Text to Image" box, click "Launch" to load the Models.<br><br>
215
- Images load faster with a simpler prompt.<br>
216
- Most images should load within 2 minutes.<br>
217
- Some models become stuck on certain prompts, and refreshing the page seems to fix it.<br><br>
218
- Not responsible for content, use at your own risk.
219
-
220
- </h4>
221
- </div>""")
222
- with gr.Tab("DIY"):
223
- gr.HTML("""<div style="text-align:Left;">
224
- <h4>Copy/Paste this code in your app.py file<br><br>
225
-
226
- import gradio as gr<br>
227
- max_d=gr.Interface.load("spaces/Omnibus/maximum_diffusion")<br>
228
- max_d.launch()<br>
229
- </h4>
230
- </div>""")
231
-
232
- with gr.Tab("Mirrors"):
233
- gr.HTML("""<div style="text-align:center;vertical-align:center;">
234
- <h4>Queue loading slow? Try a Mirror:<br><br>
235
- <a href="https://huggingface.co/spaces/Omnibus/maximum-diffusion-light">Maximum Diffusion Light 1</a><br>
236
- <p><a href="https://huggingface.co/spaces/Omnibus/maximum-diffusion-light-1">Maximum Diffusion Light 2</a><br>
237
- <p><a href="https://huggingface.co/spaces/Omnibus/maximum-diffusion-light-2">Maximum Diffusion Light 3</a>
238
-
239
-
240
- </h4>
241
- </div>""")
242
-
243
-
244
-
245
-
246
-
247
-
248
-
249
- with gr.Tab("Credits"):
250
- with gr.Row():
251
- gr.Column()
252
- with gr.Column(style="text-align:left;"):
253
- gr.HTML("""
254
- <div style="vertical-align:center">
255
- <br>
256
- <p>I learned everything I know from:
257
- <p><a href="https://huggingface.co/spaces/anzorq/finetuned_diffusion">Finetuned Diffusion</a></p>
258
- <p><a href="https://huggingface.co/spaces/Gustavosta/MagicPrompt-Stable-Diffusion">Magic Prompt Stable Diffusion</a></p>
259
- <p><a href="https://huggingface.co/spaces/huggingface-projects/magic-diffusion">Magic Diffusion</a></p>
260
-
261
- <p>Models by <a href="https://huggingface.co/Gustavosta">@Gustavosta</a>, <a href="https://twitter.com/haruu1367">@haruu1367</a>, <a href="https://twitter.com/DGSpitzer">@Helixngc7293</a>, <a href="https://twitter.com/dal_mack">@dal_mack</a>, <a href="https://twitter.com/prompthero">@prompthero</a> and others.</p>
262
- </div>
263
- """)
264
- gr.Column()
265
-
266
-
267
- with gr.Tab("Tools"):
268
- with gr.Tab("View"):
269
- with gr.Column(style="width=50%, height=70%"):
270
- gr.Pil(label="Crop")
271
- with gr.Column(style="width=50%, height=70%"):
272
- gr.Pil(label="Crop")
273
-
274
-
275
- with gr.Tab("Draw"):
276
- with gr.Column(style="width=50%, height=70%"):
277
- gr.Pil(label="Crop")
278
- with gr.Column(style="width=50%, height=70%"):
279
- gr.Pil(label="Draw")
280
-
281
-
282
- gr.ImagePaint(label="Draw")
283
-
284
- with gr.Tab("Text"):
285
- with gr.Row():
286
-
287
- with gr.Column(scale=50):
288
- gr.Textbox(label="", lines=8, interactive=True)
289
-
290
-
291
- with gr.Column(scale=50):
292
- gr.Textbox(label="", lines=8, interactive=True)
293
-
294
- with gr.Tab("Color Picker"):
295
- with gr.Row():
296
-
297
- with gr.Column(scale=50):
298
- gr.ColorPicker(label="Color", interactive=True)
299
-
300
-
301
- with gr.Column(scale=50):
302
- gr.ImagePaint(label="Draw", interactive=True)
303
-
304
-
305
-
306
- with gr.Row():
307
-
308
-
309
- input_text=gr.Textbox(label="Short Prompt")
310
- see_prompts=gr.Button("Magic Prompt")
311
- with gr.Row():
312
-
313
- prompt=gr.Textbox(label="Text to Image")
314
- run=gr.Button("Launch")
315
-
316
- # with gr.Row():
317
- # gr.Column()
318
- # with gr.Column():
319
- # clear_btn=gr.Button("Test")
320
-
321
-
322
- with gr.Row():
323
- output1=gr.Image(label="nitrosocke/Arcane-Diffusion")
324
- output2=gr.Image(label="naclbit/trinart_stable_diffusion_v2")
325
- output3=gr.Image(label="nitrosocke/redshift-diffusion")
326
- output4=gr.Image(label="runwayml/stable-diffusion-v1-5")
327
- with gr.Row():
328
- output5=gr.Image(label="claudfuen/photorealistic-fuen-v1")
329
- output6=gr.Image(label="CompVis/stable-diffusion-v1-4")
330
- output7=gr.Image(label="Linaqruf/anything-v3.0")
331
- output8=gr.Image(label="andite/anything-v4.0")
332
-
333
- with gr.Row():
334
- output9=gr.Image(label="dreamlike-art/dreamlike-photoreal-1.0")
335
- output10=gr.Image(label="prompthero/openjourney")
336
- output11=gr.Image(label="prompthero/midjourney-v4-diffusion")
337
- output12=gr.Image(label="wavymulder/Analog-Diffusion")
338
- with gr.Row():
339
- stat1=gr.Textbox(visible=False, value="running")
340
- stat2=gr.Textbox(visible=False, value="running")
341
- stat3=gr.Textbox(visible=False, value="running")
342
- stat4=gr.Textbox(visible=False, value="running")
343
- stat5=gr.Textbox(visible=False, value="running")
344
- stat6=gr.Textbox(visible=False, value="running")
345
- stat7=gr.Textbox(visible=False, value="running")
346
- stat8=gr.Textbox(visible=False, value="running")
347
- stat9=gr.Textbox(visible=False, value="running")
348
- stat10=gr.Textbox(visible=False, value="running")
349
- stat11=gr.Textbox(visible=False, value="running")
350
- stat12=gr.Textbox(visible=False, value="running")
351
-
352
-
353
- #with gr.Row():
354
- # output13=gr.Image(label="dreamlike-photoreal-2.0")
355
- # output14=gr.Image(label="Analog-Diffusion")
356
- #
357
- # output15=gr.Image(label="redshift-diffusion")
358
- # output16=gr.Image(label="midjourney-v4-diffusion")
359
-
360
-
361
-
362
- #def set_models(model_name1, model_name2, model_name3, model_name4):
363
-
364
- #return(proc1,proc2,proc3,proc4)
365
-
366
- #run.click(set_models, inputs=[model_name1, model_name2, model_name3, model_name4], outputs=[proc1,proc2,proc3,proc4])
367
- #run.click(send_it, inputs=[prompt], outputs=[output1, output2, output3, output4])
368
-
369
- def clear_queue():
370
-
371
- myface.queue.clear()
372
-
373
- #clear_btn.click(clear_queue, inputs=None, outputs=None)
374
- see_prompts.click(get_prompts, inputs=[input_text], outputs=[prompt])
375
- #timeout = time.time() + 5 #60*1 #1 minute # 5 minutes from now
376
-
377
- run.click(send_it1, inputs=[prompt], outputs=[output1])
378
- run.click(send_it2, inputs=[prompt], outputs=[output2])
379
- run.click(send_it3, inputs=[prompt], outputs=[output3])
380
- run.click(send_it4, inputs=[prompt], outputs=[output4])
381
- run.click(send_it5, inputs=[prompt], outputs=[output5])
382
- run.click(send_it6, inputs=[prompt], outputs=[output6])
383
- run.click(send_it7, inputs=[prompt], outputs=[output7])
384
- run.click(send_it8, inputs=[prompt], outputs=[output8])
385
- run.click(send_it9, inputs=[prompt], outputs=[output9])
386
- run.click(send_it10, inputs=[prompt], outputs=[output10])
387
- run.click(send_it11, inputs=[prompt], outputs=[output11])
388
- run.click(send_it12, inputs=[prompt], outputs=[output12])
389
-
390
- #output1.change(up_it1, inputs=[], outputs=[stat1])
391
- #output2.change(up_it2, inputs=[], outputs=[stat2])
392
- #output3.change(up_it3, inputs=[], outputs=[stat3])
393
- #output4.change(up_it4, inputs=[], outputs=[stat4])
394
- #output5.change(up_it5, inputs=[], outputs=[stat5])
395
- #output6.change(up_it6, inputs=[], outputs=[stat6])
396
- #output7.change(up_it7, inputs=[], outputs=[stat7])
397
- #output8.change(up_it8, inputs=[], outputs=[stat8])
398
- #output9.change(up_it9, inputs=[], outputs=[stat9])
399
- #output10.change(up_it10, inputs=[], outputs=[stat10])
400
- #output11.change(up_it11, inputs=[], outputs=[stat11])
401
- #output12.change(up_it12, inputs=[], outputs=[stat12])
402
- #run.click(send_it13, inputs=[prompt], outputs=[output13])
403
- #run.click(send_it14, inputs=[prompt], outputs=[output14])
404
- #run.click(send_it15, inputs=[prompt], outputs=[output15])
405
- #run.click(send_it16, inputs=[prompt], outputs=[output16])
406
-
407
- #myface.queue(default_enabled=False)
408
- #myface.queue(concurrency_count=240,status_update_rate=1)
409
-
410
- myface.queue(concurrency_count=800,status_update_rate=1)
411
- myface.launch(enable_queue=True,inline=True,max_threads=800)
412
-
413
- #myface.launch(enable_queue=True, max_threads=20)
414
- if __name__ == "__main__":
415
- main()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
 
2
+ import gradio as gr
3
+ max_d=gr.Interface.load("spaces/Omnibus/maximum_diffusion")
4
+ max_d.launch()