multimodalart HF Staff commited on
Commit
e050a10
·
verified ·
1 Parent(s): 9472ad9

Upload app.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. app.py +16 -0
app.py CHANGED
@@ -51,6 +51,21 @@ def _trim(waveform: torch.Tensor, sr: int, max_seconds: float):
51
  return waveform, False
52
 
53
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
54
  @spaces.GPU(duration=120)
55
  def refine(
56
  audio_path: str,
@@ -75,6 +90,7 @@ def refine(
75
  raise gr.Error("Please upload an audio file or pick an example first.")
76
  waveform, sr = _load_waveform(audio_path)
77
  waveform, trimmed = _trim(waveform, sr, MAX_SECONDS)
 
78
  steps = int(steps)
79
  if steps < 1:
80
  steps = 32
 
51
  return waveform, False
52
 
53
 
54
+ DAV_HOP = 512
55
+
56
+
57
+ def _align_hop(waveform: torch.Tensor, sr: int):
58
+ """Trim the tail to a whole DAV hop.
59
+
60
+ The windowed refinement raises 'window overlap left uncovered latent frames' when the
61
+ total sample count is not a multiple of the 512-sample DAV hop (the final window start
62
+ is aligned down and the last partial frame is never covered). Trimming to a whole hop
63
+ removes the uncovered frame; at 44.1 kHz that is at most ~11 ms of audio.
64
+ """
65
+ frames = waveform.shape[-1] // DAV_HOP
66
+ return waveform[..., : frames * DAV_HOP]
67
+
68
+
69
  @spaces.GPU(duration=120)
70
  def refine(
71
  audio_path: str,
 
90
  raise gr.Error("Please upload an audio file or pick an example first.")
91
  waveform, sr = _load_waveform(audio_path)
92
  waveform, trimmed = _trim(waveform, sr, MAX_SECONDS)
93
+ waveform = _align_hop(waveform, sr)
94
  steps = int(steps)
95
  if steps < 1:
96
  steps = 32