Mrchuw commited on
Commit
a618ee6
1 Parent(s): 3be08ba

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +74 -87
app.py CHANGED
@@ -3,30 +3,11 @@ import os
3
  import requests
4
  import random
5
  import time
 
6
  name2 = "dreamlike-art/dreamlike-photoreal-2.0"
7
- #name2 = "runwayml/stable-diffusion-v1-5"
8
 
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"
@@ -39,72 +20,78 @@ m_out = ("""
39
  """)
40
  loading=("""
41
  <div class="lds-ellipsis"><div></div><div></div><div></div><div></div></div>""")
42
- def ac():
43
- def clear():
44
- return gr.update(value=0),gr.update(value=0)
45
- def start():
46
- stamp = time.time()
47
- return gr.update(value=stamp),gr.update(value=0)
48
- def end(stamp):
49
- ts = stamp + 120
50
- ti = time.time()
51
- if ti > ts and stamp != 0:
52
- return gr.update(value=1),gr.HTML.update(f"{m_out}",visible=True)
53
- else:
54
- return gr.update(value=0),None
55
- def im_fn(put,fac="",h=None):
56
- try:
57
- if h == o:
58
- put = f"{put}{fac}"
59
- fac = f"{fac} "
60
- rn = random.randint(0, 19)
61
- model=models[rn]
62
- return model(put),fac
63
- elif h != o:
64
- return(None,None)
65
- except Exception:
66
- return None, None
67
- def cl_fac():
68
- return "",gr.HTML.update(f"{loading}")
69
- with gr.Blocks() as b:
70
- with gr.Row():
71
- with gr.Column():
72
- put = gr.Textbox()
73
- with gr.Column():
74
- with gr.Row():
75
- btn1 = gr.Button("Run")
76
- btn2 = gr.Button("Clear")
77
- message=gr.HTML("<div></div>")
78
- message2=gr.HTML("",visible=False)
 
79
 
80
- with gr.Row():
81
- out1 = gr.Image()
82
- out2 = gr.Image()
83
- with gr.Row():
84
- out3 = gr.Image()
85
- out4 = gr.Image()
 
 
 
86
 
87
- with gr.Row(visible=False):
88
- h=gr.Textbox(value="V")
89
- t_state=gr.Number()
90
- t_switch=gr.Textbox(value=0)
91
- def clear_all():
92
- return "",None,None,None,None,None,None,1,gr.HTML.update("<div></div>")
93
- fac_b = gr.Textbox(value="",visible=False)
94
 
95
- def noth():
96
- return gr.HTML.update("<div></div>")
97
- #a1=btn1.click(noth,None,btn1,every=1)
98
- btn1.click(cl_fac,None,[fac_b,message],show_progress=False)
99
- b1=btn1.click(start,None,[t_state,t_switch],show_progress=True)
100
- sta = t_state.change(end,t_state,[t_switch,message2],every=1,show_progress=True)
101
- b2=btn1.click(im_fn,[put,fac_b,h],[out1,fac_b], show_progress=True)
102
- b3=out1.change(im_fn,[put,fac_b,h],[out2,fac_b], show_progress=True)
103
- b4=out2.change(im_fn,[put,fac_b,h],[out3,fac_b], show_progress=True)
104
- b5=out3.change(im_fn,[put,fac_b,h],[out4,fac_b], show_progress=True)
105
- b6=out4.change(noth,None,message, show_progress=False)
106
- swi=t_switch.change(clear,None,[t_switch,fac_b], cancels=[sta,b2,b3,b4,b5],show_progress=False)
107
- #btn2.click(noth,None,message,cancels=[b1,sta,b2,b3,b4,b5,swi],show_progress=False)
108
- 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)
109
- b.queue(concurrency_count=100).launch(show_api=False)
110
- ac()
 
 
 
3
  import requests
4
  import random
5
  import time
6
+
7
  name2 = "dreamlike-art/dreamlike-photoreal-2.0"
 
8
 
9
  models=[
10
+ gr.Interface.load(f"models/{name2}"),
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
11
  ]
12
  #o = os.getenv("P")
13
  o = "V"
 
20
  """)
21
  loading=("""
22
  <div class="lds-ellipsis"><div></div><div></div><div></div><div></div></div>""")
23
+ def build():
24
+ def clear():
25
+ return gr.update(value=0),gr.update(value=0)
26
+ def start():
27
+ stamp = time.time()
28
+ return gr.update(value=stamp),gr.update(value=0)
29
+ def end(stamp):
30
+ ts = stamp + 360
31
+ ti = time.time()
32
+ if ti > ts and stamp != 0:
33
+ return gr.update(value=1),gr.HTML.update(f"{m_out}",visible=True)
34
+ else:
35
+ return gr.update(value=0),None
36
+ def im_fn(put,fac="",h=None):
37
+ try:
38
+ if h == o:
39
+ put = f"{put}{fac}"
40
+ fac = f"{fac} "
41
+ rn = 0
42
+ # rn = random.randint(0, 19)
43
+ model=models[rn]
44
+ return model(put),fac
45
+ elif h != o:
46
+ return(None,None)
47
+ except Exception as E:
48
+ return None, None
49
+ def cl_fac():
50
+ return "",gr.HTML.update(f"{loading}")
51
+ with gr.Blocks() as b:
52
+ with gr.Row():
53
+ with gr.Column():
54
+ put = gr.Textbox()
55
+ with gr.Column():
56
+ with gr.Row():
57
+ btn1 = gr.Button("Run")
58
+ btn2 = gr.Button("Clear")
59
+ message=gr.HTML("<div></div>")
60
+ message2=gr.HTML("",visible=False)
61
 
62
+ with gr.Row():
63
+ out1 = gr.Image()
64
+ out2 = gr.Image()
65
+ with gr.Row():
66
+ out3 = gr.Image()
67
+ out4 = gr.Image()
68
+ with gr.Row():
69
+ out5 = gr.Image()
70
+ out6 = gr.Image()
71
 
72
+ with gr.Row(visible=False):
73
+ h_variavel=gr.Textbox(value="V")
74
+ t_state=gr.Number()
75
+ t_switch=gr.Textbox(value=0)
76
+ def clear_all():
77
+ return "",None,None,None,None,None,None,1,gr.HTML.update("<div></div>")
78
+ fac_b = gr.Textbox(value="",visible=False)
79
 
80
+ def noth():
81
+ return gr.HTML.update("<div></div>")
82
+ #a1=btn1.click(noth,None,btn1,every=1)
83
+ btn1.click(cl_fac,None,[fac_b,message],show_progress=False)
84
+ b1=btn1.click(start,None,[t_state,t_switch],show_progress=True)
85
+ sta = t_state.change(end,t_state,[t_switch,message2],every=1,show_progress=True)
86
+ b2=btn1.click(im_fn,[put,fac_b,h_variavel],[out1,fac_b], show_progress=True)
87
+ b3=out1.change(im_fn,[put,fac_b,h_variavel],[out2,fac_b], show_progress=True)
88
+ b4=out2.change(im_fn,[put,fac_b,h_variavel],[out3,fac_b], show_progress=True)
89
+ b5=out3.change(im_fn,[put,fac_b,h_variavel],[out4,fac_b], show_progress=True)
90
+ b6=out4.change(im_fn,[put,fac_b,h_variavel],[out5,fac_b], show_progress=True)
91
+ b7=out5.change(im_fn,[put,fac_b,h_variavel],[out6,fac_b], show_progress=True)
92
+ b8=out6.change(noth,None,message, show_progress=False)
93
+ swi=t_switch.change(clear,None,[t_switch,fac_b], cancels=[sta,b2,b3,b4,b5,b6,b7],show_progress=False)
94
+ #btn2.click(noth,None,message,cancels=[b1,sta,b2,b3,b4,b5,swi],show_progress=False)
95
+ 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)
96
+ b.queue(concurrency_count=100).launch(show_api=False)
97
+ build()