Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -4,7 +4,7 @@ from PIL import Image
|
|
| 4 |
import io
|
| 5 |
import base64
|
| 6 |
|
| 7 |
-
def generate_qr_code(text: str, size: str = "medium", error_correction: str = "M") ->
|
| 8 |
"""
|
| 9 |
Generate QR code from text/URL
|
| 10 |
|
|
@@ -14,7 +14,7 @@ def generate_qr_code(text: str, size: str = "medium", error_correction: str = "M
|
|
| 14 |
error_correction (str): Error correction level (L, M, Q, H)
|
| 15 |
|
| 16 |
Returns:
|
| 17 |
-
|
| 18 |
"""
|
| 19 |
|
| 20 |
if not text.strip():
|
|
@@ -51,12 +51,11 @@ def generate_qr_code(text: str, size: str = "medium", error_correction: str = "M
|
|
| 51 |
img_base64 = base64.b64encode(buffer.getvalue()).decode()
|
| 52 |
|
| 53 |
return {
|
| 54 |
-
|
| 55 |
-
"info": f"QR code generated for: {text}"
|
| 56 |
}
|
| 57 |
|
| 58 |
except Exception as e:
|
| 59 |
-
return
|
| 60 |
|
| 61 |
if __name__ == "__main__":
|
| 62 |
demo = gr.Interface(
|
|
@@ -66,7 +65,7 @@ if __name__ == "__main__":
|
|
| 66 |
gr.Dropdown(["small", "medium", "large"], value="medium", label="Size"),
|
| 67 |
gr.Dropdown(["L", "M", "Q", "H"], value="M", label="Error Correction")
|
| 68 |
],
|
| 69 |
-
outputs=gr.
|
| 70 |
title="QR Code Generator for Claude",
|
| 71 |
description="Generate QR codes for Claude MCP integration"
|
| 72 |
)
|
|
|
|
| 4 |
import io
|
| 5 |
import base64
|
| 6 |
|
| 7 |
+
def generate_qr_code(text: str, size: str = "medium", error_correction: str = "M") -> str:
|
| 8 |
"""
|
| 9 |
Generate QR code from text/URL
|
| 10 |
|
|
|
|
| 14 |
error_correction (str): Error correction level (L, M, Q, H)
|
| 15 |
|
| 16 |
Returns:
|
| 17 |
+
str: Base64 data URL that can be displayed as QR code image
|
| 18 |
"""
|
| 19 |
|
| 20 |
if not text.strip():
|
|
|
|
| 51 |
img_base64 = base64.b64encode(buffer.getvalue()).decode()
|
| 52 |
|
| 53 |
return {
|
| 54 |
+
f"data:image/png;base64,{img_base64}"
|
|
|
|
| 55 |
}
|
| 56 |
|
| 57 |
except Exception as e:
|
| 58 |
+
return f"Error: Failed to generate QR code: {str(e)}"
|
| 59 |
|
| 60 |
if __name__ == "__main__":
|
| 61 |
demo = gr.Interface(
|
|
|
|
| 65 |
gr.Dropdown(["small", "medium", "large"], value="medium", label="Size"),
|
| 66 |
gr.Dropdown(["L", "M", "Q", "H"], value="M", label="Error Correction")
|
| 67 |
],
|
| 68 |
+
outputs=gr.Textbox(label="QR Code Data URL"),
|
| 69 |
title="QR Code Generator for Claude",
|
| 70 |
description="Generate QR codes for Claude MCP integration"
|
| 71 |
)
|