multimodalart HF staff commited on
Commit
799d1da
1 Parent(s): c166f1f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -0
app.py CHANGED
@@ -34,6 +34,7 @@ import moviepy.editor as mp
34
  import utils
35
  from rife_model import load_rife_model, rife_inference_with_latents
36
  from huggingface_hub import hf_hub_download, snapshot_download
 
37
 
38
  device = "cuda" if torch.cuda.is_available() else "cpu"
39
 
@@ -240,6 +241,9 @@ def infer(
240
  guidance_scale=guidance_scale,
241
  generator=torch.Generator(device="cpu").manual_seed(seed),
242
  ).frames
 
 
 
243
  elif image_input is not None:
244
  pipe_image.to(device)
245
  image_input = Image.fromarray(image_input).resize(size=(720, 480)) # Convert to PIL
@@ -255,6 +259,7 @@ def infer(
255
  generator=torch.Generator(device="cpu").manual_seed(seed),
256
  ).frames
257
  pipe_image.to("cpu")
 
258
  else:
259
  pipe.to(device)
260
  video_pt = pipe(
@@ -268,6 +273,7 @@ def infer(
268
  generator=torch.Generator(device="cpu").manual_seed(seed),
269
  ).frames
270
  pipe.to("cpu")
 
271
  return (video_pt, seed)
272
 
273
 
 
34
  import utils
35
  from rife_model import load_rife_model, rife_inference_with_latents
36
  from huggingface_hub import hf_hub_download, snapshot_download
37
+ import gc
38
 
39
  device = "cuda" if torch.cuda.is_available() else "cpu"
40
 
 
241
  guidance_scale=guidance_scale,
242
  generator=torch.Generator(device="cpu").manual_seed(seed),
243
  ).frames
244
+ del pipe_video
245
+ gc.collect()
246
+ torch.cuda.empty_cache()
247
  elif image_input is not None:
248
  pipe_image.to(device)
249
  image_input = Image.fromarray(image_input).resize(size=(720, 480)) # Convert to PIL
 
259
  generator=torch.Generator(device="cpu").manual_seed(seed),
260
  ).frames
261
  pipe_image.to("cpu")
262
+ gc.collect()
263
  else:
264
  pipe.to(device)
265
  video_pt = pipe(
 
273
  generator=torch.Generator(device="cpu").manual_seed(seed),
274
  ).frames
275
  pipe.to("cpu")
276
+ gc.collect()
277
  return (video_pt, seed)
278
 
279