File size: 844 Bytes
63efc13
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
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()