|
|
import gradio as gr
|
|
|
from ultralytics import YOLO
|
|
|
from PIL import Image
|
|
|
import numpy as np
|
|
|
import os
|
|
|
import gdown
|
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
|
|
|
|
model = YOLO(model_path)
|
|
|
|
|
|
|
|
|
def detect_damage(img):
|
|
|
results = model.predict(img, conf=0.25)
|
|
|
annotated = results[0].plot()
|
|
|
return Image.fromarray(annotated)
|
|
|
|
|
|
|
|
|
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()
|
|
|
|