-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathstreamlit.py
145 lines (127 loc) · 4.48 KB
/
streamlit.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
import tempfile
import streamlit as st
import pandas as pd
import cv2
from PIL import Image, ImageEnhance
import numpy as np
import os
#import tensorflow as tf
#import tensorflow_hub as hub
import time ,sys
import urllib.request
import urllib
import cv2
import numpy as np
import time
import sys
from demp import*
def main():
st.title("Object Detection using Intel")
st.sidebar.title("Settings")
st.sidebar.subheader("Parameters")
st.markdown(
"""
<style>
[data-testid="stSiderbar"][aria-expanded="true]>div:first-child{
width:300px;
}
[data-testid="stSiderbar"][aria-expanded="true]>div:first-child{
width:300px;
margin-left:-300px;
}
</style>
""",
unsafe_allow_html=True
)
app_model=st.sidebar.selectbox("Choose the App Model",['About App','Run on Image','Run on Video','Run on WenCam'])
if app_model=='About App':
st.markdown('In this project we are using intel model to do Object Detection on Videos using Streamlit')
st.markdown(
"""
<style>
[data-testid="stSiderbar"][aria-expanded="true]>div:first-child{
width:300px;
}
[data-testid="stSiderbar"][aria-expanded="true]>div:first-child{
width:300px;
margin-left:-300px;
}
</style>
""",
unsafe_allow_html=True
)
elif app_model=="Run on WenCam":
stframe5=st.empty()
run_object_web(stframe5,source=0, flip=True, use_popup=False)
elif app_model=="Run on Image" :
img_file_buffer=st.sidebar.file_uploader("Upload an image",type=["jpg","jpeg","png"])
DEMO_IMAGE="D:\\autonomous vechicle\\traffic.jpg"
if img_file_buffer is not None:
img=cv2.imread(img_file_buffer)
image=np.array(Image.open(img_file_buffer))
st.sidebar.text('Original Image')
st.sidebar.image(image)
stframe5=st.empty()
run_on_image(img_file_buffer,stframe5)
else:
img=cv2.imread(DEMO_IMAGE)
image=np.array(Image.open(DEMO_IMAGE))
st.sidebar.text('Original Image')
st.sidebar.image(image)
stframe5=st.empty()
run_on_image(img_file_buffer,stframe5)
elif app_model=="Run on Video":
#confidence=st.sidebar.slider('Confidence',min_value=0.0,max_value=1.0)
st.markdown(
"""
<style>
[data-testid="stSiderbar"][aria-expanded="true]>div:first-child{
width:300px;
}
[data-testid="stSiderbar"][aria-expanded="true]>div:first-child{
width:300px;
margin-left:-300px;
}
</style>
""",
unsafe_allow_html=True
)
st.sidebar.markdown('---')
video_file_buffer=st.sidebar.file_uploader("Upload the video",type=["mp4","avi","mov","asf"])
DEMO_VIDEO='D:\\autonomous vechicle\\Los Angeles 4K - California Glow - Scenic Drive - 2160.mp4'
#tffile=tempfile.NamedTemporaryFile(suffix='.mp4',delete=False)
#tffile.write(video_file_buffer.read())
demo_vid=open(DEMO_VIDEO,'rb')
demo_bytes=demo_vid.read()
st.sidebar.text("Input video")
st.sidebar.video(demo_bytes)
tffile=tempfile.NamedTemporaryFile(suffix=".mp4",delete=False)
tffile.name=DEMO_VIDEO
#tffile.write(video_file_buffer.read())
stframe=st.empty()
st.markdown("<hr/>",unsafe_allow_html=True)
kpi1,kpi2=st.columns(2)
with kpi1:
st.markdown("INFERENCE TIME")
kpi1_text=st.markdown("0")
with kpi2:
st.markdown("FPS")
kpi2_text=st.markdown("0")
st.markdown("<hr/>",unsafe_allow_html=True)
stframe2=st.empty()
stframe3=st.empty()
kpi3,kpi4=st.columns(2)
with kpi3:
st.markdown("INFERENCE TIME")
kpi3_text=st.markdown("0")
with kpi4:
st.markdown("FPS")
kpi4_text=st.markdown("0")
stframe4=st.empty()
run_object_detection(tffile.name,stframe,stframe2,kpi1_text,kpi2_text,flip=True, use_popup=False)
#run_object_detection_yolo(DEMO_VIDEO,stframe3,stframe4,kpi3_text,kpi4_text)
if __name__=='__main__':
try:
main()
except SystemExit:
pass