Update app.py
Browse files
app.py
CHANGED
|
@@ -2,7 +2,6 @@ import gradio as gr
|
|
| 2 |
import qrcode
|
| 3 |
import qrcode.constants
|
| 4 |
from PIL import Image
|
| 5 |
-
import io
|
| 6 |
|
| 7 |
def get_qr_image(data: str, fill_color: str = None, back_color: str = None):
|
| 8 |
"""
|
|
@@ -51,18 +50,11 @@ def generate_qr(url, fill_color=None, back_color=None):
|
|
| 51 |
raise ValueError("URL or data cannot be empty")
|
| 52 |
|
| 53 |
# Convert empty strings to None
|
| 54 |
-
fill_color = fill_color.strip() if fill_color else
|
| 55 |
-
back_color = back_color.strip() if back_color else
|
| 56 |
|
| 57 |
# Generate QR code with optional color parameters
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
# Save to a bytes buffer in PNG format
|
| 61 |
-
buffer = io.BytesIO()
|
| 62 |
-
img.save(buffer, format='PNG')
|
| 63 |
-
buffer.seek(0)
|
| 64 |
-
|
| 65 |
-
return buffer
|
| 66 |
|
| 67 |
except Exception as e:
|
| 68 |
# Error handling for Gradio
|
|
@@ -77,10 +69,9 @@ iface = gr.Interface(
|
|
| 77 |
gr.Textbox(label="Fill Color (optional)", placeholder="e.g., 'blue', '#FF0000'"),
|
| 78 |
gr.Textbox(label="Background Color (optional)", placeholder="e.g., 'white', '#FFFFFF'")
|
| 79 |
],
|
| 80 |
-
outputs=gr.Image(label="QR Code"
|
| 81 |
title="QR Code Generator",
|
| 82 |
description="Generate a QR code from a URL or text with optional color customization.",
|
| 83 |
-
# Optional: Specify file type
|
| 84 |
examples=[
|
| 85 |
["https://example.com"],
|
| 86 |
["Hello World", "blue", "white"]
|
|
@@ -96,7 +87,6 @@ if __name__ == "__main__":
|
|
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
-
|
| 100 |
# import gradio as gr
|
| 101 |
# import qrcode
|
| 102 |
# import qrcode.constants
|
|
|
|
| 2 |
import qrcode
|
| 3 |
import qrcode.constants
|
| 4 |
from PIL import Image
|
|
|
|
| 5 |
|
| 6 |
def get_qr_image(data: str, fill_color: str = None, back_color: str = None):
|
| 7 |
"""
|
|
|
|
| 50 |
raise ValueError("URL or data cannot be empty")
|
| 51 |
|
| 52 |
# Convert empty strings to None
|
| 53 |
+
fill_color = fill_color.strip() if fill_color else None
|
| 54 |
+
back_color = back_color.strip() if back_color else None
|
| 55 |
|
| 56 |
# Generate QR code with optional color parameters
|
| 57 |
+
return get_qr_image(url, fill_color, back_color)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 58 |
|
| 59 |
except Exception as e:
|
| 60 |
# Error handling for Gradio
|
|
|
|
| 69 |
gr.Textbox(label="Fill Color (optional)", placeholder="e.g., 'blue', '#FF0000'"),
|
| 70 |
gr.Textbox(label="Background Color (optional)", placeholder="e.g., 'white', '#FFFFFF'")
|
| 71 |
],
|
| 72 |
+
outputs=gr.Image(label="QR Code"),
|
| 73 |
title="QR Code Generator",
|
| 74 |
description="Generate a QR code from a URL or text with optional color customization.",
|
|
|
|
| 75 |
examples=[
|
| 76 |
["https://example.com"],
|
| 77 |
["Hello World", "blue", "white"]
|
|
|
|
| 87 |
|
| 88 |
|
| 89 |
|
|
|
|
| 90 |
# import gradio as gr
|
| 91 |
# import qrcode
|
| 92 |
# import qrcode.constants
|