-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
186 lines (141 loc) · 5.74 KB
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
import streamlit as st
from obj_det_and_trk_streamlit import *
#--------------------------------Web Page Designing------------------------------
hide_menu_style = """
<style>
MainMenu {visibility: hidden;}
div[data-testid="stHorizontalBlock"]> div:nth-child(1)
{
border : 2px solid #doe0db;
border-radius:5px;
text-align:center;
color:black;
background:dodgerblue;
font-weight:bold;
padding: 25px;
}
div[data-testid="stHorizontalBlock"]> div:nth-child(2)
{
border : 2px solid #doe0db;
background:dodgerblue;
border-radius:5px;
text-align:center;
font-weight:bold;
color:black;
padding: 25px;
}
</style>
"""
main_title = """
<div>
<h1 style="color:black;
text-align:center; font-size:35px;
margin-top:-95px;">
YOLOv5 People Detection and Tracking</h1>
</div>
"""
sub_title = """
<div>
<h6 style="color:dodgerblue;
text-align:center;
margin-top:-40px;">
Streamlit Basic Dasboard </h6>
</div>
"""
#--------------------------------------------------------------------------------
#---------------------------Main Function for Execution--------------------------
def main():
st.set_page_config(page_title='Dashboard',
layout = 'wide',
initial_sidebar_state = 'auto')
st.markdown(hide_menu_style,
unsafe_allow_html=True)
st.markdown(main_title,
unsafe_allow_html=True)
st.markdown(sub_title,
unsafe_allow_html=True)
inference_msg = st.empty()
st.sidebar.title("USER Configuration")
input_source = st.sidebar.radio("Source",
('Video', 'WebCam'))
conf_thres = st.sidebar.text_input("Class confidence threshold",
"0.25")
save_output_video = st.sidebar.radio("Save output video?",
('Yes', 'No'))
if save_output_video == 'Yes':
nosave = False
display_labels=False
else:
nosave = True
display_labels = True
weights = "yolov5n.pt"
device="cpu"
# ------------------------- LOCAL VIDEO ------------------------
if input_source == "Video":
video = st.sidebar.file_uploader("Select input video",
type=["mp4", "avi"],
accept_multiple_files=False)
if st.sidebar.button("Start Tracking"):
stframe = st.empty()
st.markdown("""<h4 style="color:black;">
Memory Overall Statistics</h4>""",
unsafe_allow_html=True)
kpi5, kpi6 = st.columns(2)
with kpi5:
st.markdown("""<h5 style="color:black;">
CPU Utilization</h5>""",
unsafe_allow_html=True)
kpi5_text = st.markdown("0")
with kpi6:
st.markdown("""<h5 style="color:black;">
Memory Usage</h5>""",
unsafe_allow_html=True)
kpi6_text = st.markdown("0")
detect(weights=weights,
source=video.name,
stframe=stframe,
kpi5_text=kpi5_text,
kpi6_text = kpi6_text,
conf_thres=float(conf_thres),
device="cpu",
classes=0,nosave=nosave,
display_labels=display_labels)
inference_msg.success("Inference Complete!")
# ------------------------- LOCAL VIDEO ------------------------
if input_source == "WebCam":
if st.sidebar.button("Start Tracking"):
stframe = st.empty()
st.markdown("""<h4 style="color:black;">
Memory Overall Statistics</h4>""",
unsafe_allow_html=True)
kpi5, kpi6 = st.columns(2)
with kpi5:
st.markdown("""<h5 style="color:black;">
CPU Utilization</h5>""",
unsafe_allow_html=True)
kpi5_text = st.markdown("0")
with kpi6:
st.markdown("""<h5 style="color:black;">
Memory Usage</h5>""",
unsafe_allow_html=True)
kpi6_text = st.markdown("0")
detect(weights=weights,
source="0",
stframe=stframe,
kpi5_text=kpi5_text,
kpi6_text = kpi6_text,
conf_thres=float(conf_thres),
device="cpu",
classes=0,nosave=nosave,
display_labels=display_labels)
inference_msg.success("Inference Complete!")
# --------------------------------------------------------------
torch.cuda.empty_cache()
# --------------------------------------------------------------
# --------------------MAIN FUNCTION CODE------------------------
if __name__ == "__main__":
try:
main()
except SystemExit:
pass
# ------------------------------------------------------------------