# 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()