Update app.py
Browse files6 unmodified lines789101112134 unmodified lines18192021222324252627282930315 unmodified lines37383940414243446 unmodified linesfrom demucs.pretrained import get_modelfrom demucs.apply import apply_model# Load the Demucs modelmodel = get_model("htdemucs")model.cpu()model.eval()4 unmodified linesif y.ndim == 1:y = np.expand_dims(y, axis=0)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]# 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# Save outputout_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)")interface.launch()6 unmodified lines789101112134 unmodified lines18192021222324252627282930315 unmodified lines37383940414243446 unmodified linesfrom demucs.pretrained import get_modelfrom demucs.apply import apply_model# Load Demucs model (htdemucs is good for vocals removal)model = get_model("htdemucs")model.cpu()model.eval()4 unmodified linesif y.ndim == 1:y = np.expand_dims(y, axis=0)audio_tensor = torch.tensor(y).unsqueeze(0) # shape: (1, channels, samples)with torch.no_grad():# Demucs separates: [drums, bass, other, vocals, remix]sources = apply_model(model, audio_tensor)# Keep music + expression sounds (everything except clean vocals)music_expression = sources[0][[0,1,2]].sum(dim=0) # drums + bass + other# Save outputout_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="Music + Expression Sounds"),title="Vocal Remover: Keep Music + Expression Sounds")interface.launch()
app.py+8-8