Spaces:
Running
on
Zero
Running
on
Zero
soft exception handling
Browse files
app.py
CHANGED
|
@@ -195,7 +195,7 @@ def generate_qr_code(prompt: str, text_input: str, input_type: str = "URL", imag
|
|
| 195 |
|
| 196 |
# Set protocol based on input type: None for plain text, Https for URLs
|
| 197 |
qr_protocol = "None" if input_type == "Plain Text" else "Https"
|
| 198 |
-
|
| 199 |
try:
|
| 200 |
comfy_qr_by_module_size_15 = comfy_qr_by_module_size.generate_qr(
|
| 201 |
protocol=qr_protocol,
|
|
@@ -208,9 +208,12 @@ def generate_qr_code(prompt: str, text_input: str, input_type: str = "URL", imag
|
|
| 208 |
border=border_size,
|
| 209 |
module_drawer=module_drawer,
|
| 210 |
)
|
| 211 |
-
except RuntimeError
|
| 212 |
-
error_msg =
|
| 213 |
-
|
|
|
|
|
|
|
|
|
|
| 214 |
|
| 215 |
emptylatentimage_17 = emptylatentimage.generate(
|
| 216 |
width=image_size*2, height=image_size*2, batch_size=1
|
|
@@ -314,7 +317,7 @@ def generate_qr_code(prompt: str, text_input: str, input_type: str = "URL", imag
|
|
| 314 |
# Remove batch dimension and convert to PIL Image
|
| 315 |
image_np = image_np[0] # Shape will be (1024, 1024, 3)
|
| 316 |
pil_image = Image.fromarray(image_np)
|
| 317 |
-
return pil_image
|
| 318 |
|
| 319 |
|
| 320 |
if __name__ == "__main__":
|
|
@@ -441,12 +444,16 @@ if __name__ == "__main__":
|
|
| 441 |
with gr.Column():
|
| 442 |
# The output image
|
| 443 |
output_image = gr.Image(label="Generated QR Code Art")
|
|
|
|
|
|
|
|
|
|
|
|
|
| 444 |
|
| 445 |
# When clicking the button, it will trigger the main function
|
| 446 |
generate_btn.click(
|
| 447 |
fn=generate_qr_code,
|
| 448 |
inputs=[prompt_input, text_input, input_type, image_size, border_size, error_correction, module_size, module_drawer],
|
| 449 |
-
outputs=[output_image]
|
| 450 |
)
|
| 451 |
|
| 452 |
# Add examples
|
|
@@ -565,7 +572,7 @@ if __name__ == "__main__":
|
|
| 565 |
module_size,
|
| 566 |
module_drawer
|
| 567 |
],
|
| 568 |
-
outputs=[output_image],
|
| 569 |
fn=generate_qr_code,
|
| 570 |
cache_examples=True
|
| 571 |
)
|
|
|
|
| 195 |
|
| 196 |
# Set protocol based on input type: None for plain text, Https for URLs
|
| 197 |
qr_protocol = "None" if input_type == "Plain Text" else "Https"
|
| 198 |
+
|
| 199 |
try:
|
| 200 |
comfy_qr_by_module_size_15 = comfy_qr_by_module_size.generate_qr(
|
| 201 |
protocol=qr_protocol,
|
|
|
|
| 208 |
border=border_size,
|
| 209 |
module_drawer=module_drawer,
|
| 210 |
)
|
| 211 |
+
except RuntimeError as e:
|
| 212 |
+
error_msg = (
|
| 213 |
+
f"Error generating QR code: {str(e)} "
|
| 214 |
+
"Try with a shorter text, increase the image size, or decrease the border size, module size, and error correction level."
|
| 215 |
+
)
|
| 216 |
+
return None, error_msg
|
| 217 |
|
| 218 |
emptylatentimage_17 = emptylatentimage.generate(
|
| 219 |
width=image_size*2, height=image_size*2, batch_size=1
|
|
|
|
| 317 |
# Remove batch dimension and convert to PIL Image
|
| 318 |
image_np = image_np[0] # Shape will be (1024, 1024, 3)
|
| 319 |
pil_image = Image.fromarray(image_np)
|
| 320 |
+
return pil_image, "No errors, all good!"
|
| 321 |
|
| 322 |
|
| 323 |
if __name__ == "__main__":
|
|
|
|
| 444 |
with gr.Column():
|
| 445 |
# The output image
|
| 446 |
output_image = gr.Image(label="Generated QR Code Art")
|
| 447 |
+
error_message = gr.Textbox(
|
| 448 |
+
label="Status / Errors",
|
| 449 |
+
interactive=False,
|
| 450 |
+
)
|
| 451 |
|
| 452 |
# When clicking the button, it will trigger the main function
|
| 453 |
generate_btn.click(
|
| 454 |
fn=generate_qr_code,
|
| 455 |
inputs=[prompt_input, text_input, input_type, image_size, border_size, error_correction, module_size, module_drawer],
|
| 456 |
+
outputs=[output_image, error_message]
|
| 457 |
)
|
| 458 |
|
| 459 |
# Add examples
|
|
|
|
| 572 |
module_size,
|
| 573 |
module_drawer
|
| 574 |
],
|
| 575 |
+
outputs=[output_image, error_message],
|
| 576 |
fn=generate_qr_code,
|
| 577 |
cache_examples=True
|
| 578 |
)
|