Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -2,21 +2,18 @@ from ultralytics import YOLO
|
|
| 2 |
import gradio as gr
|
| 3 |
import tempfile, os, shutil, glob
|
| 4 |
|
| 5 |
-
model = YOLO("best.pt")
|
| 6 |
|
| 7 |
def detect_potholes(video):
|
| 8 |
-
|
| 9 |
if video is None:
|
| 10 |
-
return "Please upload a video."
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
video_path = video
|
| 14 |
|
| 15 |
-
#
|
| 16 |
if os.path.exists("runs"):
|
| 17 |
shutil.rmtree("runs")
|
| 18 |
|
| 19 |
-
# β
YOLO prediction
|
| 20 |
model.predict(
|
| 21 |
source=video_path,
|
| 22 |
save=True,
|
|
@@ -24,22 +21,25 @@ def detect_potholes(video):
|
|
| 24 |
iou=0.5
|
| 25 |
)
|
| 26 |
|
| 27 |
-
# β
Find output video path from YOLO runs
|
| 28 |
output_files = glob.glob("runs/detect/*/*.mp4")
|
| 29 |
|
| 30 |
if len(output_files) == 0:
|
| 31 |
-
return "β
|
| 32 |
|
| 33 |
-
|
|
|
|
|
|
|
| 34 |
|
| 35 |
|
| 36 |
app = gr.Interface(
|
| 37 |
fn=detect_potholes,
|
| 38 |
inputs=gr.Video(label="Upload Dashcam Video"),
|
| 39 |
-
outputs=
|
|
|
|
|
|
|
|
|
|
| 40 |
title="π§ Pothole Detection AI",
|
| 41 |
description="Upload a dashcam video and detect potholes using YOLO."
|
| 42 |
)
|
| 43 |
|
| 44 |
app.launch()
|
| 45 |
-
|
|
|
|
| 2 |
import gradio as gr
|
| 3 |
import tempfile, os, shutil, glob
|
| 4 |
|
| 5 |
+
model = YOLO("best.pt")
|
| 6 |
|
| 7 |
def detect_potholes(video):
|
|
|
|
| 8 |
if video is None:
|
| 9 |
+
return "Please upload a video.", None
|
| 10 |
+
|
| 11 |
+
video_path = video # gr.Video gives file path
|
|
|
|
| 12 |
|
| 13 |
+
# Remove old results
|
| 14 |
if os.path.exists("runs"):
|
| 15 |
shutil.rmtree("runs")
|
| 16 |
|
|
|
|
| 17 |
model.predict(
|
| 18 |
source=video_path,
|
| 19 |
save=True,
|
|
|
|
| 21 |
iou=0.5
|
| 22 |
)
|
| 23 |
|
|
|
|
| 24 |
output_files = glob.glob("runs/detect/*/*.mp4")
|
| 25 |
|
| 26 |
if len(output_files) == 0:
|
| 27 |
+
return "β No output generated.", None
|
| 28 |
|
| 29 |
+
output_video = output_files[0]
|
| 30 |
+
|
| 31 |
+
return output_video, output_video # β¬
οΈ return video for preview AND download
|
| 32 |
|
| 33 |
|
| 34 |
app = gr.Interface(
|
| 35 |
fn=detect_potholes,
|
| 36 |
inputs=gr.Video(label="Upload Dashcam Video"),
|
| 37 |
+
outputs=[
|
| 38 |
+
gr.Video(label="Processed Video β
"),
|
| 39 |
+
gr.File(label="Download Video β¬οΈ")
|
| 40 |
+
],
|
| 41 |
title="π§ Pothole Detection AI",
|
| 42 |
description="Upload a dashcam video and detect potholes using YOLO."
|
| 43 |
)
|
| 44 |
|
| 45 |
app.launch()
|
|
|