Spaces:
Runtime error
Runtime error
Download app.py from pbp1701/MasterSplitter: direct link, hf CLI and curl.
- Browser
- Download file 1.48 kB
-
https://huggingface.co/spaces/pbp1701/MasterSplitter/resolve/main/app.py
- Command line
-
hf download hf://spaces/pbp1701/MasterSplitter/app.py
-
curl -L -o app.py https://huggingface.co/spaces/pbp1701/MasterSplitter/resolve/main/app.py
1.48 kB
| import os | |
| import tempfile | |
| import subprocess | |
| import gradio as gr | |
| import spaces | |
| MODEL_NAME = "htdemucs" | |
| def separate_stems(audio_path): | |
| if audio_path is None: | |
| raise gr.Error("Please upload an audio file.") | |
| out_dir = tempfile.mkdtemp() | |
| cmd = ["python", "-m", "demucs.separate", "-n", MODEL_NAME, "-o", out_dir, audio_path] | |
| subprocess.run(cmd, check=True) | |
| track_name = os.path.splitext(os.path.basename(audio_path))[0] | |
| stems_dir = os.path.join(out_dir, MODEL_NAME, track_name) | |
| vocals = os.path.join(stems_dir, "vocals.wav") | |
| drums = os.path.join(stems_dir, "drums.wav") | |
| bass = os.path.join(stems_dir, "bass.wav") | |
| other = os.path.join(stems_dir, "other.wav") | |
| return vocals, drums, bass, other | |
| demo = gr.Interface( | |
| fn=separate_stems, | |
| inputs=gr.Audio(type="filepath", label="Input track"), | |
| outputs=[ | |
| gr.Audio(type="filepath", label="Vocals"), | |
| gr.Audio(type="filepath", label="Drums"), | |
| gr.Audio(type="filepath", label="Bass"), | |
| gr.Audio(type="filepath", label="Other"), | |
| ], | |
| title="MasterSplitter - Free Stem Separation", | |
| description="Upload a song to split it into vocals, drums, bass and other stems using Demucs.", | |
| api_name="split", | |
| ) | |
| demo.queue().launch() |