Create c.py
Browse files
c.py
ADDED
|
@@ -0,0 +1,112 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import os
|
| 3 |
+
import requests
|
| 4 |
+
import random
|
| 5 |
+
import time
|
| 6 |
+
r = requests.get(f'https://huggingface.co/spaces/xp3857/text-to-image/raw/main/css.css')
|
| 7 |
+
css = r.text
|
| 8 |
+
name2 = $name2
|
| 9 |
+
models=[
|
| 10 |
+
gr.Interface.load(f"models/{name2}"),
|
| 11 |
+
gr.Interface.load(f"models/{name2}"),
|
| 12 |
+
gr.Interface.load(f"models/{name2}"),
|
| 13 |
+
gr.Interface.load(f"models/{name2}"),
|
| 14 |
+
gr.Interface.load(f"models/{name2}"),
|
| 15 |
+
gr.Interface.load(f"models/{name2}"),
|
| 16 |
+
gr.Interface.load(f"models/{name2}"),
|
| 17 |
+
gr.Interface.load(f"models/{name2}"),
|
| 18 |
+
gr.Interface.load(f"models/{name2}"),
|
| 19 |
+
gr.Interface.load(f"models/{name2}"),
|
| 20 |
+
gr.Interface.load(f"models/{name2}"),
|
| 21 |
+
gr.Interface.load(f"models/{name2}"),
|
| 22 |
+
gr.Interface.load(f"models/{name2}"),
|
| 23 |
+
gr.Interface.load(f"models/{name2}"),
|
| 24 |
+
gr.Interface.load(f"models/{name2}"),
|
| 25 |
+
gr.Interface.load(f"models/{name2}"),
|
| 26 |
+
gr.Interface.load(f"models/{name2}"),
|
| 27 |
+
gr.Interface.load(f"models/{name2}"),
|
| 28 |
+
gr.Interface.load(f"models/{name2}"),
|
| 29 |
+
gr.Interface.load(f"models/{name2}"),
|
| 30 |
+
]
|
| 31 |
+
#o = os.getenv("P")
|
| 32 |
+
o = "V"
|
| 33 |
+
m_out = ("""
|
| 34 |
+
<div id="restart">
|
| 35 |
+
<h3 id="head">Loading Time Limit Reached.</h3><br>
|
| 36 |
+
<h4 id="cont">Please choose a Simpler Prompt, or Upgrade for faster loading.</h4>
|
| 37 |
+
</div>
|
| 38 |
+
""")
|
| 39 |
+
loading=("""
|
| 40 |
+
<div class="lds-ellipsis"><div></div><div></div><div></div><div></div></div>""")
|
| 41 |
+
def ac():
|
| 42 |
+
def clear():
|
| 43 |
+
return gr.update(value=0),gr.update(value=0),gr.HTML.update("",visible=False)
|
| 44 |
+
def start():
|
| 45 |
+
stamp = time.time()
|
| 46 |
+
return gr.update(value=stamp),gr.update(value=0)
|
| 47 |
+
def end(stamp):
|
| 48 |
+
ts = stamp + 12
|
| 49 |
+
ti = time.time()
|
| 50 |
+
if ti > ts and stamp != 0:
|
| 51 |
+
return gr.update(value=1),gr.HTML.update(f"{m_out}",visible=True)
|
| 52 |
+
elif ti < ts:
|
| 53 |
+
return gr.update(value=0),gr.HTML.update("",visible=False)
|
| 54 |
+
def im_fn(put,fac="",h=None,bb=None):
|
| 55 |
+
if int(bb)==1:
|
| 56 |
+
bb=0
|
| 57 |
+
elif int(bb)==0:
|
| 58 |
+
bb=1
|
| 59 |
+
try:
|
| 60 |
+
if h == o:
|
| 61 |
+
put = f"{put}{fac}"
|
| 62 |
+
fac = f"{fac} "
|
| 63 |
+
rn = random.randint(0, 19)
|
| 64 |
+
model=models[rn]
|
| 65 |
+
return model(put),fac,bb
|
| 66 |
+
elif h != o:
|
| 67 |
+
return(None,None,bb)
|
| 68 |
+
except Exception:
|
| 69 |
+
return None, None,bb
|
| 70 |
+
def cl_fac():
|
| 71 |
+
return "",gr.HTML.update(f"<center>{loading}",visible=True),gr.HTML.update("",visible=False)
|
| 72 |
+
with gr.Blocks(css=css) as b:
|
| 73 |
+
with gr.Row():
|
| 74 |
+
with gr.Column():
|
| 75 |
+
put = gr.Textbox()
|
| 76 |
+
with gr.Column():
|
| 77 |
+
with gr.Row():
|
| 78 |
+
btn1 = gr.Button("Run")
|
| 79 |
+
btn2 = gr.Button("Clear")
|
| 80 |
+
message2=gr.HTML("",visible=False)
|
| 81 |
+
message=gr.HTML("",visible=False)
|
| 82 |
+
with gr.Row():
|
| 83 |
+
out1 = gr.Image()
|
| 84 |
+
out2 = gr.Image()
|
| 85 |
+
with gr.Row():
|
| 86 |
+
out3 = gr.Image()
|
| 87 |
+
out4 = gr.Image()
|
| 88 |
+
with gr.Row(visible=False):
|
| 89 |
+
h=gr.Textbox(value="V")
|
| 90 |
+
t_state=gr.Number()
|
| 91 |
+
t_switch=gr.Textbox(value=0)
|
| 92 |
+
bb1=gr.Textbox(value=0)
|
| 93 |
+
bb2=gr.Textbox(value=0)
|
| 94 |
+
bb3=gr.Textbox(value=0)
|
| 95 |
+
bb4=gr.Textbox(value=0)
|
| 96 |
+
def clear_all():
|
| 97 |
+
return "",None,None,None,None,None,None,1,gr.HTML.update("",visible=False),gr.HTML.update("",visible=False)
|
| 98 |
+
fac_b = gr.Textbox(value="",visible=False)
|
| 99 |
+
def noth():
|
| 100 |
+
return gr.HTML.update("<div></div>",visible=True)
|
| 101 |
+
btn1.click(cl_fac,None,[fac_b,message,message2],show_progress=False)
|
| 102 |
+
b1=btn1.click(start,None,[t_state,t_switch],show_progress=False)
|
| 103 |
+
sta = t_state.change(end,t_state,[t_switch,message2],every=1,show_progress=False)
|
| 104 |
+
b2=btn1.click(im_fn,[put,fac_b,h,bb1],[out1,fac_b,bb1], show_progress=False)
|
| 105 |
+
b3=bb1.change(im_fn,[put,fac_b,h,bb2],[out2,fac_b,bb2], show_progress=False)
|
| 106 |
+
b4=bb2.change(im_fn,[put,fac_b,h,bb3],[out3,fac_b,bb3], show_progress=False)
|
| 107 |
+
b5=bb3.change(im_fn,[put,fac_b,h,bb4],[out4,fac_b,bb4], show_progress=False)
|
| 108 |
+
b6=bb4.change(noth,None,message, cancels=[sta], show_progress=False)
|
| 109 |
+
swi=t_switch.change(clear,None,[t_switch,fac_b,message], cancels=[sta,b2,b3,b4,b5],show_progress=False)
|
| 110 |
+
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)
|
| 111 |
+
b.queue(concurrency_count=100).launch(show_api=False)
|
| 112 |
+
ac()
|