File size: 1,051 Bytes
c92ad91
 
 
 
e42ea67
c92ad91
 
 
e42ea67
 
 
c92ad91
e42ea67
c92ad91
 
 
 
 
 
 
 
 
 
 
1ff1c32
c92ad91
e42ea67
1ff1c32
e42ea67
 
 
c92ad91
1ff1c32
c92ad91
 
 
e42ea67
 
 
 
c92ad91
 
 
5530e7a
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
from ultralytics import YOLO
import gradio as gr
import tempfile, os, shutil, glob

model = YOLO("best.pt")

def detect_potholes(video):
    if video is None:
        return "Please upload a video.", None
    
    video_path = video  # gr.Video gives file path

    # Remove old results
    if os.path.exists("runs"):
        shutil.rmtree("runs")

    model.predict(
        source=video_path,
        save=True,
        conf=0.35,
        iou=0.5
    )

    output_files = glob.glob("runs/detect/*/*.mp4")

    if len(output_files) == 0:
        return "❌ No output generated.", None

    output_video = output_files[0]

    return output_video, output_video   # ⬅️ return video for preview AND download


app = gr.Interface(
    fn=detect_potholes,
    inputs=gr.Video(label="Upload Dashcam Video"),
    outputs=[
        gr.Video(label="Processed Video ✅"),
        gr.File(label="Download Video ⬇️")
    ],
    title="🚧 Pothole Detection AI",
    description="Upload a dashcam video and detect potholes using YOLO."
)
app.launch()