add hack
Browse files- README.md +1 -1
- app.py +28 -29
- examples/hack.png +3 -0
README.md
CHANGED
@@ -1,5 +1,5 @@
|
|
1 |
---
|
2 |
-
title:
|
3 |
emoji: 📱🔲
|
4 |
colorFrom: MediumSeaGreen
|
5 |
colorTo: CornflowerBlue
|
|
|
1 |
---
|
2 |
+
title: QR Code AI Art Generator
|
3 |
emoji: 📱🔲
|
4 |
colorFrom: MediumSeaGreen
|
5 |
colorTo: CornflowerBlue
|
app.py
CHANGED
@@ -61,8 +61,6 @@ def resize_for_condition_image(input_image: Image.Image, resolution: int):
|
|
61 |
|
62 |
|
63 |
def inference(
|
64 |
-
init_image: Image.Image,
|
65 |
-
qrcode_image: Image.Image,
|
66 |
qr_code_content: str,
|
67 |
prompt: str,
|
68 |
negative_prompt: str,
|
@@ -70,9 +68,9 @@ def inference(
|
|
70 |
controlnet_conditioning_scale: float = 2.0,
|
71 |
strength: float = 0.8,
|
72 |
seed: int = -1,
|
73 |
-
|
|
|
74 |
):
|
75 |
-
print(init_image, qrcode_image, qr_code_content, prompt, negative_prompt)
|
76 |
if prompt is None or prompt == "":
|
77 |
raise gr.Error("Prompt is required")
|
78 |
|
@@ -81,7 +79,8 @@ def inference(
|
|
81 |
|
82 |
generator = torch.manual_seed(seed) if seed != -1 else torch.Generator()
|
83 |
|
84 |
-
|
|
|
85 |
print("Generating random image from prompt using Stable Diffusion")
|
86 |
# generate image from prompt
|
87 |
out = sd_pipe(
|
@@ -97,7 +96,7 @@ def inference(
|
|
97 |
print("Using provided init image")
|
98 |
init_image = resize_for_condition_image(init_image, 768)
|
99 |
|
100 |
-
if qr_code_content != "":
|
101 |
print("Generating QR Code from content")
|
102 |
qr = qrcode.QRCode(
|
103 |
version=1,
|
@@ -125,7 +124,7 @@ def inference(
|
|
125 |
controlnet_conditioning_scale=float(controlnet_conditioning_scale), # type: ignore
|
126 |
generator=generator,
|
127 |
strength=float(strength),
|
128 |
-
num_inference_steps=
|
129 |
)
|
130 |
return out.images[0] # type: ignore
|
131 |
|
@@ -133,7 +132,7 @@ def inference(
|
|
133 |
with gr.Blocks() as blocks:
|
134 |
gr.Markdown(
|
135 |
"""
|
136 |
-
#
|
137 |
|
138 |
model: https://huggingface.co/DionTimmer/controlnet_qrcode-control_v1p_sd15
|
139 |
|
@@ -201,8 +200,6 @@ model: https://huggingface.co/DionTimmer/controlnet_qrcode-control_v1p_sd15
|
|
201 |
run_btn.click(
|
202 |
inference,
|
203 |
inputs=[
|
204 |
-
init_image,
|
205 |
-
qr_code_image,
|
206 |
qr_code_content,
|
207 |
prompt,
|
208 |
negative_prompt,
|
@@ -210,6 +207,8 @@ model: https://huggingface.co/DionTimmer/controlnet_qrcode-control_v1p_sd15
|
|
210 |
controlnet_conditioning_scale,
|
211 |
strength,
|
212 |
seed,
|
|
|
|
|
213 |
],
|
214 |
outputs=[result_image],
|
215 |
)
|
@@ -217,19 +216,6 @@ model: https://huggingface.co/DionTimmer/controlnet_qrcode-control_v1p_sd15
|
|
217 |
gr.Examples(
|
218 |
examples=[
|
219 |
[
|
220 |
-
"./examples/init.jpeg",
|
221 |
-
"./examples/qrcode.png",
|
222 |
-
"",
|
223 |
-
"crisp QR code prominently displayed on a billboard amidst the bustling skyline of New York City, with iconic landmarks subtly featured in the background.",
|
224 |
-
"ugly, disfigured, low quality, blurry, nsfw",
|
225 |
-
10.0,
|
226 |
-
2.0,
|
227 |
-
0.8,
|
228 |
-
2313123,
|
229 |
-
],
|
230 |
-
[
|
231 |
-
"./examples/init.jpeg",
|
232 |
-
None,
|
233 |
"https://huggingface.co",
|
234 |
"crisp QR code prominently displayed on a billboard amidst the bustling skyline of New York City, with iconic landmarks subtly featured in the background.",
|
235 |
"ugly, disfigured, low quality, blurry, nsfw",
|
@@ -237,10 +223,10 @@ model: https://huggingface.co/DionTimmer/controlnet_qrcode-control_v1p_sd15
|
|
237 |
2.0,
|
238 |
0.8,
|
239 |
2313123,
|
|
|
|
|
240 |
],
|
241 |
[
|
242 |
-
None,
|
243 |
-
None,
|
244 |
"https://huggingface.co/spaces/huggingface-projects/AI-QR-code-generator",
|
245 |
"beautiful sunset in San Francisco with Golden Gate bridge in the background",
|
246 |
"ugly, disfigured, low quality, blurry, nsfw",
|
@@ -248,10 +234,10 @@ model: https://huggingface.co/DionTimmer/controlnet_qrcode-control_v1p_sd15
|
|
248 |
2.7,
|
249 |
0.75,
|
250 |
1423585430,
|
|
|
|
|
251 |
],
|
252 |
[
|
253 |
-
None,
|
254 |
-
None,
|
255 |
"https://huggingface.co",
|
256 |
"A flying cat over a jungle",
|
257 |
"ugly, disfigured, low quality, blurry, nsfw",
|
@@ -259,12 +245,23 @@ model: https://huggingface.co/DionTimmer/controlnet_qrcode-control_v1p_sd15
|
|
259 |
2.7,
|
260 |
0.8,
|
261 |
2702246671,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
262 |
],
|
263 |
],
|
264 |
fn=inference,
|
265 |
inputs=[
|
266 |
-
init_image,
|
267 |
-
qr_code_image,
|
268 |
qr_code_content,
|
269 |
prompt,
|
270 |
negative_prompt,
|
@@ -272,6 +269,8 @@ model: https://huggingface.co/DionTimmer/controlnet_qrcode-control_v1p_sd15
|
|
272 |
controlnet_conditioning_scale,
|
273 |
strength,
|
274 |
seed,
|
|
|
|
|
275 |
],
|
276 |
outputs=[result_image],
|
277 |
cache_examples=True,
|
|
|
61 |
|
62 |
|
63 |
def inference(
|
|
|
|
|
64 |
qr_code_content: str,
|
65 |
prompt: str,
|
66 |
negative_prompt: str,
|
|
|
68 |
controlnet_conditioning_scale: float = 2.0,
|
69 |
strength: float = 0.8,
|
70 |
seed: int = -1,
|
71 |
+
init_image: Image.Image | None = None,
|
72 |
+
qrcode_image: Image.Image | None = None,
|
73 |
):
|
|
|
74 |
if prompt is None or prompt == "":
|
75 |
raise gr.Error("Prompt is required")
|
76 |
|
|
|
79 |
|
80 |
generator = torch.manual_seed(seed) if seed != -1 else torch.Generator()
|
81 |
|
82 |
+
# hack due to gradio examples
|
83 |
+
if init_image is None or init_image.size == (1, 1):
|
84 |
print("Generating random image from prompt using Stable Diffusion")
|
85 |
# generate image from prompt
|
86 |
out = sd_pipe(
|
|
|
96 |
print("Using provided init image")
|
97 |
init_image = resize_for_condition_image(init_image, 768)
|
98 |
|
99 |
+
if qr_code_content != "" or qrcode_image.size == (1, 1):
|
100 |
print("Generating QR Code from content")
|
101 |
qr = qrcode.QRCode(
|
102 |
version=1,
|
|
|
124 |
controlnet_conditioning_scale=float(controlnet_conditioning_scale), # type: ignore
|
125 |
generator=generator,
|
126 |
strength=float(strength),
|
127 |
+
num_inference_steps=40,
|
128 |
)
|
129 |
return out.images[0] # type: ignore
|
130 |
|
|
|
132 |
with gr.Blocks() as blocks:
|
133 |
gr.Markdown(
|
134 |
"""
|
135 |
+
# QR Code AI Art Generator
|
136 |
|
137 |
model: https://huggingface.co/DionTimmer/controlnet_qrcode-control_v1p_sd15
|
138 |
|
|
|
200 |
run_btn.click(
|
201 |
inference,
|
202 |
inputs=[
|
|
|
|
|
203 |
qr_code_content,
|
204 |
prompt,
|
205 |
negative_prompt,
|
|
|
207 |
controlnet_conditioning_scale,
|
208 |
strength,
|
209 |
seed,
|
210 |
+
init_image,
|
211 |
+
qr_code_image,
|
212 |
],
|
213 |
outputs=[result_image],
|
214 |
)
|
|
|
216 |
gr.Examples(
|
217 |
examples=[
|
218 |
[
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
219 |
"https://huggingface.co",
|
220 |
"crisp QR code prominently displayed on a billboard amidst the bustling skyline of New York City, with iconic landmarks subtly featured in the background.",
|
221 |
"ugly, disfigured, low quality, blurry, nsfw",
|
|
|
223 |
2.0,
|
224 |
0.8,
|
225 |
2313123,
|
226 |
+
"./examples/init.jpeg",
|
227 |
+
"./examples/hack.png",
|
228 |
],
|
229 |
[
|
|
|
|
|
230 |
"https://huggingface.co/spaces/huggingface-projects/AI-QR-code-generator",
|
231 |
"beautiful sunset in San Francisco with Golden Gate bridge in the background",
|
232 |
"ugly, disfigured, low quality, blurry, nsfw",
|
|
|
234 |
2.7,
|
235 |
0.75,
|
236 |
1423585430,
|
237 |
+
"./examples/hack.png",
|
238 |
+
"./examples/hack.png",
|
239 |
],
|
240 |
[
|
|
|
|
|
241 |
"https://huggingface.co",
|
242 |
"A flying cat over a jungle",
|
243 |
"ugly, disfigured, low quality, blurry, nsfw",
|
|
|
245 |
2.7,
|
246 |
0.8,
|
247 |
2702246671,
|
248 |
+
"./examples/hack.png",
|
249 |
+
"./examples/hack.png",
|
250 |
+
],
|
251 |
+
[
|
252 |
+
"",
|
253 |
+
"crisp QR code prominently displayed on a billboard amidst the bustling skyline of New York City, with iconic landmarks subtly featured in the background.",
|
254 |
+
"ugly, disfigured, low quality, blurry, nsfw",
|
255 |
+
10.0,
|
256 |
+
2.0,
|
257 |
+
0.8,
|
258 |
+
2313123,
|
259 |
+
"./examples/init.jpeg",
|
260 |
+
"./examples/qrcode.png",
|
261 |
],
|
262 |
],
|
263 |
fn=inference,
|
264 |
inputs=[
|
|
|
|
|
265 |
qr_code_content,
|
266 |
prompt,
|
267 |
negative_prompt,
|
|
|
269 |
controlnet_conditioning_scale,
|
270 |
strength,
|
271 |
seed,
|
272 |
+
init_image,
|
273 |
+
qr_code_image,
|
274 |
],
|
275 |
outputs=[result_image],
|
276 |
cache_examples=True,
|
examples/hack.png
ADDED
Git LFS Details
|