rupesh002 commited on
Commit
e42ea67
Β·
verified Β·
1 Parent(s): 1ff1c32

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -13
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") # 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,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 "❌ 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"),
39
- outputs=gr.Video(label="Detected Video Output"),
 
 
 
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()