Spaces:
Runtime error
Runtime error
File size: 1,743 Bytes
c56a4ac 8219f10 9f666f6 c56a4ac ca128e7 b8e4d8f c56a4ac fb25e22 ca128e7 fb25e22 ca128e7 fb25e22 ca128e7 c56a4ac cf9f7d3 b37ad8a c56a4ac cf9f7d3 c56a4ac 4f00ee3 9e1a108 c56a4ac cf9f7d3 c56a4ac |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
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=}")
os.makedirs(gradio_temp_path + f"/separated_audio/{audio_filename}/", exist_ok=True)
command = f"spleeter separate -p spleeter:{stem_count}stems {audio_path} -o {gradio_temp_path}/separated_audio/"
command = command.split()
print(f"{command=}")
result = subprocess.run(command)
print(result)
paths = []
if stem_count == 2:
paths.append(gradio_temp_path + f"/separated_audio/{audio_filename}/accompaniment.wav")
paths.append(gradio_temp_path + f"/separated_audio/{audio_filename}/vocals.wav")
elif stem_count == 4 or stem_count == 5:
paths.append(gradio_temp_path + f"/separated_audio/{audio_filename}/vocals.wav")
paths.append(gradio_temp_path + f"/separated_audio/{audio_filename}/drums.wav")
paths.append(gradio_temp_path + f"/separated_audio/{audio_filename}/bass.wav")
paths.append(gradio_temp_path + f"/separated_audio/{audio_filename}/other.wav")
if stem_count == 5:
paths.append(gradio_temp_path + f"/separated_audio/{audio_filename}/piano.wav")
# Return the audio file paths as a list of Audio components
return [gr.Audio(path) for path in paths]
# Define the Gradio interface
iface = gr.Interface(
fn=separate_audio,
inputs=[gr.Audio(type="filepath"), 2],
outputs=[gr.Audio(label='Accompaniment'), gr.Audio(label='Vocals')]
)
# Launch the interface
iface.launch()
|