|
import gradio as gr |
|
import os |
|
import requests |
|
import random |
|
import time |
|
r = requests.get(f'https://huggingface.co/spaces/xp3857/text-to-image/raw/main/css.css') |
|
css = r.text |
|
name2 = "runwayml/stable-diffusion-v1-5" |
|
|
|
model = gr.Interface.load(f"models/{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" |
|
|
|
t_out = (""" |
|
<head> |
|
<style> |
|
/* Popup container */ |
|
.popup { |
|
position: relative; |
|
display: inline-block; |
|
cursor: pointer; |
|
} |
|
|
|
/* The actual popup (appears on top) */ |
|
.popup .popuptext { |
|
visibility: hidden; |
|
width: 160px; |
|
background-color: #555; |
|
color: #fff; |
|
text-align: center; |
|
border-radius: 6px; |
|
padding: 8px 0; |
|
position: absolute; |
|
z-index: 1; |
|
bottom: 125%; |
|
left: 50%; |
|
margin-left: -80px; |
|
} |
|
|
|
/* Popup arrow */ |
|
.popup .popuptext::after { |
|
content: ""; |
|
position: absolute; |
|
top: 100%; |
|
left: 50%; |
|
margin-left: -5px; |
|
border-width: 5px; |
|
border-style: solid; |
|
border-color: #555 transparent transparent transparent; |
|
} |
|
|
|
/* Toggle this class when clicking on the popup container (hide and show the popup) */ |
|
.popup .show { |
|
visibility: visible; |
|
-webkit-animation: fadeIn 1s; |
|
animation: fadeIn 1s |
|
} |
|
|
|
/* Add animation (fade in the popup) */ |
|
@-webkit-keyframes fadeIn { |
|
from {opacity: 0;} |
|
to {opacity: 1;} |
|
} |
|
|
|
@keyframes fadeIn { |
|
from {opacity: 0;} |
|
to {opacity:1 ;} |
|
} |
|
|
|
</style> |
|
</head> |
|
<body> |
|
<div class="popup" onclick="myFunction()">Click me! |
|
<span class="popuptext" id="myPopup">Popup text...</span> |
|
</div> |
|
|
|
// When the user clicks on <div>, open the popup |
|
function myFunction() { |
|
var popup = document.getElementById("myPopup"); |
|
popup.classList.toggle("show"); |
|
} |
|
|
|
</body> |
|
|
|
|
|
|
|
""") |
|
|
|
|
|
def ac(): |
|
def clear(): |
|
return gr.update(value=0),gr.update(value=0) |
|
def start(): |
|
print ("start") |
|
stamp = time.time() |
|
return gr.update(value=stamp),gr.update(value=0) |
|
def end(stamp): |
|
ts = stamp + 10 |
|
ti = time.time() |
|
if ti > ts and stamp != 0: |
|
print("Cancelling") |
|
return gr.update(value=1),gr.HTML.update(f"{t_out}", visible=True) |
|
else: |
|
print("Passing") |
|
return gr.update(value=0),None |
|
|
|
def im_fn(put,fac="",h=None): |
|
if h == o: |
|
put = f"{put}{fac}" |
|
fac = f"{fac} " |
|
rn = random.randint(0, 19) |
|
model=models[rn] |
|
return model(put),fac |
|
elif h != o: |
|
return(None,None) |
|
def cl_fac(): |
|
return "" |
|
with gr.Blocks(css=css) as b: |
|
message=gr.HTML("", visible=False) |
|
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(value="V") |
|
t_state=gr.Number() |
|
t_switch=gr.Textbox(value=0) |
|
|
|
fac_b = gr.Textbox(value="",visible=False) |
|
btn1.click(cl_fac,None,fac_b) |
|
|
|
b1=btn1.click(start,None,[t_state,t_switch]) |
|
sta = t_state.change(end,t_state,[t_switch,message],every=1) |
|
|
|
b2=btn1.click(im_fn,[put,fac_b,h],[out1,fac_b]) |
|
b3=out1.change(im_fn,[put,fac_b,h],[out2,fac_b]) |
|
b4=out2.change(im_fn,[put,fac_b,h],[out3,fac_b]) |
|
b5=out3.change(im_fn,[put,fac_b,h],[out4,fac_b]) |
|
|
|
t_switch.change(clear,None,[t_switch,fac_b], cancels=[sta,b2,b3,b4,b5]) |
|
|
|
b.queue(concurrency_count=100).launch(show_api=False) |
|
ac() |