Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -213,30 +213,32 @@ def inference(
|
|
213 |
back_color=qr_back_color,
|
214 |
)
|
215 |
qrcode_image = resize_for_condition_image(qrcode_image, 768)
|
|
|
|
|
|
|
216 |
|
217 |
# Generate base64 string of the initial QR code
|
218 |
initial_qr_base64 = image_to_base64(qrcode_image)
|
219 |
|
220 |
-
#
|
221 |
-
|
222 |
-
init_image = qrcode_image
|
223 |
|
224 |
out = pipe(
|
225 |
prompt=prompt,
|
226 |
negative_prompt=negative_prompt,
|
227 |
-
image=
|
228 |
-
control_image=qrcode_image,
|
229 |
-
width=768,
|
230 |
-
height=768,
|
231 |
guidance_scale=float(guidance_scale),
|
232 |
-
controlnet_conditioning_scale=float(controlnet_conditioning_scale),
|
233 |
generator=generator,
|
234 |
strength=float(strength),
|
235 |
num_inference_steps=50,
|
236 |
)
|
237 |
|
238 |
# Verify the generated QR code
|
239 |
-
verify_result = scan_qr_code(out.images[0]
|
240 |
|
241 |
return out.images[0], verify_result, initial_qr_base64
|
242 |
except Exception as e:
|
@@ -446,14 +448,6 @@ with gr.Blocks(theme=gr.themes.Monochrome()) as blocks:
|
|
446 |
"""
|
447 |
)
|
448 |
|
449 |
-
with gr.Accordion("QR Code Customization", open=True):
|
450 |
-
qr_version = gr.Slider(minimum=1, maximum=40, step=1, value=1, label="QR Code Version")
|
451 |
-
qr_error_correction = gr.Dropdown(choices=["L", "M", "Q", "H"], value="H", label="Error Correction Level")
|
452 |
-
qr_box_size = gr.Slider(minimum=1, maximum=50, step=1, value=10, label="Box Size")
|
453 |
-
qr_border = gr.Slider(minimum=0, maximum=10, step=1, value=4, label="Border Size")
|
454 |
-
qr_fill_color = gr.ColorPicker(label="QR Code Color", value="#000000")
|
455 |
-
qr_back_color = gr.ColorPicker(label="Background Color", value="#FFFFFF")
|
456 |
-
|
457 |
def scan_and_display(image):
|
458 |
if image is None:
|
459 |
return "No image to scan"
|
@@ -491,12 +485,6 @@ with gr.Blocks(theme=gr.themes.Monochrome()) as blocks:
|
|
491 |
use_qr_code_as_init_image,
|
492 |
sampler,
|
493 |
verify_sensitivity,
|
494 |
-
qr_version,
|
495 |
-
qr_error_correction,
|
496 |
-
qr_box_size,
|
497 |
-
qr_border,
|
498 |
-
qr_fill_color,
|
499 |
-
qr_back_color,
|
500 |
],
|
501 |
outputs=[result_image, scan_result, initial_qr_image],
|
502 |
concurrency_limit=20
|
@@ -504,6 +492,5 @@ with gr.Blocks(theme=gr.themes.Monochrome()) as blocks:
|
|
504 |
|
505 |
download_initial_qr.click(lambda x: x, inputs=[initial_qr_image], outputs=[initial_qr_image])
|
506 |
|
507 |
-
|
508 |
blocks.queue(max_size=20,api_open=False)
|
509 |
blocks.launch(share=bool(os.environ.get("SHARE", False)), show_api=True)
|
|
|
213 |
back_color=qr_back_color,
|
214 |
)
|
215 |
qrcode_image = resize_for_condition_image(qrcode_image, 768)
|
216 |
+
else:
|
217 |
+
print("Using QR Code Image")
|
218 |
+
qrcode_image = resize_for_condition_image(qrcode_image, 768)
|
219 |
|
220 |
# Generate base64 string of the initial QR code
|
221 |
initial_qr_base64 = image_to_base64(qrcode_image)
|
222 |
|
223 |
+
# hack due to gradio examples
|
224 |
+
init_image = qrcode_image
|
|
|
225 |
|
226 |
out = pipe(
|
227 |
prompt=prompt,
|
228 |
negative_prompt=negative_prompt,
|
229 |
+
image=qrcode_image,
|
230 |
+
control_image=qrcode_image, # type: ignore
|
231 |
+
width=768, # type: ignore
|
232 |
+
height=768, # type: ignore
|
233 |
guidance_scale=float(guidance_scale),
|
234 |
+
controlnet_conditioning_scale=float(controlnet_conditioning_scale), # type: ignore
|
235 |
generator=generator,
|
236 |
strength=float(strength),
|
237 |
num_inference_steps=50,
|
238 |
)
|
239 |
|
240 |
# Verify the generated QR code
|
241 |
+
verify_result = scan_qr_code(out.images[0], sensitivity=verify_sensitivity)
|
242 |
|
243 |
return out.images[0], verify_result, initial_qr_base64
|
244 |
except Exception as e:
|
|
|
448 |
"""
|
449 |
)
|
450 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
451 |
def scan_and_display(image):
|
452 |
if image is None:
|
453 |
return "No image to scan"
|
|
|
485 |
use_qr_code_as_init_image,
|
486 |
sampler,
|
487 |
verify_sensitivity,
|
|
|
|
|
|
|
|
|
|
|
|
|
488 |
],
|
489 |
outputs=[result_image, scan_result, initial_qr_image],
|
490 |
concurrency_limit=20
|
|
|
492 |
|
493 |
download_initial_qr.click(lambda x: x, inputs=[initial_qr_image], outputs=[initial_qr_image])
|
494 |
|
|
|
495 |
blocks.queue(max_size=20,api_open=False)
|
496 |
blocks.launch(share=bool(os.environ.get("SHARE", False)), show_api=True)
|