|
|
import gradio as gr |
|
|
import os |
|
|
import requests |
|
|
import random |
|
|
import time |
|
|
r = requests.get(f'https://huggingface.co/spaces/xp3857/bin/raw/main/css.css') |
|
|
css = r.text |
|
|
name2 = "$name2" |
|
|
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 = "V" |
|
|
m_out = (""" |
|
|
<div id="restart"> |
|
|
<h3 id="head">Loading Time Limit Reached.</h3><br> |
|
|
<h4 id="cont">Please choose a Simpler Prompt, or Upgrade for faster loading.</h4> |
|
|
</div> |
|
|
""") |
|
|
loading=(""" |
|
|
<div class="lds-ellipsis"><div></div><div></div><div></div><div></div></div>""") |
|
|
def ac(): |
|
|
def clear(): |
|
|
return gr.update(value=0),gr.update(value=0),gr.HTML.update("",visible=False) |
|
|
def start(): |
|
|
stamp = time.time() |
|
|
return gr.update(value=stamp),gr.update(value=0) |
|
|
def end(stamp): |
|
|
ts = stamp + 120 |
|
|
ti = time.time() |
|
|
if ti > ts and stamp != 0: |
|
|
return gr.update(value=1),gr.HTML.update(f"{m_out}",visible=True) |
|
|
elif ti < ts: |
|
|
return gr.update(value=0),gr.HTML.update("",visible=False) |
|
|
def im_fn(put,fac="",h=None,bb=None): |
|
|
if int(bb)==1: |
|
|
bb=0 |
|
|
elif int(bb)==0: |
|
|
bb=1 |
|
|
try: |
|
|
if h == o: |
|
|
put = f"{put}{fac}" |
|
|
fac = f"{fac} " |
|
|
rn = random.randint(0, 19) |
|
|
model=models[rn] |
|
|
return model(put),fac,bb |
|
|
elif h != o: |
|
|
return(None,None,bb) |
|
|
except Exception: |
|
|
return None, None,bb |
|
|
def cl_fac(): |
|
|
return "",gr.HTML.update(f"<center>{loading}",visible=True),gr.HTML.update("",visible=False) |
|
|
with gr.Blocks(css=css) as b: |
|
|
with gr.Row(): |
|
|
with gr.Column(): |
|
|
put = gr.Textbox() |
|
|
with gr.Column(): |
|
|
with gr.Row(): |
|
|
btn1 = gr.Button("Run") |
|
|
btn2 = gr.Button("Clear") |
|
|
message2=gr.HTML("",visible=False) |
|
|
message=gr.HTML("",visible=False) |
|
|
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(value="V") |
|
|
t_state=gr.Number() |
|
|
t_switch=gr.Textbox(value=0) |
|
|
bb1=gr.Textbox(value=0) |
|
|
bb2=gr.Textbox(value=0) |
|
|
bb3=gr.Textbox(value=0) |
|
|
bb4=gr.Textbox(value=0) |
|
|
def clear_all(): |
|
|
return "",None,None,None,None,None,None,1,gr.HTML.update("",visible=False),gr.HTML.update("",visible=False) |
|
|
fac_b = gr.Textbox(value="",visible=False) |
|
|
def noth(): |
|
|
return gr.HTML.update("<div></div>",visible=True) |
|
|
btn1.click(cl_fac,None,[fac_b,message,message2],show_progress=False) |
|
|
b1=btn1.click(start,None,[t_state,t_switch],show_progress=False) |
|
|
sta = t_state.change(end,t_state,[t_switch,message2],every=1,show_progress=False) |
|
|
b2=btn1.click(im_fn,[put,fac_b,h,bb1],[out1,fac_b,bb1], show_progress=False) |
|
|
b3=bb1.change(im_fn,[put,fac_b,h,bb2],[out2,fac_b,bb2], show_progress=False) |
|
|
b4=bb2.change(im_fn,[put,fac_b,h,bb3],[out3,fac_b,bb3], show_progress=False) |
|
|
b5=bb3.change(im_fn,[put,fac_b,h,bb4],[out4,fac_b,bb4], show_progress=False) |
|
|
b6=bb4.change(noth,None,message, cancels=[sta], show_progress=False) |
|
|
swi=t_switch.change(clear,None,[t_switch,fac_b,message], cancels=[sta,b2,b3,b4,b5],show_progress=False) |
|
|
btn2.click(clear_all, None,[fac_b,put,out1,out2,out3,out4,t_state,t_switch,message,message2],cancels=[b1,sta,b2,b3,b4,b5,swi],show_progress=False) |
|
|
b.queue(concurrency_count=100).launch(show_api=False) |
|
|
ac() |