Raghvender commited on
Commit
3906f18
·
1 Parent(s): 6feb524

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -17
app.py CHANGED
@@ -1,13 +1,16 @@
1
  import gradio as gr
2
  import cv2
3
- import requests
4
- import os
5
  from ultralytics import YOLO
6
 
7
  model = YOLO('best.pt')
8
- # video_path = 'Deployment\\test_videos\\test2.mp4'
9
- def show_preds(video_path):
10
  cap = cv2.VideoCapture(video_path)
 
 
 
 
 
11
  while True:
12
  ret, frame = cap.read()
13
  if ret:
@@ -23,24 +26,25 @@ def show_preds(video_path):
23
  thickness=2,
24
  lineType=cv2.LINE_AA
25
  )
 
26
  yield cv2.cvtColor(frame_copy, cv2.COLOR_BGR2RGB)
 
 
 
27
 
28
  input_video = [
29
- gr.components.Video(type='filepath', label='Input Video'),
30
  ]
31
- outputs_video = [
32
- gr.components.Image(type='numpy', label='Output Image'),
33
  ]
34
- interface_video = gr.Interface(
35
- fn=show_preds,
36
- inputs=input_video,
37
- outputs=outputs_video,
 
38
  title='Pothole Detection',
39
- #examples=video_path,
40
- cache_examples=False,
41
  )
42
 
43
- gr.TabbedInterface(
44
- [interface_video],
45
- tab_names=['Video Inference']
46
- ).queue().launch()
 
1
  import gradio as gr
2
  import cv2
 
 
3
  from ultralytics import YOLO
4
 
5
  model = YOLO('best.pt')
6
+
7
+ def show_preds(video_path, output_path):
8
  cap = cv2.VideoCapture(video_path)
9
+ width = int(cap.get(cv2.CAP_PROP_FRAME_WIDTH))
10
+ height = int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT))
11
+ fps = cap.get(cv2.CAP_PROP_FPS)
12
+ fourcc = cv2.VideoWriter_fourcc(*'h264')
13
+ writer = cv2.VideoWriter(output_path, fourcc, fps, (width, height))
14
  while True:
15
  ret, frame = cap.read()
16
  if ret:
 
26
  thickness=2,
27
  lineType=cv2.LINE_AA
28
  )
29
+ writer.write(frame_copy)
30
  yield cv2.cvtColor(frame_copy, cv2.COLOR_BGR2RGB)
31
+ else:
32
+ break
33
+ writer.release()
34
 
35
  input_video = [
36
+ gr.inputs.Video(type='file', label='Input Video'),
37
  ]
38
+ output_video = [
39
+ gr.outputs.Video(type='file', label='Output Video'),
40
  ]
41
+
42
+ interface = gr.Interface(
43
+ show_preds,
44
+ inputs=input_video, # type: ignore
45
+ outputs=output_video, # type: ignore
46
  title='Pothole Detection',
47
+ description='Potholes Detection using YOLOv8',
 
48
  )
49
 
50
+ interface.queue().launch()