Raghvender commited on
Commit
78f69af
·
1 Parent(s): a0b1b08

Upload gradioDemo.py

Browse files
Files changed (1) hide show
  1. gradioDemo.py +46 -0
gradioDemo.py ADDED
@@ -0,0 +1,46 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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:
14
+ frame_copy = frame.copy()
15
+ outputs = model.predict(source=frame)
16
+ res = outputs[0].cpu().numpy()
17
+ for i, det in enumerate(res.boxes.xyxy):
18
+ cv2.rectangle(
19
+ frame_copy,
20
+ (int(det[0]), int(det[1])),
21
+ (int(det[2]), int(det[3])),
22
+ color=(0, 0, 255),
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()