Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,37 +1,35 @@
|
|
1 |
import gradio as gr
|
2 |
-
import numpy as np
|
3 |
from PIL import Image
|
4 |
-
|
5 |
-
|
6 |
|
7 |
-
#
|
8 |
-
|
9 |
-
|
10 |
-
model
|
|
|
|
|
|
|
11 |
|
12 |
-
# β
Damage detection using YOLOv12
|
13 |
def detect_damage(image: Image.Image):
|
14 |
results = model(image)
|
15 |
-
|
16 |
is_damaged = False
|
|
|
17 |
for result in results:
|
18 |
for box in result.boxes:
|
19 |
class_id = int(box.cls[0])
|
20 |
label = model.names[class_id]
|
21 |
-
print("Detected
|
22 |
if "apple_damaged" in label.lower():
|
23 |
is_damaged = True
|
24 |
break
|
25 |
|
26 |
return {"is_damaged": is_damaged}
|
27 |
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
title="π Apple Damage Detector",
|
34 |
-
description="Upload an apple image to detect whether it is damaged using a YOLOv12 model."
|
35 |
-
)
|
36 |
|
37 |
demo.launch()
|
|
|
1 |
import gradio as gr
|
|
|
2 |
from PIL import Image
|
3 |
+
import sys
|
4 |
+
import os
|
5 |
|
6 |
+
# π Add your custom YOLOv12 path to Python path
|
7 |
+
sys.path.append("yolov12")
|
8 |
+
|
9 |
+
# π Import your custom model loader
|
10 |
+
from models.yolo import YOLO # adjust based on your repo
|
11 |
+
|
12 |
+
model = YOLO("yolov12/best.pt")
|
13 |
|
|
|
14 |
def detect_damage(image: Image.Image):
|
15 |
results = model(image)
|
|
|
16 |
is_damaged = False
|
17 |
+
|
18 |
for result in results:
|
19 |
for box in result.boxes:
|
20 |
class_id = int(box.cls[0])
|
21 |
label = model.names[class_id]
|
22 |
+
print("Detected:", label)
|
23 |
if "apple_damaged" in label.lower():
|
24 |
is_damaged = True
|
25 |
break
|
26 |
|
27 |
return {"is_damaged": is_damaged}
|
28 |
|
29 |
+
demo = gr.Interface(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 image of an apple to check if it's damaged.")
|
|
|
|
|
|
|
34 |
|
35 |
demo.launch()
|