Spaces:
Sleeping
Sleeping
Commit
·
208fe80
1
Parent(s):
5527c63
correct separation step
Browse files
app.py
CHANGED
|
@@ -8,10 +8,6 @@ from typing import Dict
|
|
| 8 |
from pyharp import *
|
| 9 |
|
| 10 |
|
| 11 |
-
# ---------------------------
|
| 12 |
-
# Config
|
| 13 |
-
# ---------------------------
|
| 14 |
-
|
| 15 |
DEMUX_MODELS = ["mdx_extra_q", "mdx_extra", "htdemucs", "mdx_q"]
|
| 16 |
|
| 17 |
STEM_CHOICES = {
|
|
@@ -22,9 +18,6 @@ STEM_CHOICES = {
|
|
| 22 |
"Instrumental (No Vocals)": "instrumental"
|
| 23 |
}
|
| 24 |
|
| 25 |
-
# ---------------------------
|
| 26 |
-
# Stem Separation Logic
|
| 27 |
-
# ---------------------------
|
| 28 |
|
| 29 |
def separate_stem(audio_file_path: str, model_name: str, stem_choice: str) -> AudioSignal:
|
| 30 |
model = pretrained.get_model(model_name)
|
|
@@ -58,26 +51,20 @@ def separate_stem(audio_file_path: str, model_name: str, stem_choice: str) -> Au
|
|
| 58 |
|
| 59 |
return AudioSignal(stem.cpu().numpy().astype('float32'), sample_rate=sr)
|
| 60 |
|
| 61 |
-
# ---------------------------
|
| 62 |
# Gradio Callback Function
|
| 63 |
-
# ---------------------------
|
| 64 |
|
| 65 |
-
def process_fn_stem(audio_file_path: str, demucs_model: str, stem_choice: str)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 66 |
stem_signal = separate_stem(audio_file_path, model_name=demucs_model, stem_choice=stem_choice)
|
| 67 |
-
|
| 68 |
-
stem_path =
|
| 69 |
-
|
| 70 |
-
return {
|
| 71 |
-
"file": stem_path,
|
| 72 |
-
"stem": stem_choice,
|
| 73 |
-
"description": f"Separated {stem_choice} stem",
|
| 74 |
-
"amplitude": 0.7
|
| 75 |
-
}
|
| 76 |
|
| 77 |
-
# ---------------------------
|
| 78 |
-
# Model Card (for HARP)
|
| 79 |
-
# ---------------------------
|
| 80 |
|
|
|
|
| 81 |
model_card = ModelCard(
|
| 82 |
name="Demucs Stem Separator",
|
| 83 |
description="Uses Demucs to separate a music track into a selected stem.",
|
|
@@ -85,10 +72,7 @@ model_card = ModelCard(
|
|
| 85 |
tags=["demucs", "source-separation", "pyharp", "stems"]
|
| 86 |
)
|
| 87 |
|
| 88 |
-
#
|
| 89 |
-
# Gradio Interface (Blocks)
|
| 90 |
-
# ---------------------------
|
| 91 |
-
|
| 92 |
with gr.Blocks() as demo:
|
| 93 |
gr.Markdown("# 🎧 Demucs Stem Separator")
|
| 94 |
gr.Markdown("Log in with your Hugging Face account to separate music into stems.")
|
|
|
|
| 8 |
from pyharp import *
|
| 9 |
|
| 10 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
DEMUX_MODELS = ["mdx_extra_q", "mdx_extra", "htdemucs", "mdx_q"]
|
| 12 |
|
| 13 |
STEM_CHOICES = {
|
|
|
|
| 18 |
"Instrumental (No Vocals)": "instrumental"
|
| 19 |
}
|
| 20 |
|
|
|
|
|
|
|
|
|
|
| 21 |
|
| 22 |
def separate_stem(audio_file_path: str, model_name: str, stem_choice: str) -> AudioSignal:
|
| 23 |
model = pretrained.get_model(model_name)
|
|
|
|
| 51 |
|
| 52 |
return AudioSignal(stem.cpu().numpy().astype('float32'), sample_rate=sr)
|
| 53 |
|
|
|
|
| 54 |
# Gradio Callback Function
|
|
|
|
| 55 |
|
| 56 |
+
def process_fn_stem(audio_file_path: str, demucs_model: str, stem_choice: str):
|
| 57 |
+
"""
|
| 58 |
+
PyHARP process function:
|
| 59 |
+
- Separates the chosen stem using Demucs.
|
| 60 |
+
- Saves the stem as a .wav file.
|
| 61 |
+
"""
|
| 62 |
stem_signal = separate_stem(audio_file_path, model_name=demucs_model, stem_choice=stem_choice)
|
| 63 |
+
stem_path = save_audio(stem_signal, f"{stem_choice.lower().replace(' ', '_')}.wav")
|
| 64 |
+
return stem_path, LabelList(labels=[])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 65 |
|
|
|
|
|
|
|
|
|
|
| 66 |
|
| 67 |
+
# Model Card
|
| 68 |
model_card = ModelCard(
|
| 69 |
name="Demucs Stem Separator",
|
| 70 |
description="Uses Demucs to separate a music track into a selected stem.",
|
|
|
|
| 72 |
tags=["demucs", "source-separation", "pyharp", "stems"]
|
| 73 |
)
|
| 74 |
|
| 75 |
+
# Gradio UI
|
|
|
|
|
|
|
|
|
|
| 76 |
with gr.Blocks() as demo:
|
| 77 |
gr.Markdown("# 🎧 Demucs Stem Separator")
|
| 78 |
gr.Markdown("Log in with your Hugging Face account to separate music into stems.")
|