Spaces:
Running
on
Zero
Running
on
Zero
add zero gpu decorations and examples
Browse files- gradio_app.py +14 -1
gradio_app.py
CHANGED
|
@@ -5,6 +5,7 @@ import torchaudio
|
|
| 5 |
import torchaudio.transforms as T
|
| 6 |
import soundfile as sf
|
| 7 |
import gradio as gr
|
|
|
|
| 8 |
import look2hear.models
|
| 9 |
|
| 10 |
# Setup device
|
|
@@ -21,6 +22,7 @@ TARGET_SR = 16000
|
|
| 21 |
MAX_SPEAKERS = 4
|
| 22 |
|
| 23 |
# --- DnR Function ---
|
|
|
|
| 24 |
def separate_dnr(audio_file):
|
| 25 |
audio, sr = torchaudio.load(audio_file)
|
| 26 |
audio = audio.to(device)
|
|
@@ -44,6 +46,7 @@ def separate_dnr(audio_file):
|
|
| 44 |
return dialog_path, effect_path, music_path
|
| 45 |
|
| 46 |
# --- Speaker Separation Function ---
|
|
|
|
| 47 |
def separate_speakers(audio_path):
|
| 48 |
waveform, original_sr = torchaudio.load(audio_path)
|
| 49 |
if original_sr != TARGET_SR:
|
|
@@ -80,7 +83,7 @@ def separate_speakers(audio_path):
|
|
| 80 |
|
| 81 |
# --- Gradio App ---
|
| 82 |
with gr.Blocks() as demo:
|
| 83 |
-
gr.Markdown("#
|
| 84 |
|
| 85 |
with gr.Tabs():
|
| 86 |
# --- Tab 1: DnR ---
|
|
@@ -90,6 +93,11 @@ with gr.Blocks() as demo:
|
|
| 90 |
dnr_input = gr.Audio(type="filepath", label="Upload Audio File")
|
| 91 |
dnr_button = gr.Button("Separate Audio")
|
| 92 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 93 |
dnr_output_dialog = gr.Audio(label="Dialog", type="filepath")
|
| 94 |
dnr_output_effect = gr.Audio(label="Effects", type="filepath")
|
| 95 |
dnr_output_music = gr.Audio(label="Music", type="filepath")
|
|
@@ -107,6 +115,11 @@ with gr.Blocks() as demo:
|
|
| 107 |
sep_input = gr.Audio(type="filepath", label="Upload Speech Audio")
|
| 108 |
sep_button = gr.Button("Separate Speakers")
|
| 109 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 110 |
gr.Markdown("#### Separated Speakers")
|
| 111 |
sep_outputs = []
|
| 112 |
for i in range(MAX_SPEAKERS):
|
|
|
|
| 5 |
import torchaudio.transforms as T
|
| 6 |
import soundfile as sf
|
| 7 |
import gradio as gr
|
| 8 |
+
import spaces
|
| 9 |
import look2hear.models
|
| 10 |
|
| 11 |
# Setup device
|
|
|
|
| 22 |
MAX_SPEAKERS = 4
|
| 23 |
|
| 24 |
# --- DnR Function ---
|
| 25 |
+
@spaces.GPU()
|
| 26 |
def separate_dnr(audio_file):
|
| 27 |
audio, sr = torchaudio.load(audio_file)
|
| 28 |
audio = audio.to(device)
|
|
|
|
| 46 |
return dialog_path, effect_path, music_path
|
| 47 |
|
| 48 |
# --- Speaker Separation Function ---
|
| 49 |
+
@spaces.GPU()
|
| 50 |
def separate_speakers(audio_path):
|
| 51 |
waveform, original_sr = torchaudio.load(audio_path)
|
| 52 |
if original_sr != TARGET_SR:
|
|
|
|
| 83 |
|
| 84 |
# --- Gradio App ---
|
| 85 |
with gr.Blocks() as demo:
|
| 86 |
+
gr.Markdown("# TIGER: Time-frequency Interleaved Gain Extraction and Reconstruction for Efficient Speech Separation")
|
| 87 |
|
| 88 |
with gr.Tabs():
|
| 89 |
# --- Tab 1: DnR ---
|
|
|
|
| 93 |
dnr_input = gr.Audio(type="filepath", label="Upload Audio File")
|
| 94 |
dnr_button = gr.Button("Separate Audio")
|
| 95 |
|
| 96 |
+
gr.Examples(
|
| 97 |
+
examples = ["./test/test_mixture_466.wav"],
|
| 98 |
+
inputs = dnr_input
|
| 99 |
+
)
|
| 100 |
+
|
| 101 |
dnr_output_dialog = gr.Audio(label="Dialog", type="filepath")
|
| 102 |
dnr_output_effect = gr.Audio(label="Effects", type="filepath")
|
| 103 |
dnr_output_music = gr.Audio(label="Music", type="filepath")
|
|
|
|
| 115 |
sep_input = gr.Audio(type="filepath", label="Upload Speech Audio")
|
| 116 |
sep_button = gr.Button("Separate Speakers")
|
| 117 |
|
| 118 |
+
gr.Examples(
|
| 119 |
+
examples = ["./test/mix.wav"],
|
| 120 |
+
inputs = sep_input
|
| 121 |
+
)
|
| 122 |
+
|
| 123 |
gr.Markdown("#### Separated Speakers")
|
| 124 |
sep_outputs = []
|
| 125 |
for i in range(MAX_SPEAKERS):
|