Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from ultralytics import YOLO
|
| 2 |
+
import gradio as gr
|
| 3 |
+
import tempfile, os, shutil, glob
|
| 4 |
+
|
| 5 |
+
model = YOLO("best.pt") # make sure model file name matches
|
| 6 |
+
|
| 7 |
+
def detect_potholes(video):
|
| 8 |
+
if video is None:
|
| 9 |
+
return "Please upload a video."
|
| 10 |
+
|
| 11 |
+
temp_dir = tempfile.mkdtemp()
|
| 12 |
+
video_path = os.path.join(temp_dir, "input.mp4")
|
| 13 |
+
|
| 14 |
+
with open(video_path, "wb") as f:
|
| 15 |
+
f.write(video.read())
|
| 16 |
+
|
| 17 |
+
if os.path.exists("runs"):
|
| 18 |
+
shutil.rmtree("runs")
|
| 19 |
+
|
| 20 |
+
model.predict(
|
| 21 |
+
source=video_path,
|
| 22 |
+
save=True,
|
| 23 |
+
conf=0.35,
|
| 24 |
+
iou=0.5
|
| 25 |
+
)
|
| 26 |
+
|
| 27 |
+
output_files = glob.glob("runs/detect/*/*.mp4")
|
| 28 |
+
|
| 29 |
+
if len(output_files) == 0:
|
| 30 |
+
return "❌ Error: No output generated."
|
| 31 |
+
|
| 32 |
+
return output_files[0]
|
| 33 |
+
|
| 34 |
+
app = gr.Interface(
|
| 35 |
+
fn=detect_potholes,
|
| 36 |
+
inputs=gr.Video(label="Upload Dashcam Video"),
|
| 37 |
+
outputs=gr.Video(label="Detected Video Output"),
|
| 38 |
+
title="🚧 Pothole Detection AI",
|
| 39 |
+
description="Upload a dashcam video and detect potholes using YOLO."
|
| 40 |
+
)
|
| 41 |
+
|
| 42 |
+
app.launch()
|