Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -1,9 +1,10 @@
|
|
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
|
7 |
qr = qrcode.QRCode(
|
8 |
version=1,
|
9 |
error_correction=qrcode.constants.ERROR_CORRECT_L,
|
@@ -13,14 +14,13 @@ def generate_qr(url):
|
|
13 |
qr.add_data(url)
|
14 |
qr.make(fit=True)
|
15 |
|
16 |
-
img = qr.make_image(fill_color="black", back_color="white").convert("RGB")
|
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 |
-
|
|
|
|
|
|
|
|
|
24 |
|
25 |
iface = gr.Interface(
|
26 |
fn=generate_qr,
|
|
|
1 |
import qrcode
|
2 |
import gradio as gr
|
3 |
from io import BytesIO
|
4 |
+
import tempfile
|
5 |
|
6 |
def generate_qr(url):
|
7 |
+
"""Generates a QR code from a given URL and returns the image and downloadable file path."""
|
8 |
qr = qrcode.QRCode(
|
9 |
version=1,
|
10 |
error_correction=qrcode.constants.ERROR_CORRECT_L,
|
|
|
14 |
qr.add_data(url)
|
15 |
qr.make(fit=True)
|
16 |
|
17 |
+
img = qr.make_image(fill_color="black", back_color="white").convert("RGB")
|
|
|
|
|
|
|
|
|
|
|
18 |
|
19 |
+
# Save to temporary file
|
20 |
+
temp_file = tempfile.NamedTemporaryFile(delete=False, suffix=".png")
|
21 |
+
img.save(temp_file.name)
|
22 |
+
|
23 |
+
return img, temp_file.name
|
24 |
|
25 |
iface = gr.Interface(
|
26 |
fn=generate_qr,
|