Spaces:
Runtime error
Runtime error
Upload a revised app.py
Browse fileswith a detailed column of UI
app.py
CHANGED
@@ -6,33 +6,90 @@ import os
|
|
6 |
import aiohttp
|
7 |
from PIL import Image
|
8 |
from dotenv import load_dotenv
|
|
|
9 |
load_dotenv()
|
10 |
import PIL
|
11 |
|
12 |
API_URL = os.getenv("API_URL")
|
13 |
API_KEY = os.getenv("API_KEY")
|
|
|
|
|
14 |
|
15 |
import gradio as gr
|
16 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
17 |
|
18 |
async def load_image_from_url(url):
|
19 |
-
async with aiohttp.ClientSession() as session:
|
20 |
async with session.get(url) as response:
|
21 |
image_data = await response.read()
|
22 |
return Image.open(io.BytesIO(image_data))
|
23 |
|
24 |
-
async def greet(prompt):
|
25 |
|
|
|
26 |
url = API_URL
|
27 |
headers = {
|
28 |
'x-qrbtf-key': f'{API_KEY}',
|
29 |
}
|
30 |
|
31 |
full_response: str = ""
|
32 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
33 |
payload = {
|
34 |
'url': 'https://qrbtf.com/',
|
35 |
-
'prompt':
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
36 |
}
|
37 |
|
38 |
async with aiohttp.ClientSession(headers=headers) as session:
|
@@ -61,6 +118,7 @@ with gr.Blocks() as demo:
|
|
61 |
- [Official website](https://qrbtf.com/)
|
62 |
|
63 |
""")
|
|
|
64 |
with gr.Row():
|
65 |
with gr.Column():
|
66 |
url = gr.Textbox(
|
@@ -73,7 +131,36 @@ with gr.Blocks() as demo:
|
|
73 |
label="Prompt",
|
74 |
placeholder="Enter a prompt here",
|
75 |
value="1girl, flowers, birds",
|
|
|
76 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
77 |
with gr.Row():
|
78 |
clear_btn = gr.Button(
|
79 |
"Clear",
|
@@ -82,9 +169,10 @@ with gr.Blocks() as demo:
|
|
82 |
"Call API",
|
83 |
variant="primary"
|
84 |
)
|
85 |
-
|
86 |
-
|
87 |
-
btn.click(
|
88 |
-
clear_btn.click(
|
|
|
89 |
|
90 |
demo.launch()
|
|
|
6 |
import aiohttp
|
7 |
from PIL import Image
|
8 |
from dotenv import load_dotenv
|
9 |
+
|
10 |
load_dotenv()
|
11 |
import PIL
|
12 |
|
13 |
API_URL = os.getenv("API_URL")
|
14 |
API_KEY = os.getenv("API_KEY")
|
15 |
+
print(os.getenv("API_URL"))
|
16 |
+
print(os.getenv("API_KEY"))
|
17 |
|
18 |
import gradio as gr
|
19 |
|
20 |
+
showDetailsBool = False
|
21 |
+
showSeedBool = False
|
22 |
+
|
23 |
+
|
24 |
+
async def CleanBlock():
|
25 |
+
return gr.update(value='')
|
26 |
+
|
27 |
+
|
28 |
+
async def ChangeBlock():
|
29 |
+
global showDetailsBool
|
30 |
+
if not showDetailsBool:
|
31 |
+
showDetailsBool = not showDetailsBool
|
32 |
+
return gr.Button.update(value="Hide Details"), gr.update(visible=True)
|
33 |
+
else:
|
34 |
+
showDetailsBool = not showDetailsBool
|
35 |
+
return gr.Button.update(value="Show Details"), gr.update(visible=False)
|
36 |
+
|
37 |
+
|
38 |
+
async def ChangeSeedBlock():
|
39 |
+
global showSeedBool
|
40 |
+
if not showSeedBool:
|
41 |
+
showSeedBool = not showSeedBool
|
42 |
+
return gr.update(visible=True)
|
43 |
+
else:
|
44 |
+
showSeedBool = not showSeedBool
|
45 |
+
return gr.update(value='-1', visible=False)
|
46 |
+
|
47 |
|
48 |
async def load_image_from_url(url):
|
49 |
+
async with aiohttp.ClientSession(connector=aiohttp.TCPConnector(ssl=False)) as session:
|
50 |
async with session.get(url) as response:
|
51 |
image_data = await response.read()
|
52 |
return Image.open(io.BytesIO(image_data))
|
53 |
|
|
|
54 |
|
55 |
+
async def greet(my_prompt, control_weight, correct_level, padding_ratio, point_style, my_seed, size):
|
56 |
url = API_URL
|
57 |
headers = {
|
58 |
'x-qrbtf-key': f'{API_KEY}',
|
59 |
}
|
60 |
|
61 |
full_response: str = ""
|
62 |
+
point_style_out = 0
|
63 |
+
if correct_level == "L(7%)":
|
64 |
+
correct_level_out = 1
|
65 |
+
elif correct_level == "M(15%)":
|
66 |
+
correct_level_out = 0
|
67 |
+
else:
|
68 |
+
if correct_level == "Q(25%)":
|
69 |
+
correct_level_out = 3
|
70 |
+
else:
|
71 |
+
correct_level_out = 2
|
72 |
+
if size == "768*768":
|
73 |
+
width_out, height_out = 768, 768
|
74 |
+
else:
|
75 |
+
width_out, height_out = 1024, 1024
|
76 |
+
if point_style == "Normal":
|
77 |
+
point_style_out = 0
|
78 |
+
elif point_style == "circle":
|
79 |
+
point_style_out = 1
|
80 |
+
else:
|
81 |
+
if point_style == "minimum":
|
82 |
+
point_style_out = 2
|
83 |
payload = {
|
84 |
'url': 'https://qrbtf.com/',
|
85 |
+
'prompt': my_prompt,
|
86 |
+
'controlnet_weight': control_weight,
|
87 |
+
'correct_level': correct_level_out,
|
88 |
+
'padding_ratio': padding_ratio,
|
89 |
+
'point_style': point_style_out,
|
90 |
+
'seed': my_seed,
|
91 |
+
'width': width_out,
|
92 |
+
'height': height_out,
|
93 |
}
|
94 |
|
95 |
async with aiohttp.ClientSession(headers=headers) as session:
|
|
|
118 |
- [Official website](https://qrbtf.com/)
|
119 |
|
120 |
""")
|
121 |
+
|
122 |
with gr.Row():
|
123 |
with gr.Column():
|
124 |
url = gr.Textbox(
|
|
|
131 |
label="Prompt",
|
132 |
placeholder="Enter a prompt here",
|
133 |
value="1girl, flowers, birds",
|
134 |
+
interactive=True
|
135 |
)
|
136 |
+
showDetails = gr.Button("Show Details")
|
137 |
+
with gr.Column(visible=False) as detailColumn:
|
138 |
+
with gr.Row():
|
139 |
+
randomSeed = gr.Checkbox(label="Random Seed?", value=True, interactive=True)
|
140 |
+
promptsTuning = gr.Checkbox(label="Prompts Tuning?", value=True, interactive=True)
|
141 |
+
seed = gr.Textbox(
|
142 |
+
label="Seed",
|
143 |
+
placeholder="Seed",
|
144 |
+
value="-1",
|
145 |
+
interactive=True,
|
146 |
+
visible=False
|
147 |
+
)
|
148 |
+
ControlWeight = gr.Slider(0, 2, value=1.5, label="ControlWeight",
|
149 |
+
info="Controls the weight of QR_Controlnet", interactive=True) # 滑动条
|
150 |
+
|
151 |
+
marginScale = gr.Slider(0, 0.5, value=0.2, label="Margin Scale",
|
152 |
+
info="Controls how far margin is", interactive=True) # 滑动条
|
153 |
+
SizeSelection = gr.Dropdown(
|
154 |
+
["768*768", "1024*1024"], value="768*768", label="Size", interactive=True)
|
155 |
+
errorRate = gr.Dropdown(
|
156 |
+
["L(7%)", "M(15%)", "Q(25%)", "H(30%)"], value="H(30%)", label="Error Correction Rate",
|
157 |
+
interactive=True)
|
158 |
+
anchorStyle = gr.Dropdown(
|
159 |
+
["Normal", "circle", "minimum"], value="Normal", label="AnchorStyle", interactive=True)
|
160 |
+
|
161 |
+
showDetails.click(ChangeBlock, [], [showDetails, detailColumn])
|
162 |
+
|
163 |
+
with gr.Column():
|
164 |
with gr.Row():
|
165 |
clear_btn = gr.Button(
|
166 |
"Clear",
|
|
|
169 |
"Call API",
|
170 |
variant="primary"
|
171 |
)
|
172 |
+
out = gr.Image(shape=(1, 1))
|
173 |
+
|
174 |
+
btn.click(greet, [prompt, ControlWeight, errorRate, marginScale, anchorStyle, seed, SizeSelection], out)
|
175 |
+
clear_btn.click(CleanBlock, [], prompt)
|
176 |
+
randomSeed.change(ChangeSeedBlock, [], seed)
|
177 |
|
178 |
demo.launch()
|