Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,10 +1,5 @@
|
|
| 1 |
import torch
|
| 2 |
import torchaudio
|
| 3 |
-
import numpy as np
|
| 4 |
-
import scipy
|
| 5 |
-
import stempeg
|
| 6 |
-
import os
|
| 7 |
-
from openunmix import predict
|
| 8 |
import gradio as gr
|
| 9 |
import stempeg
|
| 10 |
|
|
@@ -13,36 +8,32 @@ torch.hub.download_url_to_file('https://github.com/AK391/open-unmix-pytorch/blob
|
|
| 13 |
use_cuda = torch.cuda.is_available()
|
| 14 |
device = torch.device("cuda" if use_cuda else "cpu")
|
| 15 |
|
|
|
|
|
|
|
| 16 |
|
| 17 |
def inference(audio):
|
| 18 |
-
start = 0
|
| 19 |
-
stop = 7
|
| 20 |
audio, rate = stempeg.read_stems(
|
| 21 |
-
audio
|
| 22 |
-
sample_rate=44100
|
| 23 |
-
start=start,
|
| 24 |
-
duration=stop-start,
|
| 25 |
-
)
|
| 26 |
-
estimates = predict.separate(
|
| 27 |
-
audio=torch.as_tensor(audio).float(),
|
| 28 |
-
rate=44100,
|
| 29 |
-
device=device,
|
| 30 |
)
|
| 31 |
-
|
|
|
|
|
|
|
|
|
|
| 32 |
|
| 33 |
estimates_numpy = {}
|
| 34 |
for target, estimate in estimates.items():
|
| 35 |
estimates_numpy[target] = torch.squeeze(estimate).detach().cpu().numpy().T
|
| 36 |
-
|
| 37 |
stempeg.write_stems(
|
| 38 |
target_path,
|
| 39 |
estimates_numpy,
|
| 40 |
sample_rate=rate,
|
| 41 |
writer=stempeg.FilesWriter(multiprocess=True, output_sample_rate=44100),
|
| 42 |
)
|
| 43 |
-
return 'vocals.wav', 'drums.wav', 'bass.wav', 'other.wav'
|
| 44 |
|
| 45 |
-
inputs = gr.inputs.Audio(label="Input Audio", type="
|
| 46 |
outputs = [gr.outputs.Audio(label="Vocals", type="file"),
|
| 47 |
gr.outputs.Audio(label="Drums", type="file"),
|
| 48 |
gr.outputs.Audio(label="Bass", type="file"),
|
|
@@ -55,4 +46,4 @@ article = "<p style='text-align: center'><a href='https://joss.theoj.org/papers/
|
|
| 55 |
|
| 56 |
examples = [['test.wav']]
|
| 57 |
|
| 58 |
-
gr.Interface(inference, inputs, outputs, title=title, description=description, article=article, examples=examples).launch(
|
|
|
|
| 1 |
import torch
|
| 2 |
import torchaudio
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
import gradio as gr
|
| 4 |
import stempeg
|
| 5 |
|
|
|
|
| 8 |
use_cuda = torch.cuda.is_available()
|
| 9 |
device = torch.device("cuda" if use_cuda else "cpu")
|
| 10 |
|
| 11 |
+
# loading umxhq four target separator
|
| 12 |
+
separator = torch.hub.load('sigsep/open-unmix-pytorch', 'umxhq')
|
| 13 |
|
| 14 |
def inference(audio):
|
|
|
|
|
|
|
| 15 |
audio, rate = stempeg.read_stems(
|
| 16 |
+
audio,
|
| 17 |
+
sample_rate=44100
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
)
|
| 19 |
+
audio = torch.as_tensor(audio).float().T
|
| 20 |
+
audio = audio[None]
|
| 21 |
+
estimates = separator(audio)
|
| 22 |
+
estimates = separator.to_dict(estimates)
|
| 23 |
|
| 24 |
estimates_numpy = {}
|
| 25 |
for target, estimate in estimates.items():
|
| 26 |
estimates_numpy[target] = torch.squeeze(estimate).detach().cpu().numpy().T
|
| 27 |
+
target_path = str("target.wav")
|
| 28 |
stempeg.write_stems(
|
| 29 |
target_path,
|
| 30 |
estimates_numpy,
|
| 31 |
sample_rate=rate,
|
| 32 |
writer=stempeg.FilesWriter(multiprocess=True, output_sample_rate=44100),
|
| 33 |
)
|
| 34 |
+
return 'vocals.wav', 'drums.wav', 'bass.wav', 'other.wav'
|
| 35 |
|
| 36 |
+
inputs = gr.inputs.Audio(label="Input Audio", type="filepath")
|
| 37 |
outputs = [gr.outputs.Audio(label="Vocals", type="file"),
|
| 38 |
gr.outputs.Audio(label="Drums", type="file"),
|
| 39 |
gr.outputs.Audio(label="Bass", type="file"),
|
|
|
|
| 46 |
|
| 47 |
examples = [['test.wav']]
|
| 48 |
|
| 49 |
+
gr.Interface(inference, inputs, outputs, title=title, description=description, article=article, examples=examples, analytics_enabled=False).launch(debug=True)
|