lab
commited on
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,10 +1,41 @@
|
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
|
|
|
| 2 |
|
|
|
|
|
|
|
| 3 |
|
| 4 |
-
|
| 5 |
-
|
| 6 |
|
| 7 |
-
|
| 8 |
-
|
| 9 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import torch
|
| 2 |
+
import torchaudio
|
| 3 |
import gradio as gr
|
| 4 |
+
import requests
|
| 5 |
|
| 6 |
+
# Download and load the HuBERT content encoder
|
| 7 |
+
hubert = torch.hub.load("bshall/hubert:main", "hubert_soft", trust_repo=True).cuda()
|
| 8 |
|
| 9 |
+
# Assuming similar steps for downloading and loading the acoustic model
|
| 10 |
+
acoustic_model = torch.hub.load("bshall/acoustic-model:main", "hubert_soft", trust_repo=True).cuda()
|
| 11 |
|
| 12 |
+
# Load the HiFiGAN vocoder (if used in the notebook)
|
| 13 |
+
vocoder = torch.hub.load("bshall/hifigan:main", "hifigan", trust_repo=True).cuda()
|
| 14 |
|
| 15 |
+
def voice_conversion(input_audio):
|
| 16 |
+
# Load input audio
|
| 17 |
+
waveform, sample_rate = torchaudio.load(input_audio)
|
| 18 |
+
|
| 19 |
+
# Process the audio using the models
|
| 20 |
+
with torch.no_grad():
|
| 21 |
+
units = hubert(waveform.cuda())
|
| 22 |
+
mel_spec = acoustic_model.generate(units)
|
| 23 |
+
audio_out = vocoder(mel_spec)
|
| 24 |
+
|
| 25 |
+
# Save the output audio
|
| 26 |
+
output_path = "output.wav"
|
| 27 |
+
torchaudio.save(output_path, audio_out.cpu(), sample_rate)
|
| 28 |
+
|
| 29 |
+
return output_path
|
| 30 |
|
| 31 |
+
# Define Gradio interface
|
| 32 |
+
iface = gr.Interface(
|
| 33 |
+
fn=voice_conversion,
|
| 34 |
+
inputs=gr.inputs.Audio(source="upload", type="filepath"),
|
| 35 |
+
outputs=gr.outputs.Audio(type="file"),
|
| 36 |
+
title="Voice Conversion Demo",
|
| 37 |
+
description="Upload an audio file to convert its voice using HuBERT and other models."
|
| 38 |
+
)
|
| 39 |
+
|
| 40 |
+
# Launch the interface
|
| 41 |
+
iface.launch()
|