Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from PIL import Image
|
| 3 |
+
from ultralytics import YOLO
|
| 4 |
+
from huggingface_hub import snapshot_download
|
| 5 |
+
import os
|
| 6 |
+
|
| 7 |
+
# Download the model from HF Hub (if not already cached)
|
| 8 |
+
model_dir = snapshot_download("cazzz307/Pothole-Finetuned-YoloV8")
|
| 9 |
+
model_path = os.path.join(model_dir, "best.pt")
|
| 10 |
+
|
| 11 |
+
# Load model
|
| 12 |
+
model = YOLO(model_path)
|
| 13 |
+
|
| 14 |
+
def detect_potholes(image: Image.Image):
|
| 15 |
+
results = model(image)
|
| 16 |
+
annotated_img = results[0].plot() # Returns numpy array with drawings
|
| 17 |
+
return Image.fromarray(annotated_img)
|
| 18 |
+
|
| 19 |
+
# Gradio Interface
|
| 20 |
+
demo = gr.Interface(
|
| 21 |
+
fn=detect_potholes,
|
| 22 |
+
inputs=gr.Image(type="pil"),
|
| 23 |
+
outputs=gr.Image(type="pil"),
|
| 24 |
+
title="YOLOv8 Pothole Detection",
|
| 25 |
+
description="Upload a road image. The model will highlight detected potholes using a YOLOv8 model fine-tuned on pothole datasets."
|
| 26 |
+
)
|
| 27 |
+
|
| 28 |
+
demo.launch()
|