Update app.py
Browse files6 unmodified lines78910101112134 unmodified lines181920212122232424252626272827282930315 unmodified lines373839404140414243446 unmodified linesfrom demucs.pretrained import get_modelfrom demucs.apply import apply_model
# Load the Demucs model# Load Demucs model (htdemucs is good for vocals removal)model = get_model("htdemucs")model.cpu()model.eval()4 unmodified lines if y.ndim == 1: y = np.expand_dims(y, axis=0)
audio_tensor = torch.tensor(y).unsqueeze(0) # shape (1, channels, samples) audio_tensor = torch.tensor(y).unsqueeze(0) # shape: (1, channels, samples)
with torch.no_grad(): sources = apply_model(model, audio_tensor) # Demucs returns 5 sources: [drums, bass, other, vocals, remix] # Demucs separates: [drums, bass, other, vocals, remix] sources = apply_model(model, audio_tensor)
# Sources indices for htdemucs: 0-drums, 1-bass, 2-other, 3-vocals, 4-mix # We want music + expression (everything except clean vocals) music_expression = sources[0][[0,1,2]].sum(dim=0) # drums+bass+other # Keep music + expression sounds (everything except clean vocals) music_expression = sources[0][[0,1,2]].sum(dim=0) # drums + bass + other
# Save output out_path = tempfile.NamedTemporaryFile(delete=False, suffix=".wav").name5 unmodified linesinterface = gr.Interface( fn=remove_vocals, inputs=gr.Audio(type="filepath", label="Upload Audio"), outputs=gr.Audio(label="Background Music + Expressions"), title="Vocal Remover (Keep Music + Expressions)" outputs=gr.Audio(label="Music + Expression Sounds"), title="Vocal Remover: Keep Music + Expression Sounds")
interface.launch()app.py+8-8