Commit
·
4c06cf0
1
Parent(s):
374fe66
add instrumental stem
Browse files
app.py
CHANGED
|
@@ -22,7 +22,7 @@ model_card = ModelCard(
|
|
| 22 |
|
| 23 |
|
| 24 |
DEMUX_MODELS = ["mdx_extra_q", "mdx_extra", "htdemucs", "mdx_q"]
|
| 25 |
-
STEM_NAMES = ["Drums", "Bass", "
|
| 26 |
|
| 27 |
# Global model cache
|
| 28 |
LOADED_MODELS = {}
|
|
@@ -61,17 +61,22 @@ def separate_all_stems(audio_file_path: str, model_name: str):
|
|
| 61 |
signal = AudioSignal(stem.cpu().numpy().astype("float32"), sample_rate=sr)
|
| 62 |
output_signals.append(signal)
|
| 63 |
|
| 64 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 65 |
|
| 66 |
# Process Function
|
| 67 |
-
@spaces.GPU
|
| 68 |
def process_fn(audio_file_path, model_name):
|
| 69 |
output_signals = separate_all_stems(audio_file_path, model_name)
|
|
|
|
| 70 |
outputs = []
|
| 71 |
for stem_name, signal in zip(STEM_NAMES, output_signals):
|
| 72 |
-
filename = f"demucs_{model_name}_{stem_name.lower()}.wav"
|
| 73 |
output_audio_path = save_audio(signal, filename)
|
| 74 |
outputs.append(output_audio_path)
|
|
|
|
| 75 |
return tuple(outputs)
|
| 76 |
|
| 77 |
# Gradio App
|
|
@@ -87,9 +92,9 @@ with gr.Blocks() as demo:
|
|
| 87 |
# Outputs: Multiple stems
|
| 88 |
output_drums = gr.Audio(type="filepath", label="Drums")
|
| 89 |
output_bass = gr.Audio(type="filepath", label="Bass")
|
| 90 |
-
output_other = gr.Audio(type="filepath", label="Other")
|
| 91 |
output_vocals = gr.Audio(type="filepath", label="Vocals")
|
| 92 |
-
|
|
|
|
| 93 |
|
| 94 |
app = build_endpoint(
|
| 95 |
model_card=model_card,
|
|
@@ -97,8 +102,8 @@ with gr.Blocks() as demo:
|
|
| 97 |
output_components=[
|
| 98 |
output_drums,
|
| 99 |
output_bass,
|
| 100 |
-
|
| 101 |
-
|
| 102 |
],
|
| 103 |
process_fn=process_fn
|
| 104 |
)
|
|
|
|
| 22 |
|
| 23 |
|
| 24 |
DEMUX_MODELS = ["mdx_extra_q", "mdx_extra", "htdemucs", "mdx_q"]
|
| 25 |
+
STEM_NAMES = ["Drums", "Bass", "Vocals", "Instrumental (No Vocals)"]
|
| 26 |
|
| 27 |
# Global model cache
|
| 28 |
LOADED_MODELS = {}
|
|
|
|
| 61 |
signal = AudioSignal(stem.cpu().numpy().astype("float32"), sample_rate=sr)
|
| 62 |
output_signals.append(signal)
|
| 63 |
|
| 64 |
+
# Combine drums + bass + other = instrumental
|
| 65 |
+
drums, bass, other, vocals = output_signals
|
| 66 |
+
instrumental = drums + bass + other
|
| 67 |
+
|
| 68 |
+
return [drums, bass, vocals, instrumental]
|
| 69 |
|
| 70 |
# Process Function
|
|
|
|
| 71 |
def process_fn(audio_file_path, model_name):
|
| 72 |
output_signals = separate_all_stems(audio_file_path, model_name)
|
| 73 |
+
|
| 74 |
outputs = []
|
| 75 |
for stem_name, signal in zip(STEM_NAMES, output_signals):
|
| 76 |
+
filename = f"demucs_{model_name}_{stem_name.lower().replace(' ', '_')}.wav"
|
| 77 |
output_audio_path = save_audio(signal, filename)
|
| 78 |
outputs.append(output_audio_path)
|
| 79 |
+
|
| 80 |
return tuple(outputs)
|
| 81 |
|
| 82 |
# Gradio App
|
|
|
|
| 92 |
# Outputs: Multiple stems
|
| 93 |
output_drums = gr.Audio(type="filepath", label="Drums")
|
| 94 |
output_bass = gr.Audio(type="filepath", label="Bass")
|
|
|
|
| 95 |
output_vocals = gr.Audio(type="filepath", label="Vocals")
|
| 96 |
+
output_instrumental = gr.Audio(type="filepath", label="Instrumental (No Vocals)")
|
| 97 |
+
#output_labels = gr.JSON(label="Labels")
|
| 98 |
|
| 99 |
app = build_endpoint(
|
| 100 |
model_card=model_card,
|
|
|
|
| 102 |
output_components=[
|
| 103 |
output_drums,
|
| 104 |
output_bass,
|
| 105 |
+
output_vocals,
|
| 106 |
+
output_instrumental
|
| 107 |
],
|
| 108 |
process_fn=process_fn
|
| 109 |
)
|