Tejeshwar's picture
Update app.py
b456065 verified
raw
history blame
998 Bytes
import gradio as gr
from PIL import Image
import sys
# Add yolov12 to Python path
sys.path.append("yolov12")
# Correct import from yolov12 repo
from yolov12.models.yolo import YOLO
# βœ… Correct path to the actual weights file
model = YOLO("yolov12/runs/detect/train7/weights/best.pt")
def detect_damage(image: Image.Image):
results = model(image)
is_damaged = False
for result in results:
for box in result.boxes:
class_id = int(box.cls[0])
label = model.names[class_id]
print("Detected:", label)
if "apple_damaged" in label.lower():
is_damaged = True
break
return {"is_damaged": is_damaged}
demo = gr.Interface(
fn=detect_damage,
inputs=gr.Image(type="pil"),
outputs=gr.JSON(label="Detection Result"),
title="🍎 Apple Damage Detector (YOLOv12)",
description="Upload an image of an apple to check if it's damaged using your custom YOLOv12 model."
)
demo.launch()