multimodalart HF staff commited on
Commit
536f1c7
·
1 Parent(s): 8c6a211

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +39 -14
app.py CHANGED
@@ -108,7 +108,23 @@ def prep(config):
108
 
109
 
110
  return frames, latents, total_inverted_latents, rgb_reconstruction
111
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
112
  def preprocess_and_invert(input_video,
113
  frames,
114
  latents,
@@ -141,21 +157,27 @@ def preprocess_and_invert(input_video,
141
  #preprocess_config['n_frames'] = n_frames
142
  preprocess_config['seed'] = seed
143
  preprocess_config['inversion_prompt'] = inversion_prompt
144
- preprocess_config['frames'], frames_per_second = video_to_frames(input_video)
 
 
 
145
  preprocess_config['data_path'] = input_video.split(".")[0]
146
 
147
- total_vid_frames = len(preprocess_config['frames'])
148
- total_vid_duration = total_vid_frames/frames_per_second
149
-
150
- if(total_vid_duration < 1):
151
- preprocess_config['n_frames'] = total_vid_frames
152
- else:
153
- preprocess_config['n_frames'] = int(frames_per_second/n_seconds)
154
-
155
- if preprocess_config['n_frames'] % batch_size != 0:
156
- preprocess_config['batch_size'] = largest_divisor(batch_size)
 
157
 
158
  print("Running with batch size of ", preprocess_config['batch_size'])
 
 
159
  if randomize_seed:
160
  seed = randomize_seed_fn()
161
  seed_everything(seed)
@@ -205,7 +227,9 @@ def edit_with_pnp(input_video,
205
  config["pnp_attn_t"] = pnp_attn_t
206
  config["pnp_f_t"] = pnp_f_t
207
  config["pnp_inversion_prompt"] = inversion_prompt
208
-
 
 
209
 
210
  if do_inversion:
211
  frames, latents, inverted_latents, do_inversion, batch_size, n_frames = preprocess_and_invert(
@@ -345,7 +369,7 @@ with gr.Blocks(css="style.css") as demo:
345
  input_video.upload(
346
  fn = reset_do_inversion,
347
  outputs = [do_inversion],
348
- queue = False).then(fn = preprocess_and_invert,
349
  inputs = [input_video,
350
  frames,
351
  latents,
@@ -367,6 +391,7 @@ with gr.Blocks(css="style.css") as demo:
367
  batch_size,
368
  n_frames
369
  ])
 
370
 
371
  run_button.click(fn = edit_with_pnp,
372
  inputs = [input_video,
 
108
 
109
 
110
  return frames, latents, total_inverted_latents, rgb_reconstruction
111
+
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
+
126
+ return frames, batch_size, frames_to_process
127
+
128
  def preprocess_and_invert(input_video,
129
  frames,
130
  latents,
 
157
  #preprocess_config['n_frames'] = n_frames
158
  preprocess_config['seed'] = seed
159
  preprocess_config['inversion_prompt'] = inversion_prompt
160
+ not_processed = False
161
+ if(not frames):
162
+ preprocess_config['frames'],frames_per_second = video_to_frames(input_video)
163
+ not_processed = True
164
  preprocess_config['data_path'] = input_video.split(".")[0]
165
 
166
+ if(not_processed):
167
+ total_vid_frames = len(preprocess_config['frames'])
168
+ total_vid_duration = total_vid_frames/frames_per_second
169
+
170
+ if(total_vid_duration < 1):
171
+ preprocess_config['n_frames'] = total_vid_frames
172
+ else:
173
+ preprocess_config['n_frames'] = int(frames_per_second/n_seconds)
174
+
175
+ if preprocess_config['n_frames'] % batch_size != 0:
176
+ preprocess_config['batch_size'] = largest_divisor(batch_size)
177
 
178
  print("Running with batch size of ", preprocess_config['batch_size'])
179
+ print("Total vid frames", preprocess_config['n_frames'])
180
+
181
  if randomize_seed:
182
  seed = randomize_seed_fn()
183
  seed_everything(seed)
 
227
  config["pnp_attn_t"] = pnp_attn_t
228
  config["pnp_f_t"] = pnp_f_t
229
  config["pnp_inversion_prompt"] = inversion_prompt
230
+
231
+ print("Running with batch size of ", config['batch_size'])
232
+ print("Total vid frames", config['n_frames'])
233
 
234
  if do_inversion:
235
  frames, latents, inverted_latents, do_inversion, batch_size, n_frames = preprocess_and_invert(
 
369
  input_video.upload(
370
  fn = reset_do_inversion,
371
  outputs = [do_inversion],
372
+ queue = False).then(fn = calculate_fps, inputs=[input_video], outputs=[frames, batch_size, n_frames], queue=False).then(fn = preprocess_and_invert,
373
  inputs = [input_video,
374
  frames,
375
  latents,
 
391
  batch_size,
392
  n_frames
393
  ])
394
+ input_video.change(fn = calculate_fps, inputs=[input_video], outputs=[batch_size, n_frames], queue=False)
395
 
396
  run_button.click(fn = edit_with_pnp,
397
  inputs = [input_video,