Spaces:
Running
Running
import gradio as gr | |
import requests | |
import concurrent.futures | |
import os | |
SECRET_TOKEN = os.getenv("KEY") | |
def prompt(pos,hei,wid,no): | |
hed={ | |
"Content-Type": "application/json", | |
"Authorization": "Bearer " + SECRET_TOKEN | |
} | |
j={ | |
"deployment_id": "2ce5158e-7fa0-4dd6-b533-550c1e8f8c3b", | |
"inputs": { | |
"input_text": f"{pos} (clear image: 1.1), (clean image: 1.1),masterpiece , best quality , hires , 8k, ((midlength)) ", | |
"Negative": "worst quality, low quality, normal quality, jpeg artifacts, signature, watermark, username, artist name,text, watermark,(Low quality , blurred , bad hands ,diffused body, ugly face , worst quality, low quality, normal quality, painting, drawing, monochrome, grayscale, bad anatomy, bad proportions, signature, watermark)", | |
"Width ": f"{wid}", | |
"Height ": f"{hei}", | |
"Batch": "", | |
} | |
} | |
id = [] | |
urls=[] | |
p=0 | |
no=no | |
def gen(): | |
r = requests.post("https://www.comfydeploy.com/api/run",headers=hed,json=j) | |
a=r.json() | |
a=a['run_id'] | |
id.append(a) | |
futures = [] | |
with concurrent.futures.ThreadPoolExecutor() as executor: | |
for url in range(no): | |
futures.append(executor.submit(gen)) | |
for future in concurrent.futures.as_completed(futures): | |
print(future) | |
for i in id : | |
li = requests.get(f"https://www.comfydeploy.com/api/run?run_id={i}",headers=hed) | |
lo=li.json() | |
url=lo['outputs'] | |
while url ==[]: | |
li = requests.get(f"https://www.comfydeploy.com/api/run?run_id={i}",headers=hed) | |
lo=li.json() | |
url =lo['outputs'] | |
while 'url' not in url: | |
li = requests.get(f"https://www.comfydeploy.com/api/run?run_id={i}",headers=hed) | |
lo=li.json() | |
url=lo['outputs'][0]['data']['images'][0] | |
url=url['url'] | |
urls.append(url) | |
return urls | |
with gr.Blocks() as iface: | |
gr.Interface(fn=prompt, inputs=["text",gr.Slider(8,1024,step=8.0 ,value=512),gr.Slider(8,1024,step=8.0, value=512),gr.Slider(1,10,step=1.0)],outputs="gallery") | |
if __name__ == "__main__": | |
iface.launch() | |