Update app.py
Browse files
app.py
CHANGED
|
@@ -7,7 +7,7 @@ import tempfile
|
|
| 7 |
from demucs.pretrained import get_model
|
| 8 |
from demucs.apply import apply_model
|
| 9 |
|
| 10 |
-
# Load
|
| 11 |
model = get_model("htdemucs")
|
| 12 |
model.cpu()
|
| 13 |
model.eval()
|
|
@@ -18,14 +18,14 @@ def remove_vocals(audio_file):
|
|
| 18 |
if y.ndim == 1:
|
| 19 |
y = np.expand_dims(y, axis=0)
|
| 20 |
|
| 21 |
-
audio_tensor = torch.tensor(y).unsqueeze(0) # shape (1, channels, samples)
|
| 22 |
|
| 23 |
with torch.no_grad():
|
| 24 |
-
|
|
|
|
| 25 |
|
| 26 |
-
#
|
| 27 |
-
|
| 28 |
-
music_expression = sources[0][[0,1,2]].sum(dim=0) # drums+bass+other
|
| 29 |
|
| 30 |
# Save output
|
| 31 |
out_path = tempfile.NamedTemporaryFile(delete=False, suffix=".wav").name
|
|
@@ -37,8 +37,8 @@ def remove_vocals(audio_file):
|
|
| 37 |
interface = gr.Interface(
|
| 38 |
fn=remove_vocals,
|
| 39 |
inputs=gr.Audio(type="filepath", label="Upload Audio"),
|
| 40 |
-
outputs=gr.Audio(label="
|
| 41 |
-
title="Vocal Remover
|
| 42 |
)
|
| 43 |
|
| 44 |
interface.launch()
|
|
|
|
| 7 |
from demucs.pretrained import get_model
|
| 8 |
from demucs.apply import apply_model
|
| 9 |
|
| 10 |
+
# Load Demucs model (htdemucs is good for vocals removal)
|
| 11 |
model = get_model("htdemucs")
|
| 12 |
model.cpu()
|
| 13 |
model.eval()
|
|
|
|
| 18 |
if y.ndim == 1:
|
| 19 |
y = np.expand_dims(y, axis=0)
|
| 20 |
|
| 21 |
+
audio_tensor = torch.tensor(y).unsqueeze(0) # shape: (1, channels, samples)
|
| 22 |
|
| 23 |
with torch.no_grad():
|
| 24 |
+
# Demucs separates: [drums, bass, other, vocals, remix]
|
| 25 |
+
sources = apply_model(model, audio_tensor)
|
| 26 |
|
| 27 |
+
# Keep music + expression sounds (everything except clean vocals)
|
| 28 |
+
music_expression = sources[0][[0,1,2]].sum(dim=0) # drums + bass + other
|
|
|
|
| 29 |
|
| 30 |
# Save output
|
| 31 |
out_path = tempfile.NamedTemporaryFile(delete=False, suffix=".wav").name
|
|
|
|
| 37 |
interface = gr.Interface(
|
| 38 |
fn=remove_vocals,
|
| 39 |
inputs=gr.Audio(type="filepath", label="Upload Audio"),
|
| 40 |
+
outputs=gr.Audio(label="Music + Expression Sounds"),
|
| 41 |
+
title="Vocal Remover: Keep Music + Expression Sounds"
|
| 42 |
)
|
| 43 |
|
| 44 |
interface.launch()
|