goryhon commited on
Commit
c7f5642
·
verified ·
1 Parent(s): 8429e13

Update web-demos/hugging_face/app.py

Browse files
Files changed (1) hide show
  1. web-demos/hugging_face/app.py +19 -6
web-demos/hugging_face/app.py CHANGED
@@ -321,7 +321,7 @@ def inpaint_video(video_state, resize_ratio_number, dilate_radius_number, raft_i
321
  neighbor_length=neighbor_length_number,
322
  ref_stride=ref_stride_number) # numpy array, T, H, W, 3
323
 
324
- video_output = generate_video_from_frames(inpainted_frames, output_path="./result/inpaint/{}".format(video_state["video_name"]), fps=float(fps)) # import video_input to name the output video
325
 
326
  return video_output, operation_log, operation_log
327
 
@@ -336,15 +336,28 @@ def generate_video_from_frames(frames, output_path, fps=30):
336
  fps (int, optional): The frame rate of the output video. Defaults to 30.
337
  """
338
  # Приведение fps к обычному float (из np.float64, если нужно)
339
- fps = float(fps)
 
 
 
 
340
 
341
- frames = torch.from_numpy(np.asarray(frames)) # shape: (T, H, W, C)
342
-
343
- # Убедимся, что директория существует
 
 
 
 
 
 
 
 
 
344
  if not os.path.exists(os.path.dirname(output_path)):
345
  os.makedirs(os.path.dirname(output_path))
346
 
347
- # Пишем видео
348
  torchvision.io.write_video(output_path, frames, fps=fps, video_codec="libx264")
349
  return output_path
350
 
 
321
  neighbor_length=neighbor_length_number,
322
  ref_stride=ref_stride_number) # numpy array, T, H, W, 3
323
 
324
+ video_output = generate_video_from_frames(inpainted_frames, output_path="./result/inpaint/{}".format(video_state["video_name"]), fps=fps) # import video_input to name the output video
325
 
326
  return video_output, operation_log, operation_log
327
 
 
336
  fps (int, optional): The frame rate of the output video. Defaults to 30.
337
  """
338
  # Приведение fps к обычному float (из np.float64, если нужно)
339
+ import numpy as np
340
+ import torch
341
+ import torchvision
342
+ import os
343
+ from fractions import Fraction
344
 
345
+ # Convert fps to a clean format
346
+ if isinstance(fps, np.generic):
347
+ fps = fps.item()
348
+ fps = Fraction(float(fps)).limit_denominator()
349
+
350
+ # Ensure all frames are the same shape
351
+ assert all(f.shape == frames[0].shape for f in frames), "All frames must have the same shape"
352
+
353
+ # Convert to tensor (T, H, W, C)
354
+ frames = torch.from_numpy(np.asarray(frames))
355
+
356
+ # Ensure output directory exists
357
  if not os.path.exists(os.path.dirname(output_path)):
358
  os.makedirs(os.path.dirname(output_path))
359
 
360
+ # Write the video
361
  torchvision.io.write_video(output_path, frames, fps=fps, video_codec="libx264")
362
  return output_path
363