Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -5,18 +5,18 @@ import tempfile, os, shutil, glob
|
|
| 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 |
-
|
| 15 |
-
|
| 16 |
|
|
|
|
| 17 |
if os.path.exists("runs"):
|
| 18 |
shutil.rmtree("runs")
|
| 19 |
|
|
|
|
| 20 |
model.predict(
|
| 21 |
source=video_path,
|
| 22 |
save=True,
|
|
@@ -24,13 +24,15 @@ def detect_potholes(video):
|
|
| 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"),
|
|
@@ -40,3 +42,4 @@ app = gr.Interface(
|
|
| 40 |
)
|
| 41 |
|
| 42 |
app.launch()
|
|
|
|
|
|
| 5 |
model = YOLO("best.pt") # make sure model file name matches
|
| 6 |
|
| 7 |
def detect_potholes(video):
|
| 8 |
+
|
| 9 |
if video is None:
|
| 10 |
return "Please upload a video."
|
|
|
|
|
|
|
|
|
|
| 11 |
|
| 12 |
+
# ✅ video is already a file path string from Gradio
|
| 13 |
+
video_path = video
|
| 14 |
|
| 15 |
+
# ✅ Reset runs folder (optional but clean)
|
| 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 |
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 "❌ Error: No output generated."
|
| 32 |
+
|
| 33 |
return output_files[0]
|
| 34 |
|
| 35 |
+
|
| 36 |
app = gr.Interface(
|
| 37 |
fn=detect_potholes,
|
| 38 |
inputs=gr.Video(label="Upload Dashcam Video"),
|
|
|
|
| 42 |
)
|
| 43 |
|
| 44 |
app.launch()
|
| 45 |
+
|