Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -62,11 +62,13 @@ def generate(prompt, num_frames, image, model_name_stage1, model_name_stage2, se
|
|
62 |
name = prompt[:100].replace(" ", "_") + "_" + str(now.time()).replace(":", "_").replace(".", "_")
|
63 |
|
64 |
if num_frames == [] or num_frames is None:
|
65 |
-
num_frames =
|
66 |
else:
|
67 |
num_frames = int(num_frames.split(" ")[0])
|
|
|
|
|
68 |
|
69 |
-
n_autoreg_gen = num_frames//8
|
70 |
|
71 |
inference_generator = torch.Generator(device="cuda").manual_seed(seed)
|
72 |
|
@@ -75,6 +77,9 @@ def generate(prompt, num_frames, image, model_name_stage1, model_name_stage2, se
|
|
75 |
elif model_name_stage1 == "AnimateDiff (text to video)":
|
76 |
short_video = ad_short_gen(prompt, ad_model, inference_generator, t, device)
|
77 |
elif model_name_stage1 == "SVD (image to video)":
|
|
|
|
|
|
|
78 |
short_video = svd_short_gen(image, prompt, svd_model, sdxl_model, inference_generator, t, device)
|
79 |
|
80 |
stream_long_gen(prompt, short_video, n_autoreg_gen, seed, t, image_guidance, name, stream_cli, stream_model)
|
@@ -89,36 +94,32 @@ def enhance(prompt, input_to_enhance, num_frames=None, image=None, model_name_st
|
|
89 |
|
90 |
def change_visibility(value):
|
91 |
if value == "SVD (image to video)":
|
92 |
-
return gr.Image(label='Image Prompt (if not attached then SDXL will be used to generate the starting image)', show_label=True, scale=1, show_download_button=False, interactive=True,
|
93 |
else:
|
94 |
-
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,
|
95 |
|
96 |
|
97 |
-
|
98 |
-
["Camera moving in a wide bright ice cave.",
|
99 |
-
None, "24 - frames", None, "ModelScopeT2V (text to video)", "MS-Vid2Vid-XL", 33, 50, 9.0],
|
100 |
-
["Explore the coral gardens of the sea: witness the kaleidoscope of colors and shapes as coral reefs provide shelter for a myriad of marine life.",
|
101 |
-
None, "24 - frames", None, "ModelScopeT2V (text to video)", "MS-Vid2Vid-XL", 33, 50, 9.0],
|
102 |
["Experience the dance of jellyfish: float through mesmerizing swarms of jellyfish, pulsating with otherworldly grace and beauty.",
|
103 |
-
None, "
|
|
|
|
|
104 |
["Discover the secret language of bees: delve into the complex communication system that allows bees to coordinate their actions and navigate the world.",
|
105 |
-
None, "
|
106 |
-
["
|
107 |
-
None, "
|
108 |
-
["
|
109 |
-
None, "
|
110 |
-
["Fishes swimming in ocean camera moving, cinematic.",
|
111 |
-
None, "24 - frames", "__assets__/fish.jpg", "SVD (image to video)", "MS-Vid2Vid-XL", 33, 50, 9.0],
|
112 |
-
["A squirrel on a table full of big nuts.",
|
113 |
-
None, "24 - frames", "__assets__/squirrel.jpg", "SVD (image to video)", "MS-Vid2Vid-XL", 33, 50, 9.0],
|
114 |
["Ants, beetles and centipede nest.",
|
115 |
-
None, "
|
116 |
]
|
117 |
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
|
|
|
|
122 |
|
123 |
# --------------------------
|
124 |
# ----- Gradio-Demo UI -----
|
@@ -169,7 +170,7 @@ with gr.Blocks() as demo:
|
|
169 |
with gr.Row():
|
170 |
prompt_stage1 = gr.Textbox(label='Textual Prompt', placeholder="Ex: Dog running on the street.")
|
171 |
with gr.Row():
|
172 |
-
image_stage1 = 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
|
173 |
with gr.Column():
|
174 |
video_stage1 = gr.Video(label='Long Video Preview', show_label=True, interactive=False, scale=2, show_download_button=True)
|
175 |
with gr.Row():
|
@@ -207,14 +208,26 @@ with gr.Blocks() as demo:
|
|
207 |
|
208 |
inputs_v2v = [prompt_stage1, video_stage1, num_frames, image_stage1, model_name_stage1, model_name_stage2, seed, t, image_guidance]
|
209 |
|
210 |
-
|
211 |
-
|
212 |
-
|
213 |
-
|
214 |
-
|
215 |
-
|
216 |
-
|
217 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
218 |
run_button_stage2.click(fn=enhance, inputs=inputs_v2v, outputs=video_stage2,)
|
219 |
|
220 |
'''
|
@@ -245,5 +258,4 @@ if on_huggingspace:
|
|
245 |
demo.queue(max_size=20)
|
246 |
demo.launch(debug=True)
|
247 |
else:
|
248 |
-
|
249 |
-
print(link)
|
|
|
62 |
name = prompt[:100].replace(" ", "_") + "_" + str(now.time()).replace(":", "_").replace(".", "_")
|
63 |
|
64 |
if num_frames == [] or num_frames is None:
|
65 |
+
num_frames = 24
|
66 |
else:
|
67 |
num_frames = int(num_frames.split(" ")[0])
|
68 |
+
if num_frames > 56:
|
69 |
+
num_frames = 56
|
70 |
|
71 |
+
n_autoreg_gen = (num_frames-8)//8
|
72 |
|
73 |
inference_generator = torch.Generator(device="cuda").manual_seed(seed)
|
74 |
|
|
|
77 |
elif model_name_stage1 == "AnimateDiff (text to video)":
|
78 |
short_video = ad_short_gen(prompt, ad_model, inference_generator, t, device)
|
79 |
elif model_name_stage1 == "SVD (image to video)":
|
80 |
+
# For cached examples
|
81 |
+
if isinstance(image, dict):
|
82 |
+
image = image["path"]
|
83 |
short_video = svd_short_gen(image, prompt, svd_model, sdxl_model, inference_generator, t, device)
|
84 |
|
85 |
stream_long_gen(prompt, short_video, n_autoreg_gen, seed, t, image_guidance, name, stream_cli, stream_model)
|
|
|
94 |
|
95 |
def change_visibility(value):
|
96 |
if value == "SVD (image to video)":
|
97 |
+
return gr.Image(label='Image Prompt (if not attached then SDXL will be used to generate the starting image)', show_label=True, scale=1, show_download_button=False, interactive=True, value=None)
|
98 |
else:
|
99 |
+
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)
|
100 |
|
101 |
|
102 |
+
examples_1 = [
|
|
|
|
|
|
|
|
|
103 |
["Experience the dance of jellyfish: float through mesmerizing swarms of jellyfish, pulsating with otherworldly grace and beauty.",
|
104 |
+
None, "56 - frames", None, "ModelScopeT2V (text to video)", "MS-Vid2Vid-XL", 33, 50, 9.0],
|
105 |
+
["People dancing in room filled with fog and colorful lights.",
|
106 |
+
None, "56 - frames", None, "ModelScopeT2V (text to video)", "MS-Vid2Vid-XL", 33, 50, 9.0],
|
107 |
["Discover the secret language of bees: delve into the complex communication system that allows bees to coordinate their actions and navigate the world.",
|
108 |
+
None, "56 - frames", None, "AnimateDiff (text to video)", "MS-Vid2Vid-XL", 33, 50, 9.0],
|
109 |
+
["sunset, orange sky, warm lighting, fishing boats, ocean waves seagulls, rippling water, wharf, silhouette, serene atmosphere, dusk, evening glow, coastal landscape, seaside scenery.",
|
110 |
+
None, "56 - frames", None, "AnimateDiff (text to video)", "MS-Vid2Vid-XL", 33, 50, 9.0],
|
111 |
+
["Dive into the depths of the ocean: explore vibrant coral reefs, mysterious underwater caves, and the mesmerizing creatures that call the sea home.",
|
112 |
+
None, "56 - frames", None, "SVD (image to video)", "MS-Vid2Vid-XL", 33, 50, 9.0],
|
|
|
|
|
|
|
|
|
113 |
["Ants, beetles and centipede nest.",
|
114 |
+
None, "56 - frames", None, "SVD (image to video)", "MS-Vid2Vid-XL", 33, 50, 9.0],
|
115 |
]
|
116 |
|
117 |
+
examples_2 = [
|
118 |
+
["Fishes swimming in ocean camera moving, cinematic.",
|
119 |
+
None, "56 - frames", "__assets__/fish.jpg", "SVD (image to video)", "MS-Vid2Vid-XL", 33, 50, 9.0],
|
120 |
+
["A squirrel on a table full of big nuts.",
|
121 |
+
None, "56 - frames", "__assets__/squirrel.jpg", "SVD (image to video)", "MS-Vid2Vid-XL", 33, 50, 9.0],
|
122 |
+
]
|
123 |
|
124 |
# --------------------------
|
125 |
# ----- Gradio-Demo UI -----
|
|
|
170 |
with gr.Row():
|
171 |
prompt_stage1 = gr.Textbox(label='Textual Prompt', placeholder="Ex: Dog running on the street.")
|
172 |
with gr.Row():
|
173 |
+
image_stage1 = 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)
|
174 |
with gr.Column():
|
175 |
video_stage1 = gr.Video(label='Long Video Preview', show_label=True, interactive=False, scale=2, show_download_button=True)
|
176 |
with gr.Row():
|
|
|
208 |
|
209 |
inputs_v2v = [prompt_stage1, video_stage1, num_frames, image_stage1, model_name_stage1, model_name_stage2, seed, t, image_guidance]
|
210 |
|
211 |
+
gr.Examples(examples=examples_1,
|
212 |
+
inputs=inputs_v2v,
|
213 |
+
outputs=[video_stage2],
|
214 |
+
fn=enhance,
|
215 |
+
run_on_click=False,
|
216 |
+
cache_examples=True,
|
217 |
+
preprocess=False,
|
218 |
+
postprocess=True,
|
219 |
+
)
|
220 |
+
|
221 |
+
gr.Examples(examples=examples_2,
|
222 |
+
inputs=inputs_v2v,
|
223 |
+
outputs=[video_stage2],
|
224 |
+
fn=enhance,
|
225 |
+
run_on_click=False,
|
226 |
+
cache_examples=True,
|
227 |
+
preprocess=False,
|
228 |
+
postprocess=True,
|
229 |
+
)
|
230 |
+
|
231 |
run_button_stage2.click(fn=enhance, inputs=inputs_v2v, outputs=video_stage2,)
|
232 |
|
233 |
'''
|
|
|
258 |
demo.queue(max_size=20)
|
259 |
demo.launch(debug=True)
|
260 |
else:
|
261 |
+
demo.queue(api_open=False).launch(share=args.public_access)
|
|