Update app.py
Browse files
app.py
CHANGED
|
@@ -3,17 +3,13 @@ import torchaudio
|
|
| 3 |
from sgmse.model import ScoreModel
|
| 4 |
import gradio as gr
|
| 5 |
from sgmse.util.other import pad_spec
|
| 6 |
-
|
| 7 |
# Load the pre-trained model
|
| 8 |
-
model =
|
| 9 |
-
|
| 10 |
def enhance_speech(audio_file):
|
| 11 |
# Load and process the audio file
|
| 12 |
y, sr = torchaudio.load(audio_file)
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
# Normalize
|
| 17 |
norm_factor = y.abs().max()
|
| 18 |
y = y / norm_factor
|
| 19 |
|
|
@@ -29,8 +25,7 @@ def enhance_speech(audio_file):
|
|
| 29 |
|
| 30 |
# Backward transform in time domain
|
| 31 |
x_hat = model.to_audio(sample.squeeze(), T_orig)
|
| 32 |
-
|
| 33 |
-
# Renormalize
|
| 34 |
x_hat = x_hat * norm_factor
|
| 35 |
|
| 36 |
# Save the enhanced audio
|
|
@@ -38,13 +33,12 @@ def enhance_speech(audio_file):
|
|
| 38 |
torchaudio.save(output_file, x_hat.cpu().numpy(), sr)
|
| 39 |
|
| 40 |
return output_file
|
| 41 |
-
|
| 42 |
# Gradio interface setup
|
| 43 |
inputs = gr.Audio(label="Input Audio", type="filepath")
|
| 44 |
outputs = gr.Audio(label="Output Audio", type="filepath")
|
| 45 |
title = "Speech Enhancement using SGMSE"
|
| 46 |
description = "This Gradio demo uses the SGMSE model for speech enhancement. Upload your audio file to enhance it."
|
| 47 |
article = "<p style='text-align: center'><a href='https://huggingface.co/SP-UHH/speech-enhancement-sgmse' target='_blank'>Model Card</a></p>"
|
| 48 |
-
|
| 49 |
# Launch without share=True (as it's not supported on Hugging Face Spaces)
|
| 50 |
-
gr.Interface(fn=enhance_speech, inputs=inputs, outputs=outputs, title=title, description=description, article=article).launch(
|
|
|
|
|
|
| 3 |
from sgmse.model import ScoreModel
|
| 4 |
import gradio as gr
|
| 5 |
from sgmse.util.other import pad_spec
|
|
|
|
| 6 |
# Load the pre-trained model
|
| 7 |
+
model = ScoreModel.load_from_checkpoint("https://huggingface.co/sp-uhh/speech-enhancement-sgmse/resolve/main/train_vb_29nqe0uh_epoch%3D115.ckpt")
|
|
|
|
| 8 |
def enhance_speech(audio_file):
|
| 9 |
# Load and process the audio file
|
| 10 |
y, sr = torchaudio.load(audio_file)
|
| 11 |
+
T_orig = y.size(1)
|
| 12 |
+
# Normalize
|
|
|
|
|
|
|
| 13 |
norm_factor = y.abs().max()
|
| 14 |
y = y / norm_factor
|
| 15 |
|
|
|
|
| 25 |
|
| 26 |
# Backward transform in time domain
|
| 27 |
x_hat = model.to_audio(sample.squeeze(), T_orig)
|
| 28 |
+
# Renormalize
|
|
|
|
| 29 |
x_hat = x_hat * norm_factor
|
| 30 |
|
| 31 |
# Save the enhanced audio
|
|
|
|
| 33 |
torchaudio.save(output_file, x_hat.cpu().numpy(), sr)
|
| 34 |
|
| 35 |
return output_file
|
|
|
|
| 36 |
# Gradio interface setup
|
| 37 |
inputs = gr.Audio(label="Input Audio", type="filepath")
|
| 38 |
outputs = gr.Audio(label="Output Audio", type="filepath")
|
| 39 |
title = "Speech Enhancement using SGMSE"
|
| 40 |
description = "This Gradio demo uses the SGMSE model for speech enhancement. Upload your audio file to enhance it."
|
| 41 |
article = "<p style='text-align: center'><a href='https://huggingface.co/SP-UHH/speech-enhancement-sgmse' target='_blank'>Model Card</a></p>"
|
|
|
|
| 42 |
# Launch without share=True (as it's not supported on Hugging Face Spaces)
|
| 43 |
+
gr.Interface(fn=enhance_speech, inputs=inputs, outputs=outputs, title=title, description=description, article=article).launch(
|
| 44 |
+
|