Update app.py
Browse files
app.py
CHANGED
|
@@ -15,9 +15,9 @@ import torchaudio
|
|
| 15 |
from torchaudio import transforms as T
|
| 16 |
from neucodec import DistillNeuCodec
|
| 17 |
|
| 18 |
-
# Load model
|
| 19 |
model = DistillNeuCodec.from_pretrained("neuphonic/distill-neucodec")
|
| 20 |
-
model.eval()
|
| 21 |
|
| 22 |
def reconstruct_audio(audio_file):
|
| 23 |
# Load uploaded audio
|
|
@@ -28,10 +28,10 @@ def reconstruct_audio(audio_file):
|
|
| 28 |
y = T.Resample(sr, 16_000)(y)
|
| 29 |
y = y[None, ...] # Add batch dim (B, 1, T)
|
| 30 |
|
| 31 |
-
# Encode and decode
|
| 32 |
with torch.no_grad():
|
| 33 |
-
fsq_codes = model.encode_code(y
|
| 34 |
-
recon = model.decode_code(fsq_codes)
|
| 35 |
|
| 36 |
# Save to temporary file
|
| 37 |
recon_path = "reconstructed.wav"
|
|
@@ -44,8 +44,8 @@ iface = gr.Interface(
|
|
| 44 |
fn=reconstruct_audio,
|
| 45 |
inputs=gr.Audio(type="filepath", label="Upload Audio"),
|
| 46 |
outputs=gr.Audio(type="filepath", label="Reconstructed Audio"),
|
| 47 |
-
title="Audio Reconstruction with DistillNeuCodec",
|
| 48 |
-
description="Upload any audio file, and this app will reconstruct it using DistillNeuCodec at 24kHz."
|
| 49 |
)
|
| 50 |
|
| 51 |
if __name__ == "__main__":
|
|
|
|
| 15 |
from torchaudio import transforms as T
|
| 16 |
from neucodec import DistillNeuCodec
|
| 17 |
|
| 18 |
+
# Load model on CPU
|
| 19 |
model = DistillNeuCodec.from_pretrained("neuphonic/distill-neucodec")
|
| 20 |
+
model.eval() # CPU only
|
| 21 |
|
| 22 |
def reconstruct_audio(audio_file):
|
| 23 |
# Load uploaded audio
|
|
|
|
| 28 |
y = T.Resample(sr, 16_000)(y)
|
| 29 |
y = y[None, ...] # Add batch dim (B, 1, T)
|
| 30 |
|
| 31 |
+
# Encode and decode on CPU
|
| 32 |
with torch.no_grad():
|
| 33 |
+
fsq_codes = model.encode_code(y)
|
| 34 |
+
recon = model.decode_code(fsq_codes)
|
| 35 |
|
| 36 |
# Save to temporary file
|
| 37 |
recon_path = "reconstructed.wav"
|
|
|
|
| 44 |
fn=reconstruct_audio,
|
| 45 |
inputs=gr.Audio(type="filepath", label="Upload Audio"),
|
| 46 |
outputs=gr.Audio(type="filepath", label="Reconstructed Audio"),
|
| 47 |
+
title="Audio Reconstruction with DistillNeuCodec (CPU)",
|
| 48 |
+
description="Upload any audio file, and this app will reconstruct it using DistillNeuCodec at 24kHz on CPU."
|
| 49 |
)
|
| 50 |
|
| 51 |
if __name__ == "__main__":
|