Harshavarma04 commited on
Commit
55c886a
·
verified ·
1 Parent(s): e297b7f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -8
app.py CHANGED
@@ -3,7 +3,6 @@ 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(
@@ -14,11 +13,10 @@ def generate_qr_code(data):
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.')
@@ -29,14 +27,17 @@ user_input = st.text_input("Enter text or URL:")
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,
 
3
  from PIL import Image
4
  from io import BytesIO
5
 
 
6
  # Function to generate QR code
7
  def generate_qr_code(data):
8
  qr = qrcode.QRCode(
 
13
  )
14
  qr.add_data(data)
15
  qr.make(fit=True)
16
+
17
  img = qr.make_image(fill_color="black", back_color="white")
18
  return img
19
 
 
20
  # Streamlit app
21
  st.title('QR Code Generator')
22
  st.write('Enter text or a URL to generate a QR code.')
 
27
  if user_input:
28
  # Generate QR code
29
  img = generate_qr_code(user_input)
30
+
31
+ # Convert the PIL image to a bytes-like object
 
 
 
32
  buffer = BytesIO()
33
  img.save(buffer, format="PNG")
34
  buffer.seek(0)
35
+ img_bytes = buffer.getvalue()
36
+
37
+ # Display QR code
38
+ st.image(img_bytes, caption='Generated QR Code')
39
+
40
+ # Option to download the QR code
41
  st.download_button(
42
  label="Download QR Code",
43
  data=buffer,