umerforsure's picture
Upload 2 files
9e00082 verified
raw
history blame contribute delete
979 Bytes
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()