djrana commited on
Commit
d5bbe6f
1 Parent(s): e909c64

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +35 -87
app.py CHANGED
@@ -1,87 +1,35 @@
1
- import gradio as gr
2
- import os
3
- import requests
4
- import random
5
- import time
6
- name2 = "stablediffusionapi/opendalle"
7
- models = [gr.Interface.load(f"models/{name2}") for _ in range(20)]
8
-
9
- o = "V"
10
-
11
- m_out = ("""
12
- <div id="restart">
13
- <h4 id="head">Loading Time Limit Reached. Please choose a Simpler Prompt</h4><br>
14
- </div>
15
- """)
16
- loading=("""
17
- <div class="lds-ellipsis"><div></div><div></div><div></div><div></div></div>""")
18
-
19
- def ac():
20
- def clear():
21
- return gr.update(value=0),gr.update(value=0)
22
- def start():
23
- stamp = time.time()
24
- return gr.update(value=stamp),gr.update(value=0)
25
- def end(stamp):
26
- ts = stamp + 120
27
- ti = time.time()
28
- if ti > ts and stamp != 0:
29
- return gr.update(value=1),gr.HTML.update(f"{m_out}",visible=True)
30
- else:
31
- return gr.update(value=0),None
32
- def im_fn(put,fac="",h=None):
33
- try:
34
- if h == o:
35
- put = f"{put}{fac}"
36
- fac = f"{fac} "
37
- rn = random.randint(0, 19)
38
- model=models[rn]
39
- return model(put),fac
40
- elif h != o:
41
- return(None,None)
42
- except Exception:
43
- return None, None
44
- def cl_fac():
45
- return "",gr.HTML.update(f"{loading}")
46
- with gr.Blocks() as b:
47
- with gr.Row():
48
- with gr.Column():
49
- put = gr.Textbox()
50
- with gr.Column():
51
- with gr.Row():
52
- btn1 = gr.Button("Run")
53
- btn2 = gr.Button("Clear")
54
- message=gr.HTML("<div></div>")
55
- message2=gr.HTML("",visible=False)
56
-
57
- with gr.Row():
58
- out1 = gr.Image()
59
- out2 = gr.Image()
60
- with gr.Row():
61
- out3 = gr.Image()
62
- out4 = gr.Image()
63
-
64
- with gr.Row(visible=False):
65
- h=gr.Textbox(value="V")
66
- t_state=gr.Number()
67
- t_switch=gr.Textbox(value=0)
68
- def clear_all():
69
- return "",None,None,None,None,None,None,1,gr.HTML.update("<div></div>")
70
- fac_b = gr.Textbox(value="", visible=False)
71
-
72
- def noth():
73
- return gr.HTML.update("<div></div>")
74
- #a1=btn1.click(noth,None,btn1,every=1)
75
- btn1.click(cl_fac,None,[fac_b,message],show_progress=False)
76
- b1=btn1.click(start,None,[t_state,t_switch],show_progress=True)
77
- sta = t_state.change(end,t_state,[t_switch,message2],every=1,show_progress=True)
78
- b2=btn1.click(im_fn,[put,fac_b,h],[out1,fac_b], show_progress=True)
79
- b3=out1.change(im_fn,[put,fac_b,h],[out2,fac_b], show_progress=True)
80
- b4=out2.change(im_fn,[put,fac_b,h],[out3,fac_b], show_progress=True)
81
- b5=out3.change(im_fn,[put,fac_b,h],[out4,fac_b], show_progress=True)
82
- b6=out4.change(noth,None,message, show_progress=False)
83
- swi=t_switch.change(clear,None,[t_switch,fac_b], cancels=[sta,b2,b3,b4,b5],show_progress=False)
84
- #btn2.click(noth,None,message,cancels=[b1,sta,b2,b3,b4,b5,swi],show_progress=False)
85
- 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)
86
- b.queue(concurrency_count=100).launch(show_api=False)
87
- ac()
 
1
+ import requests
2
+ import json
3
+
4
+ url = "https://modelslab.com/api/v6/images/text2img"
5
+
6
+ payload = json.dumps({
7
+ "key": "sHj15HTjxiCkFtV3PHmSeehjaVGdpNotsb1iMbIpniNzfTsjgbN7Z9RFB8Wu",
8
+ "model_id": "juggernaut-xl-v8",
9
+ "prompt": "ultra realistic close up portrait ((beautiful pale cyberpunk female with heavy black eyeliner)), blue eyes, shaved side haircut, hyper detail, cinematic lighting, magic neon, dark red city, Canon EOS R3, nikon, f/1.4, ISO 200, 1/160s, 8K, RAW, unedited, symmetrical balance, in-frame, 8K",
10
+ "negative_prompt": "painting, extra fingers, mutated hands, poorly drawn hands, poorly drawn face, deformed, ugly, blurry, bad anatomy, bad proportions, extra limbs, cloned face, skinny, glitchy, double torso, extra arms, extra hands, mangled fingers, missing lips, ugly face, distorted face, extra legs, anime",
11
+ "width": "512",
12
+ "height": "512",
13
+ "samples": "1",
14
+ "num_inference_steps": "30",
15
+ "safety_checker": "no",
16
+ "enhance_prompt": "yes",
17
+ "seed": None,
18
+ "guidance_scale": 7.5,
19
+ "multi_lingual": "no",
20
+ "panorama": "no",
21
+ "self_attention": "no",
22
+ "upscale": "no",
23
+ "embeddings": "embeddings_model_id",
24
+ "lora": "lora_model_id",
25
+ "webhook": None,
26
+ "track_id": None
27
+ })
28
+
29
+ headers = {
30
+ 'Content-Type': 'application/json'
31
+ }
32
+
33
+ response = requests.request("POST", url, headers=headers, data=payload)
34
+
35
+ print(response.text)