pirahansiah commited on
Commit
d3a35cb
·
1 Parent(s): 89e42b0

computer vision 1

Browse files
Files changed (1) hide show
  1. app.py +38 -37
app.py CHANGED
@@ -6,7 +6,8 @@ import os
6
  from ultralytics import YOLO
7
 
8
  file_urls = [
9
- 'https://lh3.googleusercontent.com/a2iyhpYl4Jgzc0r7MYgXQI1BGwkutp3rKuauNpkEbD3Z_HP-gf29M-wugKebKJQdl8ILtKWN-vOZAS9r1qMsI88=w16383'
 
10
  ]
11
 
12
  def download_file(url, save_name):
@@ -50,42 +51,42 @@ interface_image = gr.Interface(
50
  cache_examples=False,
51
  )
52
 
53
- # def show_preds_video(video_path):
54
- # cap = cv2.VideoCapture(video_path)
55
- # while(cap.isOpened()):
56
- # ret, frame = cap.read()
57
- # if ret:
58
- # frame_copy = frame.copy()
59
- # outputs = model.predict(source=frame)
60
- # results = outputs[0].cpu().numpy()
61
- # for i, det in enumerate(results.boxes.xyxy):
62
- # cv2.rectangle(
63
- # frame_copy,
64
- # (int(det[0]), int(det[1])),
65
- # (int(det[2]), int(det[3])),
66
- # color=(0, 0, 255),
67
- # thickness=2,
68
- # lineType=cv2.LINE_AA
69
- # )
70
- # yield cv2.cvtColor(frame_copy, cv2.COLOR_BGR2RGB)
71
 
72
- # inputs_video = [
73
- # gr.components.Video(type="filepath", label="Input Video"),
74
 
75
- # ]
76
- # outputs_video = [
77
- # gr.components.Image(type="numpy", label="Output Image"),
78
- # ]
79
- # interface_video = gr.Interface(
80
- # fn=show_preds_video,
81
- # inputs=inputs_video,
82
- # outputs=outputs_video,
83
- # title="Pothole detector",
84
- # examples=video_path,
85
- # cache_examples=False,
86
- # )
87
 
88
- # gr.TabbedInterface(
89
- # [interface_image, interface_video],
90
- # tab_names=['Image inference', 'Video inference']
91
- # ).queue().launch()
 
6
  from ultralytics import YOLO
7
 
8
  file_urls = [
9
+ 'https://lh3.googleusercontent.com/a2iyhpYl4Jgzc0r7MYgXQI1BGwkutp3rKuauNpkEbD3Z_HP-gf29M-wugKebKJQdl8ILtKWN-vOZAS9r1qMsI88=w16383',
10
+ 'https://www.dropbox.com/s/7sjfwncffg8xej2/video_7.mp4?dl=1'
11
  ]
12
 
13
  def download_file(url, save_name):
 
51
  cache_examples=False,
52
  )
53
 
54
+ def show_preds_video(video_path):
55
+ cap = cv2.VideoCapture(video_path)
56
+ while(cap.isOpened()):
57
+ ret, frame = cap.read()
58
+ if ret:
59
+ frame_copy = frame.copy()
60
+ outputs = model.predict(source=frame)
61
+ results = outputs[0].cpu().numpy()
62
+ for i, det in enumerate(results.boxes.xyxy):
63
+ cv2.rectangle(
64
+ frame_copy,
65
+ (int(det[0]), int(det[1])),
66
+ (int(det[2]), int(det[3])),
67
+ color=(0, 0, 255),
68
+ thickness=2,
69
+ lineType=cv2.LINE_AA
70
+ )
71
+ yield cv2.cvtColor(frame_copy, cv2.COLOR_BGR2RGB)
72
 
73
+ inputs_video = [
74
+ gr.components.Video(type="filepath", label="Input Video"),
75
 
76
+ ]
77
+ outputs_video = [
78
+ gr.components.Image(type="numpy", label="Output Image"),
79
+ ]
80
+ interface_video = gr.Interface(
81
+ fn=show_preds_video,
82
+ inputs=inputs_video,
83
+ outputs=outputs_video,
84
+ title="Video Processing ",
85
+ examples=video_path,
86
+ cache_examples=False,
87
+ )
88
 
89
+ gr.TabbedInterface(
90
+ [interface_image, interface_video],
91
+ tab_names=['Image inference', 'Video inference']
92
+ ).queue().launch()