Spaces:
Running
Running
File size: 3,493 Bytes
b6b08f6 3353a40 af2f25b 477a5c9 4b9f915 477a5c9 f9a8fb9 477a5c9 af2f25b 8646ee7 a2ffcba 4b9f915 6a0cf2a 4b9f915 7ca712f 4b9f915 59afa4a 4b9f915 59afa4a 7a306db 4b9f915 59afa4a 7a306db 9d3f500 a2ffcba 9d3f500 075ed3d 9d3f500 5cc94ec a2ffcba 075ed3d 184a373 ae7a8b1 9d3f500 5a5ad3c 184a373 b6eb1a4 184a373 b6eb1a4 184a373 cead56a e540908 4b9f915 184a373 ae7a8b1 5cc94ec 7ca712f fe498d1 cc054c3 7ca712f bda4a03 fe498d1 f421cb2 5a5ad3c 8646ee7 af2f25b |
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 |
import gradio as gr
import requests
import os
import random
import time
name2 = "runwayml/stable-diffusion-v1-5"
models=[
gr.Interface.load(f"models/{name2}"),
gr.Interface.load(f"models/{name2}"),
gr.Interface.load(f"models/{name2}"),
gr.Interface.load(f"models/{name2}"),
gr.Interface.load(f"models/{name2}"),
gr.Interface.load(f"models/{name2}"),
gr.Interface.load(f"models/{name2}"),
gr.Interface.load(f"models/{name2}"),
gr.Interface.load(f"models/{name2}"),
gr.Interface.load(f"models/{name2}"),
gr.Interface.load(f"models/{name2}"),
gr.Interface.load(f"models/{name2}"),
gr.Interface.load(f"models/{name2}"),
gr.Interface.load(f"models/{name2}"),
gr.Interface.load(f"models/{name2}"),
gr.Interface.load(f"models/{name2}"),
gr.Interface.load(f"models/{name2}"),
gr.Interface.load(f"models/{name2}"),
gr.Interface.load(f"models/{name2}"),
gr.Interface.load(f"models/{name2}"),
]
o = os.getenv("P")
def ac():
def clear(v):
if int(v) != 0:
v = 0
else:
v = 0
pass
return gr.update(value=0)
def start():
stamp = time.time()
return gr.update(value=stamp),gr.update(value=0),None,None,None,None,gr.update(value=0)
def end(stamp):
ts = stamp + 6
ti = time.time()
if ti > ts and stamp != 0:
print("Cancelling")
return gr.update(value=1)
else:
print("Passing")
return gr.update(value=0)
def im_fn(put,fac="",fac_c=None,h=None):
if h == o:
if int(fac_c)==1:
rn = random.randint(0, 19)
model=models[rn]
put = f"{put}{fac}"
fac = f"{fac} "
print (rn)
return model(put),fac,1
elif int(fac_c)!=1:
return None,"",0
elif h != o:
return(None,"",0)
def cl_fac():
return "",0,None,None,None,None
with gr.Blocks() as b:
with gr.Row():
put = gr.Textbox()
btn1 = gr.Button()
with gr.Row():
out1 = gr.Image()
out2 = gr.Image()
with gr.Row():
out3 = gr.Image()
out4 = gr.Image()
with gr.Row(visible=False):
h=gr.Textbox("Q")
t_state=gr.Number()
t_switch=gr.Textbox(value=0)
fac_b = gr.Textbox(value="",visible=False)
fac_c = gr.Textbox(value=0)
fac_d = gr.Textbox(value=1)
#b3=out1.change(im_fn,[put,fac_b,fac_c,h],[out2,fac_b,fac_c])
#b4=out2.change(im_fn,[put,fac_b,fac_c,h],[out3,fac_b,fac_c])
#b5=out3.change(im_fn,[put,fac_b,fac_c,h],[out4,fac_b,fac_c])
b1=btn1.click(start,None,[t_state,t_switch,out1,out2,out3,out4,fac_c])
sta = t_state.change(end,t_state,t_switch,every=1)
b2=btn1.click(im_fn,[put,fac_b,fac_d,h],[out1,fac_b,fac_c])
b3=out1.change(im_fn,[put,fac_b,fac_c,h],[out2,fac_b,fac_c])
b4=out2.change(im_fn,[put,fac_b,fac_c,h],[out3,fac_b,fac_c])
b5=out3.change(im_fn,[put,fac_b,fac_c,h],[out4,fac_b,fac_c])
#b0=btn1.click(cl_fac,None,[fac_b,fac_c,out1,out2,out3,out4],show_progress=False)
t_switch.change(clear,t_switch,t_switch, cancels=[sta,b2,b3,b4,b5])
b.queue(concurrency_count=100).launch(show_api=False)
ac() |