Spaces:
Runtime error
Runtime error
File size: 1,309 Bytes
d1ce89d 3f97687 d1ce89d |
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 |
import gradio as gr
get_video_data = """async (video, video_data_dummy) => {
const videoEl = document.querySelector("#video_in video");
if (!videoEl){
return [video, {}]
}
const metadata = {
duration: videoEl.duration,
currentTime: videoEl.currentTime,
isPaused: videoEl.paused,
hasEnded: videoEl.ended,
volume: videoEl.volume,
isMuted: videoEl.muted,
playbackRate: videoEl.playbackRate,
videoWidth: videoEl.videoWidth,
videoHeight: videoEl.videoHeight,
readyState: videoEl.readyState,
bufferedTimeRanges: Array.from(
{ length: videoEl.buffered.length },
(v, i) => ({
start: videoEl.buffered.start(i),
end: videoEl.buffered.end(i),
})
),
};
console.log(metadata);
return [video, metadata];
}"""
def predict(video, video_data):
timestamp = video_data["currentTime"]
return video_data
with gr.Blocks() as demo:
video_data_dummy = gr.JSON({}, visible=False)
with gr.Row():
with gr.Column():
video = gr.Video(elem_id="video_in")
with gr.Column():
timestamp = gr.JSON()
with gr.Row():
btn = gr.Button(value="Run")
btn.click(
predict, inputs=[video, video_data_dummy], outputs=[timestamp], _js=get_video_data
)
demo.launch()
|