import gradio as gr import requests import os import random import time name2 = "runwayml/stable-diffusion-v1-5" 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 = os.getenv("P") def ac(): def clear(v): if int(v) != 0: v = 0 else: v = 0 pass return v def start(): stamp = time.time() return gr.update(value=stamp),gr.update(value=0) def end(stamp): ts = stamp + 6 ti = time.time() if ti > ts and stamp != 0: t=gr.update(value=1) print("Cancelling") else: t=gr.update(value=0) print("Passing") pass return t def im_fn(put,fac="",h=None): if h == o: rn = random.randint(0, 19) model=models[rn] put = f"{put}{fac}" fac = f"{fac} " print (rn) return model(put),fac elif h != o: return(None,None) def cl_fac(): return "" with gr.Blocks(css='css.css') as b: 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("Q") t_state=gr.Number() t_switch=gr.Textbox(value=0) fac_b = gr.Textbox(value="",visible=False) btn1.click(start,None,[t_state,t_switch]) sta = t_state.change(end,t_state,t_switch,every=1) t_switch.change(clear,t_switch,t_switch, cancels=[sta]) btn1.click(cl_fac,None,fac_b) btn1.click(im_fn,[put,fac_b,h],[out1,fac_b]) out1.change(im_fn,[put,fac_b,h],[out2,fac_b]) out2.change(im_fn,[put,fac_b,h],[out3,fac_b]) out3.change(im_fn,[put,fac_b,h],[out4,fac_b]) b.queue(concurrency_count=100).launch(show_api=False) ac()