Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,40 +1,43 @@
|
|
| 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
|
| 9 |
|
| 10 |
-
def
|
| 11 |
"""
|
| 12 |
-
|
| 13 |
|
| 14 |
Args:
|
| 15 |
-
|
| 16 |
|
| 17 |
Returns:
|
| 18 |
-
|
| 19 |
"""
|
| 20 |
-
#
|
| 21 |
-
|
|
|
|
| 22 |
|
|
|
|
|
|
|
| 23 |
if decoded_objects:
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
return "No QR code found in the image."
|
| 28 |
|
| 29 |
-
#
|
| 30 |
iface = gr.Interface(
|
| 31 |
-
fn=
|
| 32 |
-
inputs=gr.Image(type="pil"),
|
| 33 |
-
outputs=
|
| 34 |
title="QR Code Scanner",
|
| 35 |
-
description="Upload an image containing a QR code to decode
|
| 36 |
)
|
| 37 |
|
| 38 |
-
# Launch the
|
| 39 |
if __name__ == "__main__":
|
| 40 |
-
iface.launch()
|
|
|
|
| 1 |
# app.py
|
| 2 |
# =============
|
| 3 |
+
# This is a complete app.py file for a QR code scanner using Gradio and Hugging Face Transformers.
|
| 4 |
|
| 5 |
import gradio as gr
|
| 6 |
+
import cv2
|
| 7 |
from pyzbar.pyzbar import decode
|
| 8 |
from PIL import Image
|
| 9 |
+
import numpy as np
|
| 10 |
|
| 11 |
+
def scan_qr_code(image):
|
| 12 |
"""
|
| 13 |
+
Scan QR code from the uploaded image.
|
| 14 |
|
| 15 |
Args:
|
| 16 |
+
image (PIL.Image.Image): The uploaded image.
|
| 17 |
|
| 18 |
Returns:
|
| 19 |
+
str: The decoded QR code data.
|
| 20 |
"""
|
| 21 |
+
# Convert PIL image to OpenCV format
|
| 22 |
+
open_cv_image = np.array(image)
|
| 23 |
+
open_cv_image = open_cv_image[:, :, ::-1].copy()
|
| 24 |
|
| 25 |
+
# Decode QR code
|
| 26 |
+
decoded_objects = decode(open_cv_image)
|
| 27 |
if decoded_objects:
|
| 28 |
+
for obj in decoded_objects:
|
| 29 |
+
return obj.data.decode('utf-8')
|
| 30 |
+
return "No QR code found"
|
|
|
|
| 31 |
|
| 32 |
+
# Define the Gradio interface
|
| 33 |
iface = gr.Interface(
|
| 34 |
+
fn=scan_qr_code,
|
| 35 |
+
inputs=gr.inputs.Image(type="pil"),
|
| 36 |
+
outputs=gr.outputs.Textbox(),
|
| 37 |
title="QR Code Scanner",
|
| 38 |
+
description="Upload an image containing a QR code to decode it."
|
| 39 |
)
|
| 40 |
|
| 41 |
+
# Launch the Gradio app
|
| 42 |
if __name__ == "__main__":
|
| 43 |
+
iface.launch()
|