Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -3,36 +3,34 @@ from PIL import Image
|
|
3 |
import os
|
4 |
import sys
|
5 |
|
6 |
-
#
|
7 |
sys.path.append(os.path.abspath("yolov12"))
|
8 |
|
9 |
-
# Import your
|
10 |
-
from yolo import
|
11 |
|
12 |
-
#
|
13 |
-
|
|
|
14 |
|
15 |
def detect_damage(image: Image.Image):
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
print("Detected:", label)
|
24 |
-
if "apple_damaged" in label.lower():
|
25 |
-
is_damaged = True
|
26 |
-
break
|
27 |
|
28 |
return {"is_damaged": is_damaged}
|
29 |
|
|
|
30 |
demo = gr.Interface(
|
31 |
fn=detect_damage,
|
32 |
inputs=gr.Image(type="pil"),
|
33 |
outputs=gr.JSON(label="Detection Result"),
|
34 |
title="🍎 Apple Damage Detector (YOLOv12)",
|
35 |
-
description="Upload an image
|
36 |
)
|
37 |
|
38 |
demo.launch()
|
|
|
3 |
import os
|
4 |
import sys
|
5 |
|
6 |
+
# Add yolov12 folder to import path
|
7 |
sys.path.append(os.path.abspath("yolov12"))
|
8 |
|
9 |
+
# Import your inference function
|
10 |
+
from yolo import run_yolov12_inference
|
11 |
|
12 |
+
# Create temp upload dir
|
13 |
+
UPLOAD_DIR = "static/uploaded"
|
14 |
+
os.makedirs(UPLOAD_DIR, exist_ok=True)
|
15 |
|
16 |
def detect_damage(image: Image.Image):
|
17 |
+
# Save image to temp path
|
18 |
+
img_name = "test_image.jpg"
|
19 |
+
img_path = os.path.join(UPLOAD_DIR, img_name)
|
20 |
+
image.save(img_path)
|
21 |
+
|
22 |
+
# Run inference using your script
|
23 |
+
is_damaged = run_yolov12_inference(img_path)
|
|
|
|
|
|
|
|
|
24 |
|
25 |
return {"is_damaged": is_damaged}
|
26 |
|
27 |
+
# Gradio interface
|
28 |
demo = gr.Interface(
|
29 |
fn=detect_damage,
|
30 |
inputs=gr.Image(type="pil"),
|
31 |
outputs=gr.JSON(label="Detection Result"),
|
32 |
title="🍎 Apple Damage Detector (YOLOv12)",
|
33 |
+
description="Upload an apple image to check if it's damaged using a custom YOLOv12 model."
|
34 |
)
|
35 |
|
36 |
demo.launch()
|