Spaces:
Sleeping
Sleeping
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() | |