Spaces:
Sleeping
Sleeping
Updated
Browse files
app.py
CHANGED
|
@@ -7,11 +7,18 @@ import numpy as np
|
|
| 7 |
detector = pipeline("object-detection", model="mdefrance/yolos-tiny-signature-detection")
|
| 8 |
|
| 9 |
# Fix: Convert NumPy to PIL image
|
| 10 |
-
def detect_signature(image
|
| 11 |
if image is None:
|
| 12 |
return {"error": "❌ Please draw or upload a signature before submitting."}
|
| 13 |
|
| 14 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
results = detector(pil_image)
|
| 16 |
|
| 17 |
valid = [r for r in results if r["score"] > 0.3]
|
|
@@ -20,6 +27,7 @@ def detect_signature(image: np.ndarray):
|
|
| 20 |
|
| 21 |
return {"message": "✅ Signature detected.", "detections": valid}
|
| 22 |
|
|
|
|
| 23 |
# Interface
|
| 24 |
gr.Interface(
|
| 25 |
fn=detect_signature,
|
|
|
|
| 7 |
detector = pipeline("object-detection", model="mdefrance/yolos-tiny-signature-detection")
|
| 8 |
|
| 9 |
# Fix: Convert NumPy to PIL image
|
| 10 |
+
def detect_signature(image):
|
| 11 |
if image is None:
|
| 12 |
return {"error": "❌ Please draw or upload a signature before submitting."}
|
| 13 |
|
| 14 |
+
# Normalize input structure
|
| 15 |
+
if isinstance(image, dict):
|
| 16 |
+
image = image.get("image", None)
|
| 17 |
+
|
| 18 |
+
if image is None:
|
| 19 |
+
return {"error": "❌ No image data received."}
|
| 20 |
+
|
| 21 |
+
pil_image = Image.fromarray(np.array(image).astype("uint8"), "RGB")
|
| 22 |
results = detector(pil_image)
|
| 23 |
|
| 24 |
valid = [r for r in results if r["score"] > 0.3]
|
|
|
|
| 27 |
|
| 28 |
return {"message": "✅ Signature detected.", "detections": valid}
|
| 29 |
|
| 30 |
+
|
| 31 |
# Interface
|
| 32 |
gr.Interface(
|
| 33 |
fn=detect_signature,
|