import gradio as gr from ultralytics import YOLO from PIL import Image import numpy as np import os import gdown # ✅ Download model from Google Drive if not already present model_path = "best.pt" file_id = "1O9C2ACDdqWKbgEShbf3AkuSqBKWDgJ3t" if not os.path.exists(model_path): url = f"https://drive.google.com/uc?id={file_id}" gdown.download(url, model_path, quiet=False) # ✅ Load the model model = YOLO(model_path) # ✅ Prediction function def detect_damage(img): results = model.predict(img, conf=0.25) annotated = results[0].plot() return Image.fromarray(annotated) # ✅ Gradio UI demo = gr.Interface( fn=detect_damage, inputs=gr.Image(type="pil", label="Upload Car Image"), outputs=gr.Image(type="pil", label="Detected Damage"), title="🚗 Car Damage Detector (YOLOv8)", description="Upload an image to detect scratch, dent, crack, and more using a trained YOLOv8 model." ) demo.launch()