benjamin-paine commited on
Commit
1231097
·
verified ·
1 Parent(s): 9139bdb

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +82 -0
app.py ADDED
@@ -0,0 +1,82 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import random
3
+ import gradio as gr
4
+ import datasets as ds
5
+
6
+ bench = ds.load_dataset(
7
+ "saiyan-world/Goku-MovieGenBench",
8
+ split="train"
9
+ )
10
+ bench = bench.cast_column("video", ds.Video(decode=False))
11
+ num_videos = len(bench)
12
+
13
+ with gr.Blocks() as demo:
14
+ header = gr.Markdown(
15
+ """
16
+ # Goku MovieGen Bench Video Explorer
17
+ Use this interface to view videos generated by [Goku](https://saiyan-world.github.io/goku/). For more information, see [Goku: Flow Based Video Generate Models on arXiv](https://arxiv.org/abs/2502.04896). """.strip()
18
+ )
19
+ video = gr.Video(
20
+ value=bench[0]["video"]["path"],
21
+ loop=True,
22
+ autoplay=True,
23
+ )
24
+
25
+ dropdown = gr.Dropdown(
26
+ label="Video",
27
+ choices=range(num_videos),
28
+ value=0
29
+ )
30
+
31
+ def set_video(new_id):
32
+ return gr.Video(
33
+ value=bench[new_id]["video"]["path"],
34
+ loop=True,
35
+ autoplay=True,
36
+ )
37
+
38
+ def decrement(current_id):
39
+ return gr.Dropdown(
40
+ label="Video",
41
+ choices=range(num_videos),
42
+ value=max(0, current_id-1)
43
+ )
44
+
45
+ def increment(current_id):
46
+ return gr.Dropdown(
47
+ label="Video",
48
+ choices=range(num_videos),
49
+ value=min(num_videos-1, current_id+1)
50
+ )
51
+
52
+ def random_video():
53
+ return gr.Dropdown(
54
+ label="Video",
55
+ choices=range(num_videos),
56
+ value=random.randint(0, num_videos-1)
57
+ )
58
+
59
+ with gr.Row():
60
+ go_previous = gr.Button("Previous")
61
+ go_previous.click(
62
+ fn=decrement,
63
+ inputs=dropdown,
64
+ outputs=dropdown,
65
+ )
66
+ go_next = gr.Button("Next")
67
+ go_next.click(
68
+ fn=increment,
69
+ inputs=dropdown,
70
+ outputs=dropdown
71
+ )
72
+ go_random = gr.Button("Random")
73
+ go_random.click(
74
+ fn=random_video,
75
+ outputs=dropdown,
76
+ )
77
+
78
+ dropdown.change(fn=set_video, inputs=dropdown, outputs=video)
79
+
80
+ demo.launch(
81
+ allowed_paths=[os.path.dirname(bench[0]["video"]["path"])]
82
+ )