Spaces:
Runtime error
Runtime error
Commit
·
72a2773
1
Parent(s):
5b4d914
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
|
| 3 |
+
import os
|
| 4 |
+
import streamlit as st
|
| 5 |
+
|
| 6 |
+
# These are the formats supported in Streamlit right now.
|
| 7 |
+
VIDEO_EXTENSIONS = ["mp4", "ogv", "m4v", "webm"]
|
| 8 |
+
|
| 9 |
+
# For sample video files, try the Internet Archive, or download a few samples here:
|
| 10 |
+
# http://techslides.com/sample-webm-ogg-and-mp4-video-files-for-html5
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
st.title("Video Player")
|
| 14 |
+
|
| 15 |
+
st.header("Local video files")
|
| 16 |
+
st.write(
|
| 17 |
+
"You can use st.video to play a locally-stored video by supplying it with a valid filesystem path."
|
| 18 |
+
)
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
def get_video_files_in_dir(directory):
|
| 22 |
+
out = []
|
| 23 |
+
for item in os.listdir(directory):
|
| 24 |
+
try:
|
| 25 |
+
name, ext = item.split(".")
|
| 26 |
+
except:
|
| 27 |
+
continue
|
| 28 |
+
if name and ext:
|
| 29 |
+
if ext in VIDEO_EXTENSIONS:
|
| 30 |
+
out.append(item)
|
| 31 |
+
return out
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
avdir = os.path.expanduser("~")
|
| 35 |
+
files = get_video_files_in_dir(avdir)
|
| 36 |
+
|
| 37 |
+
if len(files) == 0:
|
| 38 |
+
st.write(
|
| 39 |
+
"Put some video files in your home directory (%s) to activate this player."
|
| 40 |
+
% avdir
|
| 41 |
+
)
|
| 42 |
+
|
| 43 |
+
else:
|
| 44 |
+
filename = st.selectbox(
|
| 45 |
+
"Select a video file from your home directory (%s) to play" % avdir,
|
| 46 |
+
files,
|
| 47 |
+
0,
|
| 48 |
+
)
|
| 49 |
+
|
| 50 |
+
st.video(os.path.join(avdir, filename))
|
| 51 |
+
st.header("Remote video playback")
|
| 52 |
+
st.write("st.video allows a variety of HTML5 supported video links, including YouTube.")
|
| 53 |
+
|
| 54 |
+
|
| 55 |
+
def shorten_vid_option(opt):
|
| 56 |
+
return opt.split("/")[-1]
|
| 57 |
+
|
| 58 |
+
|
| 59 |
+
# A random sampling of videos found around the web. We should replace
|
| 60 |
+
# these with those sourced from the streamlit community if possible!
|
| 61 |
+
vidurl = st.selectbox(
|
| 62 |
+
"Pick a video to play",
|
| 63 |
+
(
|
| 64 |
+
"https://youtu.be/IoQsyHVFflU",
|
| 65 |
+
"https://youtu.be/ZT3_2X7Txu0?list=PLHgX2IExbFosM9aYef9-1ymyx3QNUw3w1",
|
| 66 |
+
"https://youtu.be/2N83yzUcomc?list=PLHgX2IExbFosM9aYef9-1ymyx3QNUw3w1",
|
| 67 |
+
"https://youtu.be/0i3U47OQs0E?list=PLHgX2IExbFosM9aYef9-1ymyx3QNUw3w1",
|
| 68 |
+
"https://youtu.be/L8ObyHp9PY0?list=PLHgX2IExbFosM9aYef9-1ymyx3QNUw3w1",
|
| 69 |
+
"https://youtu.be/x9vRg5KmLIo?list=PLHgX2IExbFosM9aYef9-1ymyx3QNUw3w1",
|
| 70 |
+
"https://youtu.be/ZEchaKXaaas?list=PLHgX2IExbFosM9aYef9-1ymyx3QNUw3w1",
|
| 71 |
+
"https://youtu.be/5yToL7ymfNo?list=PLHgX2IExbFosM9aYef9-1ymyx3QNUw3w1",
|
| 72 |
+
"https://youtu.be/N2hM3RYdyrE?list=PLHgX2IExbFosM9aYef9-1ymyx3QNUw3w1",
|
| 73 |
+
"https://youtu.be/Kd8OAVRyDc4?list=PLHgX2IExbFosM9aYef9-1ymyx3QNUw3w1",
|
| 74 |
+
"https://youtu.be/OsRBhgTxYPQ?list=PLHgX2IExbFosM9aYef9-1ymyx3QNUw3w1",
|
| 75 |
+
"https://youtu.be/V7rJ3eS1dHQ",
|
| 76 |
+
"https://youtu.be/w7EPhC1WEvE"
|
| 77 |
+
|
| 78 |
+
),
|
| 79 |
+
0,
|
| 80 |
+
shorten_vid_option,
|
| 81 |
+
)
|
| 82 |
+
|
| 83 |
+
st.video(vidurl)
|