Ivan000 commited on
Commit
11fbb91
·
verified ·
1 Parent(s): fcd0466

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +40 -0
app.py ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # app.py
2
+ # =============
3
+ # This is a complete app.py file for a QR code scanner using Gradio.
4
+
5
+ import gradio as gr
6
+ from pyzbar.pyzbar import decode
7
+ from PIL import Image
8
+ import io
9
+
10
+ def decode_qr_code(image):
11
+ """
12
+ Decode the QR code from the given image.
13
+
14
+ Args:
15
+ image (PIL.Image.Image): The input image containing the QR code.
16
+
17
+ Returns:
18
+ str: The decoded text from the QR code.
19
+ """
20
+ # Decode the QR code
21
+ decoded_objects = decode(image)
22
+
23
+ if decoded_objects:
24
+ # Extract the data from the first decoded object
25
+ return decoded_objects[0].data.decode('utf-8')
26
+ else:
27
+ return "No QR code found in the image."
28
+
29
+ # Create the Gradio interface
30
+ iface = gr.Interface(
31
+ fn=decode_qr_code,
32
+ inputs=gr.Image(type="pil"),
33
+ outputs="text",
34
+ title="QR Code Scanner",
35
+ description="Upload an image containing a QR code to decode its content."
36
+ )
37
+
38
+ # Launch the interface
39
+ if __name__ == "__main__":
40
+ iface.launch()