Adityadn's picture
Update app.py
8b3c2b9 verified
raw
history blame
961 Bytes
import cv2
import numpy as np
import gradio as gr
from PIL import Image
def read_qr_code(image):
"""Reads QR Code from an uploaded image using OpenCV."""
try:
# Convert image to OpenCV format
image = np.array(image.convert("RGB"))
gray = cv2.cvtColor(image, cv2.COLOR_RGB2GRAY)
# Initialize OpenCV QR Code detector
detector = cv2.QRCodeDetector()
data, _, _ = detector.detectAndDecode(gray)
if data:
return f"QR Code Data: {data}"
else:
return "No QR Code found."
except Exception as e:
return f"Error: {str(e)}"
# Gradio Interface
interface = gr.Interface(
fn=read_qr_code,
inputs=gr.Image(type="pil", label="Upload QR Code Image"),
outputs=gr.Textbox(label="Scan Result"),
description="Upload an image containing a QR Code to scan and retrieve its data.",
css="footer {visibility: hidden}"
)
interface.launch(share=True)