Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,12 +1,12 @@
|
|
1 |
import torch
|
2 |
-
|
3 |
# General
|
4 |
import os
|
5 |
from os.path import join as opj
|
6 |
import argparse
|
7 |
import datetime
|
8 |
from pathlib import Path
|
9 |
-
|
10 |
import gradio as gr
|
11 |
import tempfile
|
12 |
import yaml
|
@@ -59,7 +59,7 @@ msxl_model = init_v2v_model(cfg_v2v, devices[3])
|
|
59 |
# -------------------------
|
60 |
# ----- Functionality -----
|
61 |
# -------------------------
|
62 |
-
|
63 |
def generate(prompt, num_frames, image, model_name_stage1, model_name_stage2, seed, t, image_guidance, where_to_log=result_fol):
|
64 |
now = datetime.datetime.now()
|
65 |
name = prompt[:100].replace(" ", "_") + "_" + str(now.time()).replace(":", "_").replace(".", "_")
|
@@ -89,7 +89,7 @@ def generate(prompt, num_frames, image, model_name_stage1, model_name_stage2, se
|
|
89 |
video_path = opj(where_to_log, name+".mp4")
|
90 |
return video_path
|
91 |
|
92 |
-
|
93 |
def enhance(prompt, input_to_enhance, num_frames=None, image=None, model_name_stage1=None, model_name_stage2=None, seed=33, t=50, image_guidance=9.5, result_fol=result_fol):
|
94 |
if input_to_enhance is None:
|
95 |
input_to_enhance = generate(prompt, num_frames, image, model_name_stage1, model_name_stage2, seed, t, image_guidance)
|
@@ -105,26 +105,27 @@ def change_visibility(value):
|
|
105 |
return gr.Image(label='Image Prompt (first select Image-to-Video model from advanced options to enable image upload)', show_label=True, scale=1, show_download_button=False, interactive=False, value=None)
|
106 |
|
107 |
|
|
|
108 |
examples_1 = [
|
109 |
["Experience the dance of jellyfish: float through mesmerizing swarms of jellyfish, pulsating with otherworldly grace and beauty.",
|
110 |
-
|
111 |
["People dancing in room filled with fog and colorful lights.",
|
112 |
-
|
113 |
["Discover the secret language of bees: delve into the complex communication system that allows bees to coordinate their actions and navigate the world.",
|
114 |
-
|
115 |
["sunset, orange sky, warm lighting, fishing boats, ocean waves seagulls, rippling water, wharf, silhouette, serene atmosphere, dusk, evening glow, coastal landscape, seaside scenery.",
|
116 |
-
|
117 |
["Dive into the depths of the ocean: explore vibrant coral reefs, mysterious underwater caves, and the mesmerizing creatures that call the sea home.",
|
118 |
-
|
119 |
["Ants, beetles and centipede nest.",
|
120 |
-
|
121 |
]
|
122 |
|
123 |
examples_2 = [
|
124 |
["Fishes swimming in ocean camera moving, cinematic.",
|
125 |
-
|
126 |
["A squirrel on a table full of big nuts.",
|
127 |
-
|
128 |
]
|
129 |
|
130 |
# --------------------------
|
@@ -215,6 +216,8 @@ with gr.Blocks() as demo:
|
|
215 |
|
216 |
inputs_v2v = [prompt_stage1, video_stage1, num_frames, image_stage1, model_name_stage1, model_name_stage2, seed, t, image_guidance]
|
217 |
|
|
|
|
|
218 |
gr.HTML("""
|
219 |
<h2>
|
220 |
You can check the inference time for different number of frames
|
@@ -225,21 +228,21 @@ with gr.Blocks() as demo:
|
|
225 |
""")
|
226 |
|
227 |
gr.Examples(examples=examples_1,
|
228 |
-
inputs=
|
229 |
-
|
230 |
-
|
231 |
-
|
232 |
-
|
233 |
)
|
234 |
|
235 |
gr.Examples(examples=examples_2,
|
236 |
-
inputs=
|
237 |
-
|
238 |
-
|
239 |
-
|
240 |
-
|
241 |
-
|
242 |
-
|
243 |
)
|
244 |
|
245 |
run_button_stage2.click(fn=enhance, inputs=inputs_v2v, outputs=video_stage2,)
|
|
|
1 |
import torch
|
2 |
+
torch.jit.script = lambda f: f
|
3 |
# General
|
4 |
import os
|
5 |
from os.path import join as opj
|
6 |
import argparse
|
7 |
import datetime
|
8 |
from pathlib import Path
|
9 |
+
import spaces
|
10 |
import gradio as gr
|
11 |
import tempfile
|
12 |
import yaml
|
|
|
59 |
# -------------------------
|
60 |
# ----- Functionality -----
|
61 |
# -------------------------
|
62 |
+
@spaces.GPU(duration=120)
|
63 |
def generate(prompt, num_frames, image, model_name_stage1, model_name_stage2, seed, t, image_guidance, where_to_log=result_fol):
|
64 |
now = datetime.datetime.now()
|
65 |
name = prompt[:100].replace(" ", "_") + "_" + str(now.time()).replace(":", "_").replace(".", "_")
|
|
|
89 |
video_path = opj(where_to_log, name+".mp4")
|
90 |
return video_path
|
91 |
|
92 |
+
@spaces.GPU(duration=400)
|
93 |
def enhance(prompt, input_to_enhance, num_frames=None, image=None, model_name_stage1=None, model_name_stage2=None, seed=33, t=50, image_guidance=9.5, result_fol=result_fol):
|
94 |
if input_to_enhance is None:
|
95 |
input_to_enhance = generate(prompt, num_frames, image, model_name_stage1, model_name_stage2, seed, t, image_guidance)
|
|
|
105 |
return gr.Image(label='Image Prompt (first select Image-to-Video model from advanced options to enable image upload)', show_label=True, scale=1, show_download_button=False, interactive=False, value=None)
|
106 |
|
107 |
|
108 |
+
# [prompt_stage1, video_stage2, num_frames, image_stage1, model_name_stage1, seed, t, image_guidance]
|
109 |
examples_1 = [
|
110 |
["Experience the dance of jellyfish: float through mesmerizing swarms of jellyfish, pulsating with otherworldly grace and beauty.",
|
111 |
+
"__assets__/examples/t2v/1.mp4", "56 - frames", None, "ModelScopeT2V (text to video)", 33, 50, 9.0],
|
112 |
["People dancing in room filled with fog and colorful lights.",
|
113 |
+
"__assets__/examples/t2v/2.mp4", "56 - frames", None, "ModelScopeT2V (text to video)", 33, 50, 9.0],
|
114 |
["Discover the secret language of bees: delve into the complex communication system that allows bees to coordinate their actions and navigate the world.",
|
115 |
+
"__assets__/examples/t2v/3.mp4", "56 - frames", None, "AnimateDiff (text to video)", 33, 50, 9.0],
|
116 |
["sunset, orange sky, warm lighting, fishing boats, ocean waves seagulls, rippling water, wharf, silhouette, serene atmosphere, dusk, evening glow, coastal landscape, seaside scenery.",
|
117 |
+
"__assets__/examples/t2v/4.mp4", "56 - frames", None, "AnimateDiff (text to video)", 33, 50, 9.0],
|
118 |
["Dive into the depths of the ocean: explore vibrant coral reefs, mysterious underwater caves, and the mesmerizing creatures that call the sea home.",
|
119 |
+
"__assets__/examples/t2v/5.mp4", "56 - frames", None, "SVD (image to video)", 33, 50, 9.0],
|
120 |
["Ants, beetles and centipede nest.",
|
121 |
+
"__assets__/examples/t2v/6.mp4", "56 - frames", None, "SVD (image to video)", 33, 50, 9.0],
|
122 |
]
|
123 |
|
124 |
examples_2 = [
|
125 |
["Fishes swimming in ocean camera moving, cinematic.",
|
126 |
+
"__assets__/examples/i2v/1.mp4", "56 - frames", "__assets__/fish.jpg", "SVD (image to video)", 33, 50, 9.0],
|
127 |
["A squirrel on a table full of big nuts.",
|
128 |
+
"__assets__/examples/i2v/2.mp4", "56 - frames", "__assets__/squirrel.jpg", "SVD (image to video)", 33, 50, 9.0],
|
129 |
]
|
130 |
|
131 |
# --------------------------
|
|
|
216 |
|
217 |
inputs_v2v = [prompt_stage1, video_stage1, num_frames, image_stage1, model_name_stage1, model_name_stage2, seed, t, image_guidance]
|
218 |
|
219 |
+
inputs_examples = [prompt_stage1, video_stage2, num_frames, image_stage1, model_name_stage1, seed, t, image_guidance]
|
220 |
+
|
221 |
gr.HTML("""
|
222 |
<h2>
|
223 |
You can check the inference time for different number of frames
|
|
|
228 |
""")
|
229 |
|
230 |
gr.Examples(examples=examples_1,
|
231 |
+
inputs=inputs_examples,
|
232 |
+
# outputs=[video_stage2],
|
233 |
+
# fn=enhance,
|
234 |
+
# run_on_click=False,
|
235 |
+
# cache_examples=False,
|
236 |
)
|
237 |
|
238 |
gr.Examples(examples=examples_2,
|
239 |
+
inputs=inputs_examples,
|
240 |
+
# outputs=[video_stage2],
|
241 |
+
# fn=enhance,
|
242 |
+
# run_on_click=False,
|
243 |
+
# cache_examples=False,
|
244 |
+
# # preprocess=False,
|
245 |
+
# # postprocess=True,
|
246 |
)
|
247 |
|
248 |
run_button_stage2.click(fn=enhance, inputs=inputs_v2v, outputs=video_stage2,)
|