mrfakename commited on
Commit
55781cc
·
verified ·
1 Parent(s): c966889

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -9
app.py CHANGED
@@ -11,16 +11,11 @@ DEVICE = "cuda" if torch.cuda.is_available() else "cpu"
11
  MODEL = SNAC.from_pretrained("hubertsiuzdak/snac_24khz").eval().to(DEVICE)
12
 
13
  def reconstruct(audio_in):
14
- """
15
- audio_in is (sample_rate:int, data:np.ndarray) from gr.Audio(type="numpy")
16
- returns (24000, np.ndarray)
17
- """
18
  if audio_in is None:
19
  return None
20
 
21
- sr, data = audio_in # data: (T,) or (T, C)
22
 
23
- # convert to mono if stereo
24
  if data.ndim == 2 and data.shape[1] > 1:
25
  data = data.mean(axis=1)
26
 
@@ -32,10 +27,11 @@ def reconstruct(audio_in):
32
  x = x.unsqueeze(0).to(DEVICE) # [1, 1, T]
33
 
34
  with torch.inference_mode():
35
- y_hat, _, _, _, _ = MODEL(x) # [1, 1, T]
 
36
 
37
- y = y_hat.squeeze(0).squeeze(0).detach().cpu()
38
- y = torch.clamp(y, -1.0, 1.0) # safety clamp
39
 
40
  return (24000, y.numpy())
41
 
 
11
  MODEL = SNAC.from_pretrained("hubertsiuzdak/snac_24khz").eval().to(DEVICE)
12
 
13
  def reconstruct(audio_in):
 
 
 
 
14
  if audio_in is None:
15
  return None
16
 
17
+ sr, data = audio_in
18
 
 
19
  if data.ndim == 2 and data.shape[1] > 1:
20
  data = data.mean(axis=1)
21
 
 
27
  x = x.unsqueeze(0).to(DEVICE) # [1, 1, T]
28
 
29
  with torch.inference_mode():
30
+ out = MODEL(x)
31
+ audio_hat = out[0] if isinstance(out, (list, tuple)) else out
32
 
33
+ y = audio_hat.squeeze(0).squeeze(0).detach().cpu()
34
+ y = torch.clamp(y, -1.0, 1.0)
35
 
36
  return (24000, y.numpy())
37