Spaces:
Sleeping
Sleeping
File size: 979 Bytes
9e00082 |
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 31 32 33 34 35 |
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()
|