kinsung commited on
Commit
92a6a90
Β·
verified Β·
1 Parent(s): 214799b
Files changed (3) hide show
  1. README.md +12 -13
  2. app.py +64 -0
  3. requirements.txt +5 -0
README.md CHANGED
@@ -1,13 +1,12 @@
1
- ---
2
- title: Queue
3
- emoji: πŸ“ˆ
4
- colorFrom: gray
5
- colorTo: yellow
6
- sdk: streamlit
7
- sdk_version: 1.44.1
8
- app_file: app.py
9
- pinned: false
10
- license: apache-2.0
11
- ---
12
-
13
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
1
+ ---
2
+ title: QR-Code-Generator-Streamlit App
3
+ emoji: πŸ‘
4
+ colorFrom: red
5
+ colorTo: green
6
+ sdk: streamlit
7
+ sdk_version: 1.17.0
8
+ app_file: app.py
9
+ pinned: false
10
+ ---
11
+
12
+ Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
app.py ADDED
@@ -0,0 +1,64 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import qrcode
3
+ from qrcode.image.pil import PilImage
4
+ from PIL import Image
5
+ import io
6
+ import base64
7
+ from urllib.parse import urlparse
8
+
9
+
10
+ # Function to convert image to base64
11
+ def get_image_as_base64(image: Image):
12
+ buffer = io.BytesIO()
13
+ image.save(buffer, format="PNG")
14
+ image_base64 = base64.b64encode(buffer.getvalue()).decode('utf-8')
15
+ return image_base64
16
+
17
+ def get_url_filename(url):
18
+ parsed_uri = urlparse(url)
19
+ domain = '{uri.netloc}'.format(uri=parsed_uri)
20
+ main_domain = domain.split('.')
21
+ main_domain = main_domain[1] if main_domain[0] == 'www' else main_domain[0]
22
+ path = parsed_uri.path.strip('/').replace('/', '_')
23
+ return f"{main_domain}_{path}" if path else main_domain
24
+
25
+
26
+ # QR code content options
27
+ qr_content_options = ["URL", "Text"]
28
+ # qr_content_options = ["URL", "Text", "Contact Information"]
29
+ qr_content_type = st.selectbox("Select QR content type", qr_content_options)
30
+
31
+
32
+ content = st.text_area("Enter your content", height=150)
33
+
34
+ if st.button("Generate QR Code"):
35
+ if content:
36
+ if content.strip():
37
+ # Generate QR code
38
+ qr = qrcode.QRCode(
39
+ version=1,
40
+ error_correction=qrcode.constants.ERROR_CORRECT_H,
41
+ box_size=10,
42
+ border=4
43
+ )
44
+ qr.add_data(content)
45
+ qr.make(fit=True)
46
+
47
+ img = qr.make_image(fill_color="black", back_color="white", image_factory=PilImage)
48
+
49
+ # Convert PilImage to bytes-like object
50
+ buffer = io.BytesIO()
51
+ img.save(buffer, format="PNG")
52
+ img_bytes = buffer.getvalue()
53
+
54
+ img_base64 = get_image_as_base64(img)
55
+
56
+ st.markdown(f"##### {content}")
57
+ st.image(img_bytes, caption=f"QR code for {content}", use_column_width=True)
58
+ file_name = get_url_filename(content)
59
+ st.markdown(f'<a href="data:image/png;base64,{img_base64}" download="{file_name}.png" style="display:inline-block;background-color:#4CAF50;border:none;color:white;padding:8px 16px;text-align:center;text-decoration:none;font-size:16px;margin:4px 2px;cursor:pointer;">Download QR code</a>', unsafe_allow_html=True)
60
+ else:
61
+ st.error("Please enter content for the QR code.")
62
+
63
+
64
+
requirements.txt ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ openai==0.25.0
2
+ streamlit
3
+ qrcode==7.3.1
4
+ #pillow==9.4.0
5
+ altair<5