ibyteohdear commited on
Commit
ce02a16
·
verified ·
1 Parent(s): 888e6bc

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -2
app.py CHANGED
@@ -77,9 +77,24 @@ net, feature_utils, seq_cfg = load_all_models()
77
 
78
  # --- INFERENCE FUNCTIONS ---
79
 
 
 
 
 
 
 
 
 
 
 
 
80
  @spaces.GPU()
81
  @torch.inference_mode()
82
- def video_to_audio(video, prompt, negative_prompt, seed, num_steps, cfg_strength, duration):
 
 
 
 
83
  rng = torch.Generator(device=device)
84
  rng.manual_seed(int(seed)) if seed >= 0 else rng.seed()
85
  fm = FlowMatching(min_sigma=0, inference_mode='euler', num_steps=int(num_steps))
@@ -103,7 +118,7 @@ def video_to_audio(video, prompt, negative_prompt, seed, num_steps, cfg_strength
103
  make_video(video_info, path, audio, sampling_rate=seq_cfg.sampling_rate)
104
  gc.collect()
105
  return path
106
-
107
  @spaces.GPU()
108
  @torch.inference_mode()
109
  def image_to_audio(image, prompt, negative_prompt, seed, num_steps, cfg_strength, duration):
 
77
 
78
  # --- INFERENCE FUNCTIONS ---
79
 
80
+ def get_video_duration(video_path):
81
+ if video_path is None:
82
+ return 8
83
+ try:
84
+ import torchaudio
85
+ info = torchaudio.info(video_path)
86
+ duration = info.num_frames / info.sample_rate
87
+ return round(duration, 2)
88
+ except Exception:
89
+ return 8 #
90
+
91
  @spaces.GPU()
92
  @torch.inference_mode()
93
+ def video_to_audio(video, prompt, negative_prompt, seed, num_steps, cfg_strength, duration=None):
94
+
95
+ if duration is None:
96
+ duration = get_video_duration(video)
97
+
98
  rng = torch.Generator(device=device)
99
  rng.manual_seed(int(seed)) if seed >= 0 else rng.seed()
100
  fm = FlowMatching(min_sigma=0, inference_mode='euler', num_steps=int(num_steps))
 
118
  make_video(video_info, path, audio, sampling_rate=seq_cfg.sampling_rate)
119
  gc.collect()
120
  return path
121
+
122
  @spaces.GPU()
123
  @torch.inference_mode()
124
  def image_to_audio(image, prompt, negative_prompt, seed, num_steps, cfg_strength, duration):