CultriX commited on
Commit
9414579
·
verified ·
1 Parent(s): 8b06480

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -16
app.py CHANGED
@@ -6,20 +6,24 @@ import numpy as np
6
  import cv2
7
 
8
  def generate_qr(data: str) -> tuple:
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
- img = qr.make_image(fill="black", back_color="white")
 
18
 
19
- temp_file = tempfile.NamedTemporaryFile(delete=False, suffix=".png")
20
- img.save(temp_file.name, format="PNG")
21
- temp_file.close() # Ensure file is written to disk
22
- return temp_file.name, img # Return the file path and the PIL image
 
 
 
23
 
24
  def read_qr(img: Image.Image) -> str:
25
  img = np.array(img)
@@ -65,9 +69,9 @@ def create_gradio_interface():
65
  copy_button = gr.Button("Copy to Clipboard")
66
  read_interface.render()
67
  copy_button.click(
68
- lambda text: gr.Textbox.update(value="Copied to Clipboard!"),
69
- qr_text,
70
- qr_text,
71
  )
72
 
73
  demo.launch(share=True)
 
6
  import cv2
7
 
8
  def generate_qr(data: str) -> tuple:
9
+ try:
10
+ qr = qrcode.QRCode(
11
+ version=1,
12
+ error_correction=qrcode.constants.ERROR_CORRECT_L,
13
+ box_size=10,
14
+ border=4,
15
+ )
16
+ qr.add_data(data)
17
+ qr.make(fit=True)
18
+ img = qr.make_image(fill="black", back_color="white")
19
 
20
+ temp_file = tempfile.NamedTemporaryFile(delete=False, suffix=".png")
21
+ img.save(temp_file.name, format="PNG")
22
+ temp_file.close() # Ensure file is written to disk
23
+ return temp_file.name, img # Return the file path and the PIL image
24
+ except Exception as e:
25
+ print(f"Error generating QR code: {e}")
26
+ return None, None
27
 
28
  def read_qr(img: Image.Image) -> str:
29
  img = np.array(img)
 
69
  copy_button = gr.Button("Copy to Clipboard")
70
  read_interface.render()
71
  copy_button.click(
72
+ fn=lambda text: gr.outputs.Textbox.update(value="Copied to Clipboard!"),
73
+ inputs=qr_text,
74
+ outputs=qr_text,
75
  )
76
 
77
  demo.launch(share=True)