radames commited on
Commit
d1ce89d
1 Parent(s): da77745

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +50 -0
app.py ADDED
@@ -0,0 +1,50 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+
3
+
4
+ get_video_data = """async (video, video_data_dummy) => {
5
+ const videoEl = document.querySelector("#video_in video");
6
+ if (!videoEl){
7
+ return [video, {}]
8
+ }
9
+ const metadata = {
10
+ duration: videoEl.duration,
11
+ currentTime: videoEl.currentTime,
12
+ isPaused: videoEl.paused,
13
+ hasEnded: videoEl.ended,
14
+ volume: videoEl.volume,
15
+ isMuted: videoEl.muted,
16
+ playbackRate: videoEl.playbackRate,
17
+ videoWidth: videoEl.videoWidth,
18
+ videoHeight: videoEl.videoHeight,
19
+ readyState: videoEl.readyState,
20
+ bufferedTimeRanges: Array.from(
21
+ { length: videoEl.buffered.length },
22
+ (v, i) => ({
23
+ start: videoEl.buffered.start(i),
24
+ end: videoEl.buffered.end(i),
25
+ })
26
+ ),
27
+ };
28
+ console.log(metadata);
29
+ return [video, metadata];
30
+ }"""
31
+
32
+
33
+ def predict(video, video_data):
34
+ timestamp = video_data["timestamp"]
35
+ return video_data
36
+
37
+
38
+ with gr.Blocks() as demo:
39
+ video_data_dummy = gr.JSON({}, visible=False)
40
+ with gr.Row():
41
+ with gr.Column():
42
+ video = gr.Video(elem_id="video_in")
43
+ with gr.Column():
44
+ timestamp = gr.JSON()
45
+ with gr.Row():
46
+ btn = gr.Button(value="Run")
47
+ btn.click(
48
+ predict, inputs=[video, video_data_dummy], outputs=[timestamp], _js=get_video_data
49
+ )
50
+ demo.launch()