File size: 725 Bytes
dae7c61
 
81e9e78
d1735aa
dae7c61
81e9e78
d1735aa
6aea0c0
d1735aa
6aea0c0
 
dae7c61
 
6aea0c0
 
 
 
 
dae7c61
 
b456065
 
 
 
 
4e1b6d4
b456065
dae7c61
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import gradio as gr
from PIL import Image
import os
import sys

sys.path.append(os.path.abspath("yolov12"))

from yolo import run_yolov12_inference

UPLOAD_DIR = "static/uploaded"
os.makedirs(UPLOAD_DIR, exist_ok=True)

def detect_damage(image: Image.Image):
    img_name = "test_image.jpg"
    img_path = os.path.join(UPLOAD_DIR, img_name)
    image.save(img_path)

    is_damaged = run_yolov12_inference(img_path)
    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 apple image to check if it's damaged using YOLOv12."
)

demo.launch()