Spaces:
Paused
Paused
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import qrcode
|
| 3 |
+
from io import BytesIO
|
| 4 |
+
from PIL import Image
|
| 5 |
+
|
| 6 |
+
def generate_qr_code(data: str):
|
| 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(data)
|
| 14 |
+
qr.make(fit=True)
|
| 15 |
+
img = qr.make_image(fill_color="black", back_color="white")
|
| 16 |
+
return img
|
| 17 |
+
|
| 18 |
+
# Streamlit UI
|
| 19 |
+
st.title("QR Code Generator")
|
| 20 |
+
|
| 21 |
+
data = st.text_input("Enter the text or URL for the QR code:")
|
| 22 |
+
|
| 23 |
+
if data:
|
| 24 |
+
img = generate_qr_code(data)
|
| 25 |
+
buffer = BytesIO()
|
| 26 |
+
img.save(buffer, format="PNG")
|
| 27 |
+
st.image(buffer.getvalue(), caption="Generated QR Code")
|
| 28 |
+
|
| 29 |
+
# Option to download the QR code
|
| 30 |
+
btn = st.download_button(
|
| 31 |
+
label="Download QR Code",
|
| 32 |
+
data=buffer,
|
| 33 |
+
file_name="qr_code.png",
|
| 34 |
+
mime="image/png",
|
| 35 |
+
)
|