Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import qrcode
|
| 2 |
+
import gradio as gr
|
| 3 |
+
from io import BytesIO
|
| 4 |
+
|
| 5 |
+
def generate_qr(url):
|
| 6 |
+
"""Generates a QR code from a given URL and returns the image and download link."""
|
| 7 |
+
qr = qrcode.QRCode(
|
| 8 |
+
version=1,
|
| 9 |
+
error_correction=qrcode.constants.ERROR_CORRECT_L,
|
| 10 |
+
box_size=10,
|
| 11 |
+
border=4
|
| 12 |
+
)
|
| 13 |
+
qr.add_data(url)
|
| 14 |
+
qr.make(fit=True)
|
| 15 |
+
|
| 16 |
+
img = qr.make_image(fill="black", back_color="white")
|
| 17 |
+
|
| 18 |
+
# Save to BytesIO for download
|
| 19 |
+
img_io = BytesIO()
|
| 20 |
+
img.save(img_io, format="PNG")
|
| 21 |
+
img_io.seek(0)
|
| 22 |
+
|
| 23 |
+
return img, img_io
|
| 24 |
+
|
| 25 |
+
# Gradio Interface
|
| 26 |
+
def qr_interface(url):
|
| 27 |
+
img, img_io = generate_qr(url)
|
| 28 |
+
return img, ("qr_code.png", img_io.getvalue())
|
| 29 |
+
|
| 30 |
+
iface = gr.Interface(
|
| 31 |
+
fn=qr_interface,
|
| 32 |
+
inputs=gr.Textbox(label="Enter URL"),
|
| 33 |
+
outputs=[gr.Image(label="Generated QR Code"), gr.File(label="Download QR Code")],
|
| 34 |
+
title="QR Code Generator",
|
| 35 |
+
description="Enter a URL to generate and download a QR Code."
|
| 36 |
+
)
|
| 37 |
+
|
| 38 |
+
iface.launch()
|