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