Update app.py
Browse files
app.py
CHANGED
@@ -79,32 +79,56 @@ def video_to_audio(video_path: str, prompt: str, negative_prompt: str = "music",
|
|
79 |
rng.seed()
|
80 |
fm = FlowMatching(min_sigma=0, inference_mode='euler', num_steps=num_steps)
|
81 |
|
82 |
-
#
|
83 |
-
video_info = load_video(video_path, static_duration=duration)
|
84 |
|
|
|
|
|
|
|
|
|
85 |
clip_frames = video_info.clip_frames
|
86 |
sync_frames = video_info.sync_frames
|
87 |
actual_duration = video_info.duration_sec
|
|
|
|
|
|
|
|
|
|
|
88 |
clip_frames = clip_frames.unsqueeze(0)
|
89 |
sync_frames = sync_frames.unsqueeze(0)
|
|
|
|
|
90 |
seq_cfg.duration = actual_duration
|
91 |
net.update_seq_lengths(seq_cfg.latent_seq_len, seq_cfg.clip_seq_len, seq_cfg.sync_seq_len)
|
92 |
|
|
|
93 |
audios = generate(clip_frames,
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
101 |
audio = audios.float().cpu()[0]
|
102 |
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
return video_save_path
|
107 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
108 |
except Exception as e:
|
109 |
logger.error(f"Error in video_to_audio: {str(e)}")
|
110 |
return video_path # ์ค๋ฅ ๋ฐ์ ์ ์๋ณธ ๋น๋์ค ๋ฐํ
|
@@ -321,6 +345,7 @@ def generate_video(image, prompt):
|
|
321 |
|
322 |
# ์ค๋์ค ์ฒ๋ฆฌ ์ถ๊ฐ
|
323 |
try:
|
|
|
324 |
final_path_with_audio = video_to_audio(
|
325 |
final_path,
|
326 |
prompt=prompt,
|
@@ -328,16 +353,25 @@ def generate_video(image, prompt):
|
|
328 |
seed=-1,
|
329 |
num_steps=25,
|
330 |
cfg_strength=4.5,
|
331 |
-
duration=8
|
332 |
)
|
333 |
|
334 |
-
|
335 |
-
|
336 |
-
|
337 |
-
|
338 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
339 |
|
340 |
-
return final_path_with_audio
|
341 |
except Exception as e:
|
342 |
logger.error(f"Error in audio processing: {str(e)}")
|
343 |
return final_path # ์ค๋์ค ์ฒ๋ฆฌ ์คํจ ์ ์ํฐ๋งํฌ๋ง ๋ ๋น๋์ค ๋ฐํ
|
|
|
79 |
rng.seed()
|
80 |
fm = FlowMatching(min_sigma=0, inference_mode='euler', num_steps=num_steps)
|
81 |
|
82 |
+
# video_info = load_video(video_path, duration) ๋์ :
|
83 |
+
video_info = load_video(video_path, static_duration=duration)
|
84 |
|
85 |
+
if video_info is None:
|
86 |
+
logger.error("Failed to load video")
|
87 |
+
return video_path
|
88 |
+
|
89 |
clip_frames = video_info.clip_frames
|
90 |
sync_frames = video_info.sync_frames
|
91 |
actual_duration = video_info.duration_sec
|
92 |
+
|
93 |
+
if clip_frames is None or sync_frames is None:
|
94 |
+
logger.error("Failed to extract frames from video")
|
95 |
+
return video_path
|
96 |
+
|
97 |
clip_frames = clip_frames.unsqueeze(0)
|
98 |
sync_frames = sync_frames.unsqueeze(0)
|
99 |
+
|
100 |
+
# ์ํ์ค ๊ธธ์ด ์
๋ฐ์ดํธ
|
101 |
seq_cfg.duration = actual_duration
|
102 |
net.update_seq_lengths(seq_cfg.latent_seq_len, seq_cfg.clip_seq_len, seq_cfg.sync_seq_len)
|
103 |
|
104 |
+
# ์ค๋์ค ์์ฑ
|
105 |
audios = generate(clip_frames,
|
106 |
+
sync_frames,
|
107 |
+
[prompt],
|
108 |
+
negative_text=[negative_prompt],
|
109 |
+
feature_utils=feature_utils,
|
110 |
+
net=net,
|
111 |
+
fm=fm,
|
112 |
+
rng=rng,
|
113 |
+
cfg_strength=cfg_strength)
|
114 |
+
|
115 |
+
if audios is None:
|
116 |
+
logger.error("Failed to generate audio")
|
117 |
+
return video_path
|
118 |
+
|
119 |
audio = audios.float().cpu()[0]
|
120 |
|
121 |
+
# ๊ฒฐ๊ณผ ๋น๋์ค ์์ฑ
|
122 |
+
output_path = tempfile.NamedTemporaryFile(delete=False, suffix='.mp4').name
|
123 |
+
success = make_video(video_info, output_path, audio, sampling_rate=seq_cfg.sampling_rate)
|
|
|
124 |
|
125 |
+
if not success:
|
126 |
+
logger.error("Failed to create video with audio")
|
127 |
+
return video_path
|
128 |
+
|
129 |
+
logger.info(f'Successfully saved video with audio to {output_path}')
|
130 |
+
return output_path
|
131 |
+
|
132 |
except Exception as e:
|
133 |
logger.error(f"Error in video_to_audio: {str(e)}")
|
134 |
return video_path # ์ค๋ฅ ๋ฐ์ ์ ์๋ณธ ๋น๋์ค ๋ฐํ
|
|
|
345 |
|
346 |
# ์ค๋์ค ์ฒ๋ฆฌ ์ถ๊ฐ
|
347 |
try:
|
348 |
+
logger.info("Starting audio generation process")
|
349 |
final_path_with_audio = video_to_audio(
|
350 |
final_path,
|
351 |
prompt=prompt,
|
|
|
353 |
seed=-1,
|
354 |
num_steps=25,
|
355 |
cfg_strength=4.5,
|
356 |
+
duration=8.0 # float ํ์
์ผ๋ก ๋ช
์
|
357 |
)
|
358 |
|
359 |
+
if final_path_with_audio != final_path:
|
360 |
+
logger.info("Audio generation successful")
|
361 |
+
# ์์ ํ์ผ ์ ๋ฆฌ
|
362 |
+
try:
|
363 |
+
if output_path != final_path:
|
364 |
+
os.remove(output_path)
|
365 |
+
if final_path != final_path_with_audio:
|
366 |
+
os.remove(final_path)
|
367 |
+
except Exception as e:
|
368 |
+
logger.warning(f"Error cleaning up temporary files: {str(e)}")
|
369 |
+
|
370 |
+
return final_path_with_audio
|
371 |
+
else:
|
372 |
+
logger.warning("Audio generation skipped, using original video")
|
373 |
+
return final_path
|
374 |
|
|
|
375 |
except Exception as e:
|
376 |
logger.error(f"Error in audio processing: {str(e)}")
|
377 |
return final_path # ์ค๋์ค ์ฒ๋ฆฌ ์คํจ ์ ์ํฐ๋งํฌ๋ง ๋ ๋น๋์ค ๋ฐํ
|