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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import os
|
3 |
+
|
4 |
+
css = """
|
5 |
+
<style>
|
6 |
+
body, html {
|
7 |
+
margin: 0;
|
8 |
+
padding: 0;
|
9 |
+
font-family: 'Helvetica Neue', Arial, sans-serif;
|
10 |
+
background-color: #121212; /* Dark background for the body */
|
11 |
+
color: #e0e0e0; /* Light grey text for better readability */
|
12 |
+
height: 100%;
|
13 |
+
width: 100%;
|
14 |
+
}
|
15 |
+
|
16 |
+
.gr-prose h2 {
|
17 |
+
color: #ffffff !important; /* This ensures that the color is white */
|
18 |
+
}
|
19 |
+
|
20 |
+
.gr-prose a {
|
21 |
+
color: #ffffff !important; /* This ensures that the color is white */
|
22 |
+
}
|
23 |
+
|
24 |
+
|
25 |
+
div {
|
26 |
+
background-color: #121212; /* Slightly lighter dark shade for div backgrounds */
|
27 |
+
color: #e0e0e0; /* Light grey text color for readability */
|
28 |
+
}
|
29 |
+
|
30 |
+
.gallery-container {
|
31 |
+
display: flex;
|
32 |
+
flex-direction: column;
|
33 |
+
align-items: center;
|
34 |
+
justify-content: flex-start;
|
35 |
+
min-height: 100vh;
|
36 |
+
padding: 2rem;
|
37 |
+
box-sizing: border-box;
|
38 |
+
}
|
39 |
+
|
40 |
+
.video-container {
|
41 |
+
display: grid;
|
42 |
+
grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
|
43 |
+
gap: 1rem;
|
44 |
+
padding: 1rem;
|
45 |
+
width: 100%;
|
46 |
+
max-width: 1200px;
|
47 |
+
}
|
48 |
+
|
49 |
+
.video-item {
|
50 |
+
padding-top: 0;
|
51 |
+
margin-bottom: 1rem;
|
52 |
+
}
|
53 |
+
|
54 |
+
.video-item video {
|
55 |
+
width: 100%;
|
56 |
+
display: block;
|
57 |
+
border-radius: 8px;
|
58 |
+
}
|
59 |
+
|
60 |
+
.video-caption {
|
61 |
+
color: #ffffff; /* Maintain white text for captions */
|
62 |
+
padding: 0.5rem;
|
63 |
+
border-radius: 4px;
|
64 |
+
margin-top: 0.5rem;
|
65 |
+
font-size: 0.9rem;
|
66 |
+
display: block;
|
67 |
+
width: auto;
|
68 |
+
}
|
69 |
+
|
70 |
+
.nav-buttons {
|
71 |
+
display: flex;
|
72 |
+
justify-content: center;
|
73 |
+
gap: 1rem;
|
74 |
+
margin-top: 1rem;
|
75 |
+
}
|
76 |
+
|
77 |
+
.button {
|
78 |
+
background-color: #333333; /* Dark grey button background */
|
79 |
+
color: #ffffff; /* White text on buttons for visibility */
|
80 |
+
border: none;
|
81 |
+
padding: 0.5rem 1rem;
|
82 |
+
border-radius: 0.3rem;
|
83 |
+
cursor: pointer;
|
84 |
+
transition: background 0.2s ease-in-out;
|
85 |
+
}
|
86 |
+
|
87 |
+
.gr-button {
|
88 |
+
background-color: #e5e7eb !important;
|
89 |
+
}
|
90 |
+
|
91 |
+
.button:hover {
|
92 |
+
background-color: #4f4f4f; /* Lighter grey on hover for visibility */
|
93 |
+
}
|
94 |
+
|
95 |
+
.slider {
|
96 |
+
background-color: #333333; /* Slider background */
|
97 |
+
border-radius: 0.3rem;
|
98 |
+
margin: 1rem 0;
|
99 |
+
}
|
100 |
+
|
101 |
+
.slider input[type="range"] {
|
102 |
+
width: 100%;
|
103 |
+
}
|
104 |
+
|
105 |
+
a, a:visited {
|
106 |
+
color: #76a9ff; /* Blue accent color for links for visibility */
|
107 |
+
text-decoration: none;
|
108 |
+
}
|
109 |
+
|
110 |
+
a:hover {
|
111 |
+
color: #a4c2ff; /* Lighter blue on hover for visibility */
|
112 |
+
}
|
113 |
+
|
114 |
+
input[type="text"], select, textarea {
|
115 |
+
background-color: #333333; /* Dark grey input background for contrast */
|
116 |
+
color: #ffffff; /* White text for inputs */
|
117 |
+
border: 1px solid #343434; /* Subtle border color */
|
118 |
+
border-radius: 0.3rem;
|
119 |
+
padding: 0.5rem;
|
120 |
+
}
|
121 |
+
|
122 |
+
input[type="text"]:focus, select:focus, textarea:focus {
|
123 |
+
outline: none;
|
124 |
+
border-color: #76a9ff; /* Blue border color for focus */
|
125 |
+
}
|
126 |
+
|
127 |
+
/* Additional global styles can go here */
|
128 |
+
|
129 |
+
</style>
|
130 |
+
"""
|
131 |
+
|
132 |
+
# @keyframes animatedGradient {
|
133 |
+
# 0% { background-position: 0% 50%; }
|
134 |
+
# 50% { background-position: 100% 50%; }
|
135 |
+
# 100% { background-position: 0% 50%; }
|
136 |
+
# }
|
137 |
+
|
138 |
+
# .video-item {
|
139 |
+
# /* ... other styles ... */
|
140 |
+
# background: linear-gradient(270deg, #6a6a6a, #373737, #2d2d2d, #373737);
|
141 |
+
# background-size: 800% 800%;
|
142 |
+
# animation: animatedGradient 15s ease infinite;
|
143 |
+
# }
|
144 |
+
|
145 |
+
# JavaScript function to load the motion backgrounds
|
146 |
+
js = """
|
147 |
+
<script>
|
148 |
+
function addMotionBackgrounds() {
|
149 |
+
// Select all video containers
|
150 |
+
var containers = document.querySelectorAll('.video-container');
|
151 |
+
|
152 |
+
containers.forEach(container => {
|
153 |
+
// Create a div for the background
|
154 |
+
var background = document.createElement('div');
|
155 |
+
background.className = 'video-background';
|
156 |
+
|
157 |
+
// Append the background div to the container
|
158 |
+
container.appendChild(background);
|
159 |
+
});
|
160 |
+
}
|
161 |
+
// Call the function to add motion backgrounds
|
162 |
+
window.onload = addMotionBackgrounds;
|
163 |
+
</script>
|
164 |
+
"""
|
165 |
+
# def showcase(page_num):
|
166 |
+
# videos_per_page = 3
|
167 |
+
# start_index = (page_num - 1) * videos_per_page
|
168 |
+
# end_index = start_index + videos_per_page
|
169 |
+
# video_html = "<center>" # Centering the content
|
170 |
+
|
171 |
+
# for i in range(start_index, end_index):
|
172 |
+
# video_name = f"{i:04d}.mp4"
|
173 |
+
# caption_name = f"{i:04d}.txt"
|
174 |
+
# video_html += "<div style='margin-bottom: 20px;'>"
|
175 |
+
|
176 |
+
# for category in ['gen2', 'floor33', 'pika']:
|
177 |
+
# video_url = f"http://localhost:8000/{category}/{video_name}"
|
178 |
+
# caption_path = os.path.join('prompts', caption_name) # Path to the caption file
|
179 |
+
# if os.path.exists(os.path.join('static', category, video_name)): # Check if video file exists
|
180 |
+
# caption_text = ""
|
181 |
+
# if os.path.exists(caption_path): # Check if caption file exists and read it
|
182 |
+
# with open(caption_path, 'r') as file:
|
183 |
+
# caption_text = file.read().strip()
|
184 |
+
|
185 |
+
# video_html += f"""
|
186 |
+
# <div style="display: inline-block; margin-right: 10px; text-align: left;">
|
187 |
+
# <video width='480' height='360' controls>
|
188 |
+
# <source src="{video_url}" type="video/mp4">
|
189 |
+
# Your browser does not support the video tag.
|
190 |
+
# </video>
|
191 |
+
# <p style="font-size: 16px; font-weight: bold;">{category}/{video_name}</p>
|
192 |
+
# <p style="font-size: 14px; margin-top: 5px; color: #666;">{caption_text}</p> <!-- Caption text -->
|
193 |
+
# </div>
|
194 |
+
# """
|
195 |
+
|
196 |
+
# video_html += "</div>"
|
197 |
+
# # video_html += "</center>"
|
198 |
+
# return video_html
|
199 |
+
|
200 |
+
def showcase(page_num):
|
201 |
+
videos_per_page = 1
|
202 |
+
start_index = (page_num - 1) * videos_per_page
|
203 |
+
end_index = start_index + videos_per_page
|
204 |
+
video_html = "<div class='gallery-container'>"
|
205 |
+
|
206 |
+
for i in range(start_index, end_index):
|
207 |
+
video_name = f"{i:04d}.mp4"
|
208 |
+
caption_name = f"{i:04d}.txt"
|
209 |
+
video_html += "<div class='video-container'>"
|
210 |
+
|
211 |
+
for category in [ 'VideoCrafter2','Pika','VideoCrafter1','VideoCrafter0.9','Pika1.0', 'Gen2-09.2023','Gen2-12.2023','HotShot','Lavie-Base','Lavie-Interpolation','ModelScope','MoonValley','Show1', 'ZeroScope']:
|
212 |
+
video_url = f"http://localhost:8000/{category}/{video_name}"
|
213 |
+
caption_path = os.path.join('prompts', caption_name)
|
214 |
+
if os.path.exists(os.path.join('static', category, video_name)):
|
215 |
+
caption_text = ""
|
216 |
+
if os.path.exists(caption_path):
|
217 |
+
with open(caption_path, 'r') as file:
|
218 |
+
caption_text = file.read().strip()
|
219 |
+
|
220 |
+
video_html += f"""
|
221 |
+
<div class='video-item'>
|
222 |
+
<video controls>
|
223 |
+
<source src="{video_url}" type="video/mp4">
|
224 |
+
Your browser does not support the video tag.
|
225 |
+
</video>
|
226 |
+
<p class='video-caption'>{category}: {caption_text}</p>
|
227 |
+
</div>
|
228 |
+
"""
|
229 |
+
|
230 |
+
video_html += "</div>"
|
231 |
+
video_html += "</div>"
|
232 |
+
return video_html
|
233 |
+
|
234 |
+
|
235 |
+
# Description and Acknowledgements
|
236 |
+
|
237 |
+
description_html = """
|
238 |
+
<div style="text-align: center; margin-bottom: 20px;">
|
239 |
+
<h2>EvalCrafter Text-to-Video (ECTV) Gallery 🎥📊</h2>
|
240 |
+
<p>
|
241 |
+
<a href="https://huggingface.co/datasets/RaphaelLiu/EvalCrafter_T2V_Dataset">Dataset</a> ·
|
242 |
+
<a href="https://github.com/EvalCrafter/EvalCrafter">Code</a> ·
|
243 |
+
<a href="http://evalcrafter.github.io">Project Page</a> ·
|
244 |
+
<a href="https://huggingface.co/spaces/AILab-CVC/EvalCrafter">Leaderboard</a> ·
|
245 |
+
<a href="https://arxiv.org/abs/2310.11440">Paper@ArXiv</a> ·
|
246 |
+
<a href="https://github.com/evalcrafter/EvalCrafter/blob/master/prompt700.txt">Prompt list</a></p>
|
247 |
+
<p>Welcome to the ECTV Gallery! This repository contains around 10000 videos generated by various methods using the Prompt list. These videos have been evaluated using the innovative EvalCrafter framework, which assesses generative models across visual, content, and motion qualities using 17 objective metrics and subjective user opinions.</p>
|
248 |
+
<!-- Add more details and acknowledgements as needed -->
|
249 |
+
</div>
|
250 |
+
"""
|
251 |
+
|
252 |
+
|
253 |
+
# def navigate(direction, page_num):
|
254 |
+
# if direction == "Beginning":
|
255 |
+
# page_num.value = 1
|
256 |
+
# elif direction == "Previous":
|
257 |
+
# page_num.value = max(1, page_num.value - 1)
|
258 |
+
# elif direction == "Next":
|
259 |
+
# page_num.value = min(total_pages, page_num.value + 1)
|
260 |
+
# elif direction == "End":
|
261 |
+
# page_num.value = total_pages
|
262 |
+
# # Assuming showcase is a function that returns HTML content based on page_num
|
263 |
+
# output_html_content = showcase(page_num.value)
|
264 |
+
# return page_num, output_html_content
|
265 |
+
|
266 |
+
def navigate(direction, current_page):
|
267 |
+
if direction == "Beginning":
|
268 |
+
return 1
|
269 |
+
elif direction == "Previous":
|
270 |
+
return max(1, current_page - 1)
|
271 |
+
elif direction == "Next":
|
272 |
+
return min(total_pages, current_page + 1)
|
273 |
+
elif direction == "End":
|
274 |
+
return total_pages
|
275 |
+
else:
|
276 |
+
# For direct navigation through the slider
|
277 |
+
return current_page
|
278 |
+
|
279 |
+
def navigate_to_page(page_num, page_slider):
|
280 |
+
# Directly navigate to the selected page from the slider
|
281 |
+
page_num.value = page_slider
|
282 |
+
return page_num, showcase(page_num)
|
283 |
+
|
284 |
+
|
285 |
+
# Define the total number of pages.
|
286 |
+
total_videos = 700
|
287 |
+
videos_per_page = 1
|
288 |
+
total_pages = (total_videos + videos_per_page - 1) // videos_per_page
|
289 |
+
|
290 |
+
with gr.Blocks(css=css) as app:
|
291 |
+
gr.Markdown(description_html)
|
292 |
+
gr.Markdown(js)
|
293 |
+
page_num = gr.Variable(value=1)
|
294 |
+
|
295 |
+
|
296 |
+
|
297 |
+
|
298 |
+
with gr.Row():
|
299 |
+
beginning_button = gr.Button("Beginning")
|
300 |
+
previous_button = gr.Button("Previous")
|
301 |
+
next_button = gr.Button("Next")
|
302 |
+
end_button = gr.Button("End")
|
303 |
+
page_slider = gr.Slider(minimum=1, maximum=total_pages, step=1, value=1, label="Go to page")
|
304 |
+
output_html = gr.HTML()
|
305 |
+
|
306 |
+
|
307 |
+
|
308 |
+
def update_output(direction):
|
309 |
+
# new_page_num = navigate(direction, page_num.value)
|
310 |
+
if isinstance(direction, int):
|
311 |
+
new_page_num = direction
|
312 |
+
else:
|
313 |
+
new_page_num = navigate(direction, page_num.value)
|
314 |
+
page_num.value = new_page_num
|
315 |
+
content = showcase(new_page_num)
|
316 |
+
return new_page_num, content
|
317 |
+
|
318 |
+
def initialization(start):
|
319 |
+
page_num.value = int(start)
|
320 |
+
return page_num.value, showcase(page_num.value)
|
321 |
+
|
322 |
+
app.load(fn=lambda: initialization('1'), inputs=None, outputs=[page_slider, output_html])
|
323 |
+
|
324 |
+
|
325 |
+
beginning_button.click(fn=lambda: update_output("Beginning"), inputs=None, outputs=[page_slider, output_html])
|
326 |
+
previous_button.click(fn=lambda: update_output("Previous"), inputs=None, outputs=[page_slider, output_html])
|
327 |
+
next_button.click(fn=lambda: update_output("Next"), inputs=None, outputs=[page_slider, output_html])
|
328 |
+
end_button.click(fn=lambda: update_output("End"), inputs=None, outputs=[page_slider, output_html])
|
329 |
+
page_slider.change(fn=lambda x: update_output(x), inputs=page_slider, outputs=[page_slider, output_html])
|
330 |
+
|
331 |
+
# Initialize the display for the first page
|
332 |
+
output_html.update(value=showcase(page_num.value))
|
333 |
+
|
334 |
+
app.launch(share=True)
|