Spaces:
Runtime error
Runtime error
import gradio as gr | |
import os | |
import random | |
import subprocess | |
def separate_audio(audio_path, stem_count): | |
print(f"{audio_path=}") | |
head, tail = os.path.split(audio_path) | |
gradio_temp_path = head | |
audio_filename = tail.split('.')[0] | |
print(f"{gradio_temp_path=}") | |
print(f"{audio_filename=}") | |
print(f"{stem_count=}") | |
command = f"spleeter separate -p spleeter:{stem_count}stems {audio_path}" | |
command = command.split() | |
print(f"{command=}") | |
result = subprocess.run(command) | |
print(result) | |
randomnumber = str(random.randint(111111111, 999999999)) | |
paths = [] | |
if stem_count == 2: | |
paths.append(('Accompaniment', f"{gradio_temp_path}/separated_audio/{randomnumber}/accompaniment.wav")) | |
paths.append(('Vocals', f"{gradio_temp_path}/separated_audio/{randomnumber}/vocals.wav")) | |
elif stem_count == 4 or stem_count == 5: | |
paths.append(('Vocals', f"{gradio_temp_path}/separated_audio/{randomnumber}/vocals.wav")) | |
paths.append(('Drums', f"{gradio_temp_path}/separated_audio/{randomnumber}/drums.wav")) | |
paths.append(('Bass', f"{gradio_temp_path}/separated_audio/{randomnumber}/bass.wav")) | |
paths.append(('Other', f"{gradio_temp_path}/separated_audio/{randomnumber}/other.wav")) | |
if stem_count == 5: | |
paths.append(('Piano', f"{gradio_temp_path}/separated_audio/{randomnumber}/piano.wav")) | |
return paths | |
iface = gr.Interface( | |
fn=separate_audio, | |
inputs=[gr.Audio(type="filepath"), gr.Radio([2, 4, 5])], | |
outputs="text", | |
) | |
iface.launch() | |