aiqcamp commited on
Commit
0c5effb
·
verified ·
1 Parent(s): 9b8d878

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -8
app.py CHANGED
@@ -72,8 +72,6 @@ def video_to_audio(video_path: str, prompt: str, negative_prompt: str = "music",
72
  cfg_strength: float = 4.5, target_duration: float = 6.0):
73
  try:
74
  logger.info("Starting audio generation process")
75
-
76
- # GPU 메모리 최적화
77
  torch.cuda.empty_cache()
78
 
79
  rng = torch.Generator(device=device)
@@ -85,12 +83,16 @@ def video_to_audio(video_path: str, prompt: str, negative_prompt: str = "music",
85
  fm = FlowMatching(min_sigma=0, inference_mode='euler', num_steps=num_steps)
86
 
87
  # load_video 함수 호출 수정
88
- video_info = load_video(video_path, duration=target_duration) # static_duration을 duration으로 변경
89
 
90
  if video_info is None:
91
  logger.error("Failed to load video")
92
  return video_path
93
 
 
 
 
 
94
  clip_frames = video_info.clip_frames
95
  sync_frames = video_info.sync_frames
96
  actual_duration = video_info.duration_sec
@@ -99,7 +101,6 @@ def video_to_audio(video_path: str, prompt: str, negative_prompt: str = "music",
99
  logger.error("Failed to extract frames from video")
100
  return video_path
101
 
102
- # 메모리 효율을 위해 배치 크기 조정
103
  clip_frames = clip_frames.unsqueeze(0).to(device, dtype=torch.float16)
104
  sync_frames = sync_frames.unsqueeze(0).to(device, dtype=torch.float16)
105
 
@@ -126,13 +127,12 @@ def video_to_audio(video_path: str, prompt: str, negative_prompt: str = "music",
126
  output_path = tempfile.NamedTemporaryFile(delete=False, suffix='.mp4').name
127
  logger.info(f"Creating final video with audio at {output_path}")
128
 
129
- success = make_video(video_info, output_path, audio, sampling_rate=seq_cfg.sampling_rate)
130
 
131
- # GPU 메모리 정리
132
  torch.cuda.empty_cache()
133
 
134
- if not success:
135
- logger.error("Failed to create video with audio")
136
  return video_path
137
 
138
  logger.info(f'Successfully saved video with audio to {output_path}')
 
72
  cfg_strength: float = 4.5, target_duration: float = 6.0):
73
  try:
74
  logger.info("Starting audio generation process")
 
 
75
  torch.cuda.empty_cache()
76
 
77
  rng = torch.Generator(device=device)
 
83
  fm = FlowMatching(min_sigma=0, inference_mode='euler', num_steps=num_steps)
84
 
85
  # load_video 함수 호출 수정
86
+ video_info = load_video(video_path) # duration 파라미터 제거
87
 
88
  if video_info is None:
89
  logger.error("Failed to load video")
90
  return video_path
91
 
92
+ # 비디오 길이 조정이 필요한 경우 여기서 처리
93
+ if hasattr(video_info, 'set_duration'):
94
+ video_info.set_duration(target_duration)
95
+
96
  clip_frames = video_info.clip_frames
97
  sync_frames = video_info.sync_frames
98
  actual_duration = video_info.duration_sec
 
101
  logger.error("Failed to extract frames from video")
102
  return video_path
103
 
 
104
  clip_frames = clip_frames.unsqueeze(0).to(device, dtype=torch.float16)
105
  sync_frames = sync_frames.unsqueeze(0).to(device, dtype=torch.float16)
106
 
 
127
  output_path = tempfile.NamedTemporaryFile(delete=False, suffix='.mp4').name
128
  logger.info(f"Creating final video with audio at {output_path}")
129
 
130
+ make_video(video_info, output_path, audio, sampling_rate=seq_cfg.sampling_rate)
131
 
 
132
  torch.cuda.empty_cache()
133
 
134
+ if not os.path.exists(output_path):
135
+ logger.error("Failed to create output video")
136
  return video_path
137
 
138
  logger.info(f'Successfully saved video with audio to {output_path}')