xp3857 commited on
Commit
226e928
·
1 Parent(s): b78e131

Create b.py

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