Spleeter / app.py
shethjenil's picture
Update app.py
63efc13 verified
raw
history blame
844 Bytes
from spleeter import Splitter
import torchaudio
from torchaudio.transforms import Resample
import torch
import gradio as gr
def separate(inst,audio_path,progress=gr.Progress(True)):
model = Splitter(inst)
wav, sr = torchaudio.load(audio_path)
target_sr = 44100
if sr != target_sr:
resampler = Resample(sr, target_sr)
wav = resampler(wav)
sr = target_sr
with torch.no_grad():
results = model.forward(wav)
for i in results:
torchaudio.save(f"{i}.mp3", results[i], sr,format="mp3")
return tuple([i+".mp3" for i in results] + [None for _ in range(5-len(results))])
gr.Interface(separate, gr.Dropdown([2,4,5]),gr.Audio(type="filepath"), [gr.Audio(type="filepath"), gr.Audio(type="filepath"),gr.Audio(type="filepath"),gr.Audio(type="filepath"),gr.Audio(type="filepath")]).launch()