Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -12,6 +12,7 @@ import spaces
|
|
| 12 |
import numpy as np
|
| 13 |
import cv2
|
| 14 |
from pyzxing import BarCodeReader
|
|
|
|
| 15 |
|
| 16 |
from diffusers import (
|
| 17 |
StableDiffusionPipeline,
|
|
@@ -109,6 +110,8 @@ def scan_qr_code(image):
|
|
| 109 |
|
| 110 |
return None
|
| 111 |
|
|
|
|
|
|
|
| 112 |
|
| 113 |
@spaces.GPU()
|
| 114 |
def inference(
|
|
@@ -123,6 +126,9 @@ def inference(
|
|
| 123 |
qrcode_image: Image.Image | None = None,
|
| 124 |
use_qr_code_as_init_image = True,
|
| 125 |
sampler = "DPM++ Karras SDE",
|
|
|
|
|
|
|
|
|
|
| 126 |
):
|
| 127 |
try:
|
| 128 |
if prompt is None or prompt == "":
|
|
@@ -146,7 +152,7 @@ def inference(
|
|
| 146 |
qr.add_data(qr_code_content)
|
| 147 |
qr.make(fit=True)
|
| 148 |
|
| 149 |
-
qrcode_image = qr.make_image(fill_color=
|
| 150 |
qrcode_image = resize_for_condition_image(qrcode_image, 768)
|
| 151 |
else:
|
| 152 |
print("Using QR Code Image")
|
|
@@ -179,7 +185,13 @@ def inference(
|
|
| 179 |
strength=float(strength),
|
| 180 |
num_inference_steps=50,
|
| 181 |
)
|
| 182 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 183 |
except Exception as e:
|
| 184 |
print(f"Error in inference: {str(e)}")
|
| 185 |
# Return a blank image in case of an error
|
|
@@ -349,6 +361,22 @@ with gr.Blocks(theme='Hev832/Applio') as blocks:
|
|
| 349 |
Try **-1** if you want to explore and generate different designs. If you find something you really love, write down the seed number and use it again to recreate the same design.
|
| 350 |
"""
|
| 351 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 352 |
with gr.Row():
|
| 353 |
run_btn = gr.Button("🎨 Create Your QR Art", variant="primary")
|
| 354 |
|
|
@@ -401,6 +429,9 @@ with gr.Blocks(theme='Hev832/Applio') as blocks:
|
|
| 401 |
qr_code_image,
|
| 402 |
use_qr_code_as_init_image,
|
| 403 |
sampler,
|
|
|
|
|
|
|
|
|
|
| 404 |
],
|
| 405 |
outputs=[result_image],
|
| 406 |
concurrency_limit=20
|
|
|
|
| 12 |
import numpy as np
|
| 13 |
import cv2
|
| 14 |
from pyzxing import BarCodeReader
|
| 15 |
+
from PIL import ImageOps
|
| 16 |
|
| 17 |
from diffusers import (
|
| 18 |
StableDiffusionPipeline,
|
|
|
|
| 110 |
|
| 111 |
return None
|
| 112 |
|
| 113 |
+
def invert_image(image):
|
| 114 |
+
return ImageOps.invert(image)
|
| 115 |
|
| 116 |
@spaces.GPU()
|
| 117 |
def inference(
|
|
|
|
| 126 |
qrcode_image: Image.Image | None = None,
|
| 127 |
use_qr_code_as_init_image = True,
|
| 128 |
sampler = "DPM++ Karras SDE",
|
| 129 |
+
bg_color: str = "white",
|
| 130 |
+
qr_color: str = "black",
|
| 131 |
+
invert_final_image: bool = False,
|
| 132 |
):
|
| 133 |
try:
|
| 134 |
if prompt is None or prompt == "":
|
|
|
|
| 152 |
qr.add_data(qr_code_content)
|
| 153 |
qr.make(fit=True)
|
| 154 |
|
| 155 |
+
qrcode_image = qr.make_image(fill_color=qr_color, back_color=bg_color)
|
| 156 |
qrcode_image = resize_for_condition_image(qrcode_image, 768)
|
| 157 |
else:
|
| 158 |
print("Using QR Code Image")
|
|
|
|
| 185 |
strength=float(strength),
|
| 186 |
num_inference_steps=50,
|
| 187 |
)
|
| 188 |
+
|
| 189 |
+
final_image = out.images[0]
|
| 190 |
+
|
| 191 |
+
if invert_final_image:
|
| 192 |
+
final_image = invert_image(final_image)
|
| 193 |
+
|
| 194 |
+
return final_image
|
| 195 |
except Exception as e:
|
| 196 |
print(f"Error in inference: {str(e)}")
|
| 197 |
# Return a blank image in case of an error
|
|
|
|
| 361 |
Try **-1** if you want to explore and generate different designs. If you find something you really love, write down the seed number and use it again to recreate the same design.
|
| 362 |
"""
|
| 363 |
)
|
| 364 |
+
with gr.Accordion("QR Code Customization", open=True):
|
| 365 |
+
bg_color = gr.ColorPicker(
|
| 366 |
+
label="Background Color",
|
| 367 |
+
value="#FFFFFF",
|
| 368 |
+
info="Choose the background color for the QR code"
|
| 369 |
+
)
|
| 370 |
+
qr_color = gr.ColorPicker(
|
| 371 |
+
label="QR Code Color",
|
| 372 |
+
value="#000000",
|
| 373 |
+
info="Choose the color for the QR code pattern"
|
| 374 |
+
)
|
| 375 |
+
invert_final_image = gr.Checkbox(
|
| 376 |
+
label="Invert Final Image",
|
| 377 |
+
value=False,
|
| 378 |
+
info="Check this to invert the colors of the final image"
|
| 379 |
+
)
|
| 380 |
with gr.Row():
|
| 381 |
run_btn = gr.Button("🎨 Create Your QR Art", variant="primary")
|
| 382 |
|
|
|
|
| 429 |
qr_code_image,
|
| 430 |
use_qr_code_as_init_image,
|
| 431 |
sampler,
|
| 432 |
+
bg_color,
|
| 433 |
+
qr_color,
|
| 434 |
+
invert_final_image,
|
| 435 |
],
|
| 436 |
outputs=[result_image],
|
| 437 |
concurrency_limit=20
|