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()