Spaces:
Paused
Paused
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import torch
|
| 2 |
+
import gradio as gr
|
| 3 |
+
import torchaudio
|
| 4 |
+
from transformers import AutoModel
|
| 5 |
+
import spaces
|
| 6 |
+
|
| 7 |
+
checkpoint_path = "/content/VoiceRestore"
|
| 8 |
+
model = AutoModel.from_pretrained(checkpoint_path, trust_remote_code=True)
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
@spaces.GPU()
|
| 12 |
+
def restore_audio(input_audio):
|
| 13 |
+
# load the audio file
|
| 14 |
+
output_path = "restored_output.wav"
|
| 15 |
+
model(input_audio, output_path)
|
| 16 |
+
return output_path
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
with gr.Blocks() as demo:
|
| 20 |
+
gr.Markdown("<h1 style='text-align: center;'>🔊 Voice Restoration with Transformer-based Model</h1>")
|
| 21 |
+
gr.Markdown(
|
| 22 |
+
"""
|
| 23 |
+
<p style='text-align: center;'>Upload a degraded audio file or select an example, and the space will restore it using the <b>VoiceRestore</b> model!<br>
|
| 24 |
+
Based on this <a href='https://github.com/skirdey/voicerestore' target='_blank'>repo</a> by @StanKirdey,<br>
|
| 25 |
+
and the HF Transformers model by <a href='https://github.com/jadechoghari' target='_blank'>@jadechoghari</a>.
|
| 26 |
+
</p>
|
| 27 |
+
"""
|
| 28 |
+
)
|
| 29 |
+
|
| 30 |
+
with gr.Row():
|
| 31 |
+
with gr.Column():
|
| 32 |
+
gr.Markdown("### 🎧 Select an Example or Upload Your Audio:")
|
| 33 |
+
input_audio = gr.Audio(label="Upload Degraded Audio", type="filepath")
|
| 34 |
+
gr.Examples(
|
| 35 |
+
examples=["example1.wav", "example2.wav", "example3.wav"],
|
| 36 |
+
inputs=input_audio,
|
| 37 |
+
label="Sample Degraded Audios"
|
| 38 |
+
)
|
| 39 |
+
|
| 40 |
+
with gr.Column():
|
| 41 |
+
gr.Markdown("### 🎶 Restored Audio Output:")
|
| 42 |
+
output_audio = gr.Audio(label="Restored Audio", type="filepath")
|
| 43 |
+
|
| 44 |
+
with gr.Row():
|
| 45 |
+
restore_btn = gr.Button("✨ Restore Audio")
|
| 46 |
+
|
| 47 |
+
# Connect the button to the function
|
| 48 |
+
restore_btn.click(restore_audio, inputs=input_audio, outputs=output_audio)
|
| 49 |
+
|
| 50 |
+
# Launch the demo
|
| 51 |
+
demo.launch(debug=True)
|