Spaces:
Runtime error
Runtime error
Commit
•
1ec57b2
1
Parent(s):
848c1a5
Update app.py
Browse files
app.py
CHANGED
@@ -112,20 +112,20 @@ def prep(config):
|
|
112 |
|
113 |
def calculate_fps(input_video, batch_size):
|
114 |
frames, frames_per_second = video_to_frames(input_video)
|
115 |
-
total_vid_frames = len(frames)
|
116 |
-
total_vid_duration = total_vid_frames/frames_per_second
|
117 |
|
118 |
-
if(total_vid_duration < 1):
|
119 |
-
|
120 |
-
else:
|
121 |
-
|
122 |
-
|
123 |
-
if frames_to_process % batch_size != 0:
|
124 |
-
|
125 |
-
print("total vid duration", total_vid_duration)
|
126 |
-
print("frames to process", frames_to_process)
|
127 |
-
print("batch size", batch_size)
|
128 |
-
return frames,
|
129 |
|
130 |
def preprocess_and_invert(input_video,
|
131 |
frames,
|
@@ -140,6 +140,7 @@ def preprocess_and_invert(input_video,
|
|
140 |
batch_size: int = 8,
|
141 |
n_frames: int = 40,
|
142 |
n_seconds: int = 1,
|
|
|
143 |
inversion_prompt:str = '',
|
144 |
|
145 |
):
|
@@ -166,18 +167,17 @@ def preprocess_and_invert(input_video,
|
|
166 |
else:
|
167 |
preprocess_config['frames'] = frames
|
168 |
preprocess_config['data_path'] = input_video.split(".")[0]
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
total_vid_duration = total_vid_frames/frames_per_second
|
173 |
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
|
179 |
-
|
180 |
-
|
181 |
|
182 |
print("Running with batch size of ", preprocess_config['batch_size'])
|
183 |
print("Total vid frames", preprocess_config['n_frames'])
|
@@ -194,7 +194,7 @@ def preprocess_and_invert(input_video,
|
|
194 |
inverted_latents = gr.State(value=total_inverted_latents)
|
195 |
do_inversion = False
|
196 |
|
197 |
-
return frames, latents, inverted_latents, do_inversion, preprocess_config['batch_size'], preprocess_config['n_frames']
|
198 |
|
199 |
|
200 |
def edit_with_pnp(input_video,
|
@@ -212,6 +212,7 @@ def edit_with_pnp(input_video,
|
|
212 |
batch_size: int = 8, #needs to be the same as for preprocess
|
213 |
n_frames: int = 40,#needs to be the same as for preprocess
|
214 |
n_seconds: int = 1,
|
|
|
215 |
n_timesteps: int = 50,
|
216 |
gudiance_scale: float = 7.5,
|
217 |
inversion_prompt: str = "", #needs to be the same as for preprocess
|
@@ -337,9 +338,11 @@ with gr.Blocks(css="style.css") as demo:
|
|
337 |
minimum=1, maximum=2, step=1)
|
338 |
n_timesteps = gr.Slider(label='Diffusion steps', minimum=25, maximum=100,
|
339 |
value=50, step=25, interactive=True)
|
340 |
-
|
|
|
341 |
value=10, step=1, interactive=True)
|
342 |
|
|
|
343 |
with gr.TabItem('Plug-and-Play Parameters'):
|
344 |
with gr.Column(min_width=100):
|
345 |
pnp_attn_t = gr.Slider(label='pnp attention threshold', minimum=0, maximum=1,
|
@@ -373,7 +376,7 @@ with gr.Blocks(css="style.css") as demo:
|
|
373 |
input_video.upload(
|
374 |
fn = reset_do_inversion,
|
375 |
outputs = [do_inversion],
|
376 |
-
queue = False).then(fn = calculate_fps, inputs=[input_video
|
377 |
inputs = [input_video,
|
378 |
frames,
|
379 |
latents,
|
@@ -386,6 +389,7 @@ with gr.Blocks(css="style.css") as demo:
|
|
386 |
batch_size,
|
387 |
n_frames,
|
388 |
n_seconds,
|
|
|
389 |
inversion_prompt
|
390 |
],
|
391 |
outputs = [frames,
|
@@ -393,11 +397,10 @@ with gr.Blocks(css="style.css") as demo:
|
|
393 |
inverted_latents,
|
394 |
do_inversion,
|
395 |
batch_size,
|
396 |
-
n_frames
|
397 |
-
run_button
|
398 |
])
|
399 |
|
400 |
-
input_video.change(fn = calculate_fps, inputs=[input_video
|
401 |
|
402 |
run_button.click(fn = edit_with_pnp,
|
403 |
inputs = [input_video,
|
@@ -414,6 +417,7 @@ with gr.Blocks(css="style.css") as demo:
|
|
414 |
batch_size,
|
415 |
n_frames,
|
416 |
n_seconds,
|
|
|
417 |
n_timesteps,
|
418 |
gudiance_scale,
|
419 |
inversion_prompt,
|
|
|
112 |
|
113 |
def calculate_fps(input_video, batch_size):
|
114 |
frames, frames_per_second = video_to_frames(input_video)
|
115 |
+
#total_vid_frames = len(frames)
|
116 |
+
#total_vid_duration = total_vid_frames/frames_per_second
|
117 |
|
118 |
+
#if(total_vid_duration < 1):
|
119 |
+
# frames_to_process = total_vid_frames
|
120 |
+
#else:
|
121 |
+
# frames_to_process = int(frames_per_second/n_seconds)
|
122 |
+
#
|
123 |
+
#if frames_to_process % batch_size != 0:
|
124 |
+
# batch_size = largest_divisor(batch_size)
|
125 |
+
#print("total vid duration", total_vid_duration)
|
126 |
+
#print("frames to process", frames_to_process)
|
127 |
+
#print("batch size", batch_size)
|
128 |
+
return frames, frames_per_second
|
129 |
|
130 |
def preprocess_and_invert(input_video,
|
131 |
frames,
|
|
|
140 |
batch_size: int = 8,
|
141 |
n_frames: int = 40,
|
142 |
n_seconds: int = 1,
|
143 |
+
n_fps_input: int = 40,
|
144 |
inversion_prompt:str = '',
|
145 |
|
146 |
):
|
|
|
167 |
else:
|
168 |
preprocess_config['frames'] = frames
|
169 |
preprocess_config['data_path'] = input_video.split(".")[0]
|
170 |
+
|
171 |
+
total_vid_frames = len(preprocess_config['frames'])
|
172 |
+
total_vid_duration = total_vid_frames/frames_per_second
|
|
|
173 |
|
174 |
+
if(total_vid_duration < 1):
|
175 |
+
preprocess_config['n_frames'] = total_vid_frames
|
176 |
+
else:
|
177 |
+
preprocess_config['n_frames'] = int(frames_per_second/n_seconds)
|
178 |
|
179 |
+
if preprocess_config['n_frames'] % batch_size != 0:
|
180 |
+
preprocess_config['batch_size'] = largest_divisor(batch_size)
|
181 |
|
182 |
print("Running with batch size of ", preprocess_config['batch_size'])
|
183 |
print("Total vid frames", preprocess_config['n_frames'])
|
|
|
194 |
inverted_latents = gr.State(value=total_inverted_latents)
|
195 |
do_inversion = False
|
196 |
|
197 |
+
return frames, latents, inverted_latents, do_inversion, preprocess_config['batch_size'], preprocess_config['n_frames']
|
198 |
|
199 |
|
200 |
def edit_with_pnp(input_video,
|
|
|
212 |
batch_size: int = 8, #needs to be the same as for preprocess
|
213 |
n_frames: int = 40,#needs to be the same as for preprocess
|
214 |
n_seconds: int = 1,
|
215 |
+
n_fps_input: int = 40,
|
216 |
n_timesteps: int = 50,
|
217 |
gudiance_scale: float = 7.5,
|
218 |
inversion_prompt: str = "", #needs to be the same as for preprocess
|
|
|
338 |
minimum=1, maximum=2, step=1)
|
339 |
n_timesteps = gr.Slider(label='Diffusion steps', minimum=25, maximum=100,
|
340 |
value=50, step=25, interactive=True)
|
341 |
+
n_fps_input = gr.Slider(label="Input frames per second", value=40, minimum=1, maximum=120)
|
342 |
+
n_fps = gr.Slider(label='Output frames per second', minimum=1, maximum=60,
|
343 |
value=10, step=1, interactive=True)
|
344 |
|
345 |
+
|
346 |
with gr.TabItem('Plug-and-Play Parameters'):
|
347 |
with gr.Column(min_width=100):
|
348 |
pnp_attn_t = gr.Slider(label='pnp attention threshold', minimum=0, maximum=1,
|
|
|
376 |
input_video.upload(
|
377 |
fn = reset_do_inversion,
|
378 |
outputs = [do_inversion],
|
379 |
+
queue = False).then(fn = calculate_fps, inputs=[input_video], outputs=[frames, n_fps_input], queue=False).then(fn = preprocess_and_invert,
|
380 |
inputs = [input_video,
|
381 |
frames,
|
382 |
latents,
|
|
|
389 |
batch_size,
|
390 |
n_frames,
|
391 |
n_seconds,
|
392 |
+
n_fps_input,
|
393 |
inversion_prompt
|
394 |
],
|
395 |
outputs = [frames,
|
|
|
397 |
inverted_latents,
|
398 |
do_inversion,
|
399 |
batch_size,
|
400 |
+
n_frames
|
|
|
401 |
])
|
402 |
|
403 |
+
input_video.change(fn = calculate_fps, inputs=[input_video], outputs=[frames, n_fps_input], queue=False)
|
404 |
|
405 |
run_button.click(fn = edit_with_pnp,
|
406 |
inputs = [input_video,
|
|
|
417 |
batch_size,
|
418 |
n_frames,
|
419 |
n_seconds,
|
420 |
+
n_fps_input,
|
421 |
n_timesteps,
|
422 |
gudiance_scale,
|
423 |
inversion_prompt,
|