File size: 978 Bytes
11fbb91
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# app.py
# =============
# This is a complete app.py file for a QR code scanner using Gradio.

import gradio as gr
from pyzbar.pyzbar import decode
from PIL import Image
import io

def decode_qr_code(image):
    """
    Decode the QR code from the given image.

    Args:
        image (PIL.Image.Image): The input image containing the QR code.

    Returns:
        str: The decoded text from the QR code.
    """
    # Decode the QR code
    decoded_objects = decode(image)

    if decoded_objects:
        # Extract the data from the first decoded object
        return decoded_objects[0].data.decode('utf-8')
    else:
        return "No QR code found in the image."

# Create the Gradio interface
iface = gr.Interface(
    fn=decode_qr_code,
    inputs=gr.Image(type="pil"),
    outputs="text",
    title="QR Code Scanner",
    description="Upload an image containing a QR code to decode its content."
)

# Launch the interface
if __name__ == "__main__":
    iface.launch()