import gradio as gr import cv2 from pyzbar.pyzbar import decode import numpy as np def qr_barcode_scanner(image): # Convert PIL image to numpy array image_data = np.array(image) # Convert RGB to grayscale if needed if len(image_data.shape) == 3 and image_data.shape[2] == 3: image_data = cv2.cvtColor(image_data, cv2.COLOR_RGB2GRAY) # Decode QR codes and barcodes decoded_objects = decode(image_data) if len(decoded_objects) == 0: return "No QR code or barcode found." results = [] for obj in decoded_objects: data = obj.data.decode("utf-8") results.append(f"Type: {obj.type}, Data: {data}") return "\n".join(results) iface = gr.Interface( fn=qr_barcode_scanner, inputs=gr.inputs.Image(type="pil", label="Select an image containing QR code or barcode."), outputs=gr.outputs.Textbox(), live=True, capture_session=True, interpretation="default" ) iface.launch(share=True)