NAGA commited on
Commit
2b32015
·
1 Parent(s): 6748ade

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +121 -0
app.py ADDED
@@ -0,0 +1,121 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # To run use
2
+ # $ streamlit run yolor_streamlit_demo.py
3
+
4
+ from yolo_v7 import names, load_yolov7_and_process_each_frame
5
+
6
+ import tempfile
7
+ import cv2
8
+
9
+ from models.models import *
10
+ from utils.datasets import *
11
+ from utils.general import *
12
+ import streamlit as st
13
+
14
+
15
+ def main():
16
+
17
+ #title
18
+ st.title('Object Tracking Dashboard YOLOv7-tiny')
19
+
20
+ #side bar title
21
+ st.sidebar.title('Settings')
22
+
23
+ st.markdown(
24
+ """
25
+ <style>
26
+ [data-testid="stSidebar"][aria-expanded="true"] > div:first-child {
27
+ width: 350px;
28
+ }
29
+ [data-testid="stSidebar"][aria-expanded="false"] > div:first-child {
30
+ width: 350px;
31
+ margin-left: -350px;
32
+ }
33
+ </style>
34
+ """,
35
+ unsafe_allow_html=True,
36
+ )
37
+
38
+ use_webcam = st.sidebar.checkbox('Use Webcam')
39
+
40
+ st.sidebar.markdown('---')
41
+ confidence = st.sidebar.slider('Confidence',min_value=0.0, max_value=1.0, value = 0.25)
42
+ st.sidebar.markdown('---')
43
+
44
+ save_img = st.sidebar.checkbox('Save Video')
45
+ enable_GPU = st.sidebar.checkbox('enable GPU')
46
+
47
+ custom_classes = st.sidebar.checkbox('Use Custom Classes')
48
+ assigned_class_id = []
49
+ if custom_classes:
50
+ assigned_class = st.sidebar.multiselect('Select The Custom Classes',list(names),default='person')
51
+ for each in assigned_class:
52
+ assigned_class_id.append(names.index(each))
53
+
54
+ video_file_buffer = st.sidebar.file_uploader("Upload a video", type=[ "mp4", "mov",'avi','asf', 'm4v' ])
55
+
56
+ DEMO_VIDEO = 'test.mp4'
57
+
58
+ tfflie = tempfile.NamedTemporaryFile(suffix='.mp4', delete=False)
59
+
60
+
61
+ ##We get our input video here
62
+
63
+ if not video_file_buffer:
64
+ if use_webcam:
65
+ vid = cv2.VideoCapture(0, cv2.CAP_ARAVIS)
66
+ tfflie.name = 0
67
+ else:
68
+ vid = cv2.VideoCapture(DEMO_VIDEO)
69
+ tfflie.name = DEMO_VIDEO
70
+ dem_vid = open(tfflie.name,'rb')
71
+ demo_bytes = dem_vid.read()
72
+
73
+ st.sidebar.text('Input Video')
74
+ st.sidebar.video(demo_bytes)
75
+
76
+ else:
77
+ tfflie.write(video_file_buffer.read())
78
+ # print("No Buffer")
79
+ dem_vid = open(tfflie.name,'rb')
80
+ demo_bytes = dem_vid.read()
81
+
82
+ st.sidebar.text('Input Video')
83
+ st.sidebar.video(demo_bytes)
84
+
85
+
86
+ print(tfflie.name)
87
+ # vid = cv2.VideoCapture(tfflie.name)
88
+
89
+ stframe = st.empty()
90
+
91
+ st.markdown("<hr/>", unsafe_allow_html=True)
92
+ kpi1, kpi2, kpi3 = st.beta_columns(3) #st.columns(3)
93
+
94
+ # stframe.image(im0,channels = 'BGR',use_column_width=True)
95
+
96
+ with kpi1:
97
+ st.markdown("**Frame Rate**")
98
+ kpi1_text = st.markdown("0")
99
+
100
+ with kpi2:
101
+ st.markdown("**Tracked Objects**")
102
+ kpi2_text = st.markdown("0")
103
+
104
+ with kpi3:
105
+ st.markdown("**Total Count**")
106
+ kpi3_text = st.markdown("0")
107
+
108
+ st.markdown("<hr/>", unsafe_allow_html=True)
109
+ # call yolor
110
+ # load_yolor_and_process_each_frame(tfflie.name, enable_GPU, confidence, assigned_class_id, kpi1_text, kpi2_text, kpi3_text, stframe)
111
+ load_yolov7_and_process_each_frame('yolov7-tiny', tfflie.name, enable_GPU, save_img, confidence, assigned_class_id, kpi1_text, kpi2_text, kpi3_text, stframe)
112
+
113
+ st.text('Video is Processed')
114
+
115
+ if __name__ == '__main__':
116
+ try:
117
+ main()
118
+ except SystemExit:
119
+ pass
120
+
121
+