Spaces:
Runtime error
Runtime error
File size: 1,480 Bytes
c47462a | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 | import os
import tempfile
import subprocess
import gradio as gr
import spaces
MODEL_NAME = "htdemucs"
@spaces.GPU(duration=120)
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() |