Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,45 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import qrcode
|
3 |
+
from PIL import Image
|
4 |
+
from io import BytesIO
|
5 |
+
|
6 |
+
|
7 |
+
# Function to generate QR code
|
8 |
+
def generate_qr_code(data):
|
9 |
+
qr = qrcode.QRCode(
|
10 |
+
version=1,
|
11 |
+
error_correction=qrcode.constants.ERROR_CORRECT_L,
|
12 |
+
box_size=10,
|
13 |
+
border=4,
|
14 |
+
)
|
15 |
+
qr.add_data(data)
|
16 |
+
qr.make(fit=True)
|
17 |
+
|
18 |
+
img = qr.make_image(fill_color="black", back_color="white")
|
19 |
+
return img
|
20 |
+
|
21 |
+
|
22 |
+
# Streamlit app
|
23 |
+
st.title('QR Code Generator')
|
24 |
+
st.write('Enter text or a URL to generate a QR code.')
|
25 |
+
|
26 |
+
# User input
|
27 |
+
user_input = st.text_input("Enter text or URL:")
|
28 |
+
|
29 |
+
if user_input:
|
30 |
+
# Generate QR code
|
31 |
+
img = generate_qr_code(user_input)
|
32 |
+
|
33 |
+
# Display QR code
|
34 |
+
st.image(img, caption='Generated QR Code')
|
35 |
+
|
36 |
+
# Option to download the QR code
|
37 |
+
buffer = BytesIO()
|
38 |
+
img.save(buffer, format="PNG")
|
39 |
+
buffer.seek(0)
|
40 |
+
st.download_button(
|
41 |
+
label="Download QR Code",
|
42 |
+
data=buffer,
|
43 |
+
file_name="qr_code.png",
|
44 |
+
mime="image/png"
|
45 |
+
)
|