Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -3,34 +3,27 @@ from PIL import Image
|
|
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
|
34 |
)
|
35 |
|
36 |
demo.launch()
|
|
|
3 |
import os
|
4 |
import sys
|
5 |
|
|
|
6 |
sys.path.append(os.path.abspath("yolov12"))
|
7 |
|
|
|
8 |
from yolo import run_yolov12_inference
|
9 |
|
|
|
10 |
UPLOAD_DIR = "static/uploaded"
|
11 |
os.makedirs(UPLOAD_DIR, exist_ok=True)
|
12 |
|
13 |
def detect_damage(image: Image.Image):
|
|
|
14 |
img_name = "test_image.jpg"
|
15 |
img_path = os.path.join(UPLOAD_DIR, img_name)
|
16 |
image.save(img_path)
|
17 |
|
|
|
18 |
is_damaged = run_yolov12_inference(img_path)
|
|
|
19 |
return {"is_damaged": is_damaged}
|
20 |
|
|
|
21 |
demo = gr.Interface(
|
22 |
fn=detect_damage,
|
23 |
inputs=gr.Image(type="pil"),
|
24 |
outputs=gr.JSON(label="Detection Result"),
|
25 |
title="🍎 Apple Damage Detector (YOLOv12)",
|
26 |
+
description="Upload an apple image to check if it's damaged using YOLOv12."
|
27 |
)
|
28 |
|
29 |
demo.launch()
|