ShashwatStable commited on
Commit
203ac21
·
verified ·
1 Parent(s): 3651431

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +49 -55
app.py CHANGED
@@ -1,65 +1,59 @@
1
- import gradio as gr
2
- import requests
3
  import concurrent.futures
 
 
4
  import os
5
- SECRET_TOKEN = os.getenv("KEY")
6
- def prompt(pos,hei,wid,no):
7
- hed={
8
- "Content-Type": "application/json",
9
- "Authorization": "Bearer " + SECRET_TOKEN
10
- }
11
- j={
12
- "deployment_id": "2ce5158e-7fa0-4dd6-b533-550c1e8f8c3b",
13
- "inputs": {
14
- "input_text": f"{pos} (clear image: 1.1), (clean image: 1.1),masterpiece , best quality , hires , 8k, ((midlength)) ",
15
- "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)",
16
- "Width ": f"{wid}",
17
- "Height ": f"{hei}",
18
- "Batch": "",
19
- }
20
- }
21
- id = []
22
  urls=[]
23
- p=0
24
- no=no
25
-
26
-
27
  def gen():
28
- r = requests.post("https://www.comfydeploy.com/api/run",headers=hed,json=j)
29
- a=r.json()
30
- a=a['run_id']
31
- id.append(a)
32
-
33
- futures = []
34
- with concurrent.futures.ThreadPoolExecutor() as executor:
35
- for url in range(no):
36
- futures.append(executor.submit(gen))
37
- for future in concurrent.futures.as_completed(futures):
38
- print(future)
39
-
40
- for i in id :
41
- li = requests.get(f"https://www.comfydeploy.com/api/run?run_id={i}",headers=hed)
42
- lo=li.json()
43
- url=lo['outputs']
44
- while url ==[]:
45
- li = requests.get(f"https://www.comfydeploy.com/api/run?run_id={i}",headers=hed)
46
- lo=li.json()
47
- url =lo['outputs']
48
- while 'url' not in url:
49
- li = requests.get(f"https://www.comfydeploy.com/api/run?run_id={i}",headers=hed)
50
- lo=li.json()
51
- url=lo['outputs'][0]['data']['images'][0]
52
- url=url['url']
53
- urls.append(url)
54
- return urls
55
-
56
 
57
  with gr.Blocks() as iface:
58
 
59
- 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")
60
 
61
 
62
  if __name__ == "__main__":
63
- iface.launch()
64
-
65
-
 
1
+ # @title Default title text
 
2
  import concurrent.futures
3
+ import time
4
+ import gradio as gr
5
  import os
6
+ import requests
7
+ def pr(positive,Neg,width,height,cfg,no):
8
+ head ={
9
+ "Content-Type": "application/json",
10
+ "Authorization": "Bearer " + "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyX2lkIjoidXNlcl8yYkpvRzhxd1BYV3lreXpVNmhCQWNZZVlNRk4iLCJpYXQiOjE3MDYyMDM2NjV9.ujXZh1la_WZqwLtPSySw772W1oC34CPab4GKVMipwHA",
11
+ }
12
+ j = {
13
+ "deployment_id": "62d2228a-38c3-4894-bdc1-6f2eaf1d9ef8",
14
+ "inputs": {
15
+ "Cfg": cfg ,
16
+ "Width ": f"{width}",
17
+ "Height ": f"{height}",
18
+ "Ps": f"{positive}",
19
+ "Neg": f"{Neg}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) ",
20
+ }
21
+ }
22
+ id=[]
23
  urls=[]
 
 
 
 
24
  def gen():
25
+ r = requests.post("https://www.comfydeploy.com/api/run",headers=head,json=j)
26
+ a=r.json()
27
+ print(a)
28
+ a=a['run_id']
29
+ id.append(a)
30
+
31
+ for i in id:
32
+ li = requests.get(f"https://www.comfydeploy.com/api/run?run_id={i}",headers=head)
33
+ lo=li.json()
34
+ url=lo['outputs']
35
+ while url ==[]:
36
+ li = requests.get(f"https://www.comfydeploy.com/api/run?run_id={i}",headers=head)
37
+ lo=li.json()
38
+ url =lo['outputs']
39
+ while 'url' not in url:
40
+ li = requests.get(f"https://www.comfydeploy.com/api/run?run_id={i}",headers=head)
41
+ lo=li.json()
42
+ url=lo['outputs'][0]['data']['images'][0]
43
+ url=url['url']
44
+ urls.append(url)
45
+ futures = []
46
+ with concurrent.futures.ThreadPoolExecutor() as executor:
47
+ for url in range(no):
48
+ futures.append(executor.submit(gen))
49
+ for future in concurrent.futures.as_completed(futures):
50
+ print(future)
51
+ return list(set(urls) )
 
52
 
53
  with gr.Blocks() as iface:
54
 
55
+ gr.Interface(fn=pr, inputs=["text","text",gr.Slider(8,1024,step=8.0 ,value=512),gr.Slider(8,1024,step=8.0, value=512),gr.Slider(1,25,step=1.0,value=7),gr.Slider(1,10,step=1.0)],outputs="gallery")
56
 
57
 
58
  if __name__ == "__main__":
59
+ iface.launch()