awacke1 commited on
Commit
10dd95d
·
1 Parent(s): 4ddb6bc

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +74 -0
app.py ADDED
@@ -0,0 +1,74 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ import os
3
+ import streamlit as st
4
+
5
+ # These are the formats supported in Streamlit right now.
6
+ VIDEO_EXTENSIONS = ["mp4", "ogv", "m4v", "webm"]
7
+
8
+ # For sample video files, try the Internet Archive, or download a few samples here:
9
+ # http://techslides.com/sample-webm-ogg-and-mp4-video-files-for-html5
10
+
11
+
12
+ st.title("Video Widget Examples")
13
+
14
+ st.header("Local video files")
15
+ st.write(
16
+ "You can use st.video to play a locally-stored video by supplying it with a valid filesystem path."
17
+ )
18
+
19
+
20
+ def get_video_files_in_dir(directory):
21
+ out = []
22
+ for item in os.listdir(directory):
23
+ try:
24
+ name, ext = item.split(".")
25
+ except:
26
+ continue
27
+ if name and ext:
28
+ if ext in VIDEO_EXTENSIONS:
29
+ out.append(item)
30
+ return out
31
+
32
+
33
+ avdir = os.path.expanduser("~")
34
+ files = get_video_files_in_dir(avdir)
35
+
36
+ if len(files) == 0:
37
+ st.write(
38
+ "Put some video files in your home directory (%s) to activate this player."
39
+ % avdir
40
+ )
41
+
42
+ else:
43
+ filename = st.selectbox(
44
+ "Select a video file from your home directory (%s) to play" % avdir,
45
+ files,
46
+ 0,
47
+ )
48
+
49
+ st.video(os.path.join(avdir, filename))
50
+ st.header("Remote video playback")
51
+ st.write("st.video allows a variety of HTML5 supported video links, including YouTube.")
52
+
53
+
54
+ def shorten_vid_option(opt):
55
+ return opt.split("/")[-1]
56
+
57
+
58
+ # A random sampling of videos found around the web. We should replace
59
+ # these with those sourced from the streamlit community if possible!
60
+ vidurl = st.selectbox(
61
+ "Pick a video to play",
62
+ (
63
+ "https://youtu.be/_T8LGqJtuGc",
64
+ "https://www.youtube.com/watch?v=kmfC-i9WgH0",
65
+ "https://www.youtube.com/embed/sSn4e1lLVpA",
66
+ "http://www.rochikahn.com/video/videos/zapatillas.mp4",
67
+ "http://www.marmosetcare.com/video/in-the-wild/intro.webm",
68
+ "https://www.orthopedicone.com/u/home-vid-4.mp4",
69
+ ),
70
+ 0,
71
+ shorten_vid_option,
72
+ )
73
+
74
+ st.video(vidurl)