alexrods commited on
Commit
fafde43
·
1 Parent(s): 250c6f0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +33 -43
app.py CHANGED
@@ -1,52 +1,42 @@
1
- # import tempfile
2
- # import streamlit as st
3
- import gradio as gr
4
  from prediction import smartcities
5
 
6
- # # Streamlit Interface
7
- # st.header("Smart City Cars and Bikes detection")
8
- # st.markdown("Upload a video or select the example")
9
 
10
- # ## Select video to inference
11
- # file_video = str
12
 
13
- # f = st.file_uploader(" Upload a video ", type=["mp4"])
14
- # if f is not None:
15
- # tfile = tempfile.NamedTemporaryFile(delete=False)
16
- # tfile.write(f.read())
17
- # file_video = tfile.name
18
 
19
- # if st.button("example"):
20
- # file_video = "test_video.mp4"
21
 
22
- # ## Process video
23
- # if file_video is not None:
24
- # sc = smartcities()
25
- # output = sc.predict(file_video)
26
- # col1, col2 = st.columns(2)
27
-
28
- # if output is not None:
29
- # with col1:
30
- # st.subheader("Input: ")
31
- # # video = open(file_video, "wb")
32
- # # video_bytes = video.read()
33
- # # st.video(video, format="video/mp4")
34
- # # st.video(video_bytes)
35
- # with col2:
36
- # st.subheader("Output: ")
37
- # output_video = open(output, "rb")
38
- # output_bytes = output_video.read()
39
- # st.video(output_bytes, format="video/mp4")
40
- # st.download_button("Download", output_bytes, file_name="output_video.mp4", mime="video/mp4")
41
- def object_detection(input):
42
  sc = smartcities()
43
- output = sc.predict(input)
44
-
45
- demo = gr.Interface.load(object_detection, input="video", output="video")
46
- demo.launch()
47
-
48
-
49
-
50
-
 
 
 
 
 
 
 
 
51
 
52
 
 
1
+ import cv2
2
+ import tempfile
3
+ import streamlit as st
4
  from prediction import smartcities
5
 
6
+ # Streamlit Interface
7
+ st.header("Smart City Cars and Bikes detection")
8
+ st.markdown("Upload a video or select the example")
9
 
10
+ ## Select video to inference
11
+ file_video = str
12
 
13
+ f = st.file_uploader(" Upload a video ", type=["mp4"])
14
+ if f is not None:
15
+ tfile = tempfile.NamedTemporaryFile(delete=False)
16
+ tfile.write(f.read())
17
+ file_video = tfile.name
18
 
19
+ if st.button("example"):
20
+ file_video = "test_video.mp4"
21
 
22
+ ## Process video
23
+ if file_video is not None:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
24
  sc = smartcities()
25
+ output = sc.predict(file_video)
26
+
27
+ col1, col2 = st.columns(2)
28
+ if output is not None:
29
+ with col1:
30
+ st.subheader("Input: ")
31
+ video = open(file_video, "rb")
32
+ video_bytes = video.read()
33
+ st.video(video_bytes, format="video/mp4")
34
+ # st.video(video_bytes)
35
+ with col2:
36
+ st.subheader("Output: ")
37
+ output_video = open(output, "rb")
38
+ output_bytes = output_video.read()
39
+ st.video(output_bytes, format="video/mp4")
40
+ st.download_button("Download", output_bytes, file_name="output_video.mp4", mime="video/mp4")
41
 
42