Spaces:
Running
on
Zero
Running
on
Zero
patrickvonplaten
commited on
Commit
β’
7c5e6e0
1
Parent(s):
73dac90
add examples
Browse files
README.md
CHANGED
@@ -9,6 +9,7 @@ app_file: app.py
|
|
9 |
pinned: false
|
10 |
suggested_hardware: t4-medium
|
11 |
startup_duration_timeout: 1h
|
|
|
12 |
---
|
13 |
|
14 |
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
|
|
9 |
pinned: false
|
10 |
suggested_hardware: t4-medium
|
11 |
startup_duration_timeout: 1h
|
12 |
+
duplicated_from: huggingface-projects/QR-code-AI-art-generator
|
13 |
---
|
14 |
|
15 |
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
app.py
CHANGED
@@ -20,15 +20,6 @@ from diffusers import (
|
|
20 |
EulerDiscreteScheduler,
|
21 |
)
|
22 |
|
23 |
-
API_URL = "https://api-inference.huggingface.co/models/stabilityai/stable-diffusion-2-1"
|
24 |
-
HF_TOKEN = os.environ.get("HF_TOKEN")
|
25 |
-
|
26 |
-
headers = {"Authorization": f"Bearer {HF_TOKEN}"}
|
27 |
-
|
28 |
-
def query(payload):
|
29 |
-
response = requests.post(API_URL, headers=headers, json=payload)
|
30 |
-
return response.content
|
31 |
-
|
32 |
qrcode_generator = qrcode.QRCode(
|
33 |
version=1,
|
34 |
error_correction=qrcode.ERROR_CORRECT_H,
|
@@ -112,16 +103,7 @@ def inference(
|
|
112 |
qrcode_image = resize_for_condition_image(qrcode_image, 768)
|
113 |
|
114 |
# hack due to gradio examples
|
115 |
-
|
116 |
-
init_image = qrcode_image
|
117 |
-
elif init_image is None or init_image.size == (1, 1):
|
118 |
-
print("Generating random image from prompt using Stable Diffusion 2.1 via Inference API")
|
119 |
-
# generate image from prompt
|
120 |
-
image_bytes = query({"inputs": prompt})
|
121 |
-
init_image = Image.open(io.BytesIO(image_bytes))
|
122 |
-
else:
|
123 |
-
print("Using provided init image")
|
124 |
-
init_image = resize_for_condition_image(init_image, 768)
|
125 |
|
126 |
out = pipe(
|
127 |
prompt=prompt,
|
@@ -146,22 +128,13 @@ with gr.Blocks() as blocks:
|
|
146 |
|
147 |
## π‘ How to generate beautiful QR codes
|
148 |
|
149 |
-
|
150 |
-
|
151 |
-
**1. Blend-in mode**.
|
152 |
-
Use the QR code image as the initial image **and** the control image.
|
153 |
-
When using the QR code as both the init and control image, you can get QR Codes that blend in **very** naturally with your provided prompt.
|
154 |
The strength parameter defines how much noise is added to your QR code and the noisy QR code is then guided towards both your prompt and the QR code image via Controlnet.
|
155 |
-
|
156 |
-
This mode arguably achieves the asthetically most appealing images, but also requires more tuning of the controlnet conditioning scale and the strength value. If the generated image
|
157 |
looks way to much like the original QR code, make sure to gently increase the *strength* value and reduce the *conditioning* scale. Also check out the examples below.
|
158 |
|
159 |
-
**2. Condition-only mode**.
|
160 |
-
Use the QR code image **only** as the control image and denoise from a provided initial image.
|
161 |
-
When providing an initial image or letting SD 2.1 generate the initial image, you have much more freedom to decide how the generated QR code can look like depending on your provided image.
|
162 |
-
This mode allows you to stongly steer the generated QR code into a style, landscape, motive that you provided before-hand. This mode tends to generate QR codes that
|
163 |
-
are less *"blend-in"* with the QR code itself. Make sure to choose high controlnet conditioning scales between 1.5 and 5.0 and lower strength values between 0.5 and 0.7. Also check examples below.
|
164 |
-
|
165 |
model: https://huggingface.co/DionTimmer/controlnet_qrcode-control_v1p_sd15
|
166 |
|
167 |
<a href="https://huggingface.co/spaces/huggingface-projects/QR-code-AI-art-generator?duplicate=true" style="display: inline-block;margin-top: .5em;margin-right: .25em;" target="_blank">
|
@@ -190,18 +163,11 @@ model: https://huggingface.co/DionTimmer/controlnet_qrcode-control_v1p_sd15
|
|
190 |
label="Negative Prompt",
|
191 |
value="ugly, disfigured, low quality, blurry, nsfw",
|
192 |
)
|
193 |
-
use_qr_code_as_init_image = gr.Checkbox(label="Use QR code as init image", value=True, interactive=
|
194 |
|
195 |
with gr.Accordion(label="Init Images (Optional)", open=False, visible=False) as init_image_acc:
|
196 |
init_image = gr.Image(label="Init Image (Optional). Leave blank to generate image with SD 2.1", type="pil")
|
197 |
|
198 |
-
def change_view(qr_code_as_image: bool):
|
199 |
-
if not qr_code_as_image:
|
200 |
-
return {init_image_acc: gr.update(visible=True)}
|
201 |
-
else:
|
202 |
-
return {init_image_acc: gr.update(visible=False)}
|
203 |
-
|
204 |
-
use_qr_code_as_init_image.change(change_view, inputs=[use_qr_code_as_init_image], outputs=[init_image_acc])
|
205 |
|
206 |
with gr.Accordion(
|
207 |
label="Params: The generated QR Code functionality is largely influenced by the parameters detailed below",
|
@@ -296,58 +262,6 @@ model: https://huggingface.co/DionTimmer/controlnet_qrcode-control_v1p_sd15
|
|
296 |
True,
|
297 |
"DPM++ Karras SDE",
|
298 |
],
|
299 |
-
[
|
300 |
-
"https://huggingface.co/spaces/huggingface-projects/QR-code-AI-art-generator",
|
301 |
-
"billboard amidst the bustling skyline of New York City, with iconic landmarks subtly featured in the background.",
|
302 |
-
"ugly, disfigured, low quality, blurry, nsfw",
|
303 |
-
13.37,
|
304 |
-
2.81,
|
305 |
-
0.68,
|
306 |
-
2313123,
|
307 |
-
"./examples/hack.png",
|
308 |
-
"./examples/hack.png",
|
309 |
-
False,
|
310 |
-
"DDIM",
|
311 |
-
],
|
312 |
-
[
|
313 |
-
"https://huggingface.co/spaces/huggingface-projects/QR-code-AI-art-generator",
|
314 |
-
"beautiful sunset in San Francisco with Golden Gate bridge in the background",
|
315 |
-
"ugly, disfigured, low quality, blurry, nsfw",
|
316 |
-
11.01,
|
317 |
-
2.61,
|
318 |
-
0.66,
|
319 |
-
1423585430,
|
320 |
-
"./examples/hack.png",
|
321 |
-
"./examples/hack.png",
|
322 |
-
False,
|
323 |
-
"DDIM",
|
324 |
-
],
|
325 |
-
[
|
326 |
-
"https://huggingface.co",
|
327 |
-
"A flying cat over a jungle",
|
328 |
-
"ugly, disfigured, low quality, blurry, nsfw",
|
329 |
-
13,
|
330 |
-
2.81,
|
331 |
-
0.66,
|
332 |
-
2702246671,
|
333 |
-
"./examples/hack.png",
|
334 |
-
"./examples/hack.png",
|
335 |
-
False,
|
336 |
-
"DDIM",
|
337 |
-
],
|
338 |
-
[
|
339 |
-
"",
|
340 |
-
"crisp QR code prominently displayed on a billboard amidst the bustling skyline of New York City, with iconic landmarks subtly featured in the background.",
|
341 |
-
"ugly, disfigured, low quality, blurry, nsfw",
|
342 |
-
10.0,
|
343 |
-
2.0,
|
344 |
-
0.8,
|
345 |
-
2313123,
|
346 |
-
"./examples/init.jpeg",
|
347 |
-
"./examples/qrcode.png",
|
348 |
-
False,
|
349 |
-
"DDIM",
|
350 |
-
],
|
351 |
],
|
352 |
fn=inference,
|
353 |
inputs=[
|
@@ -364,7 +278,7 @@ model: https://huggingface.co/DionTimmer/controlnet_qrcode-control_v1p_sd15
|
|
364 |
sampler,
|
365 |
],
|
366 |
outputs=[result_image],
|
367 |
-
cache_examples=
|
368 |
)
|
369 |
|
370 |
blocks.queue(concurrency_count=1, max_size=20)
|
|
|
20 |
EulerDiscreteScheduler,
|
21 |
)
|
22 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
23 |
qrcode_generator = qrcode.QRCode(
|
24 |
version=1,
|
25 |
error_correction=qrcode.ERROR_CORRECT_H,
|
|
|
103 |
qrcode_image = resize_for_condition_image(qrcode_image, 768)
|
104 |
|
105 |
# hack due to gradio examples
|
106 |
+
init_image = qrcode_image
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
107 |
|
108 |
out = pipe(
|
109 |
prompt=prompt,
|
|
|
128 |
|
129 |
## π‘ How to generate beautiful QR codes
|
130 |
|
131 |
+
We use the QR code image as the initial image **and** the control image, which allows you to generate
|
132 |
+
QR Codes that blend in **very naturally** with your provided prompt.
|
|
|
|
|
|
|
133 |
The strength parameter defines how much noise is added to your QR code and the noisy QR code is then guided towards both your prompt and the QR code image via Controlnet.
|
134 |
+
Use a high strength value between 0.8 and 0.95 and choose a conditioning scale between 0.6 and 2.0.
|
135 |
+
This mode arguably achieves the asthetically most appealing QR code images, but also requires more tuning of the controlnet conditioning scale and the strength value. If the generated image
|
136 |
looks way to much like the original QR code, make sure to gently increase the *strength* value and reduce the *conditioning* scale. Also check out the examples below.
|
137 |
|
|
|
|
|
|
|
|
|
|
|
|
|
138 |
model: https://huggingface.co/DionTimmer/controlnet_qrcode-control_v1p_sd15
|
139 |
|
140 |
<a href="https://huggingface.co/spaces/huggingface-projects/QR-code-AI-art-generator?duplicate=true" style="display: inline-block;margin-top: .5em;margin-right: .25em;" target="_blank">
|
|
|
163 |
label="Negative Prompt",
|
164 |
value="ugly, disfigured, low quality, blurry, nsfw",
|
165 |
)
|
166 |
+
use_qr_code_as_init_image = gr.Checkbox(label="Use QR code as init image", value=True, interactive=False, info="Whether init image should be QR code. Unclick to pass init image or generate init image with Stable Diffusion 2.1")
|
167 |
|
168 |
with gr.Accordion(label="Init Images (Optional)", open=False, visible=False) as init_image_acc:
|
169 |
init_image = gr.Image(label="Init Image (Optional). Leave blank to generate image with SD 2.1", type="pil")
|
170 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
171 |
|
172 |
with gr.Accordion(
|
173 |
label="Params: The generated QR Code functionality is largely influenced by the parameters detailed below",
|
|
|
262 |
True,
|
263 |
"DPM++ Karras SDE",
|
264 |
],
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
265 |
],
|
266 |
fn=inference,
|
267 |
inputs=[
|
|
|
278 |
sampler,
|
279 |
],
|
280 |
outputs=[result_image],
|
281 |
+
cache_examples=True,
|
282 |
)
|
283 |
|
284 |
blocks.queue(concurrency_count=1, max_size=20)
|