-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathyoutube.py
68 lines (53 loc) · 1.75 KB
/
youtube.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
import streamlit as st
import warnings
try:
from streamlit_terran_timeline import terran_timeline, generate_timeline
except ImportError:
warnings.warn(
"Failed to load terran_timeline from streamlit_terran_timeline. "
"Please run 'pip install streamlit_terran_timeline' or "
"'pip install .' if working locally"
)
exit(1)
st.header("Face-recognition interactive-timeline generator")
st.write(
"In this demo we show you how easy it is to create an interactive"
"timeline chart of faces detected on videos. Thanksfully, there's an open "
"source project called Terran that makes all this process super super easy!"
)
st.write("More descriptions here")
st.subheader("Loading your video")
st.write(
"You can select videos from **multiple sources**: "
"YouTube and almost any video streaming platform, or any local file"
)
#
# Ask the user to input a video link or path and show the video below
#
video_path = st.text_input(
"Link or path to video", "https://www.youtube.com/watch?v=v2VgA_MCNDg"
)
#
# Show the actual faces timeline chart
#
st.subheader("Faces timeline chart")
st.write("")
@st.cache(persist=True, ttl=86_400, suppress_st_warning=True, show_spinner=False)
def _generate_timeline(video_path):
timeline = generate_timeline(
video_src=video_path,
appearence_threshold=5,
batch_size=32,
duration=None,
framerate=8,
output_directory="timelines",
ref_directory=None,
similarity_threshold=0.75,
start_time=0,
thumbnail_rate=1,
)
return timeline
with st.spinner("Generating timeline"):
timeline = _generate_timeline(video_path)
start_time = terran_timeline(timeline)
st.video(video_path, start_time=int(start_time))