Spaces:
Running
Running
| import gradio as gr | |
| from spleeter.separator import Separator | |
| import os | |
| # Initialize Spleeter with the 5stems model (for vocals, harmony, adlibs, etc.) | |
| separator = Separator('spleeter:5stems') | |
| # Function to separate the audio into vocals, harmony, ad-libs, and accompaniment | |
| def separate_vocals(input_audio): | |
| output_dir = "output" | |
| if not os.path.exists(output_dir): | |
| os.makedirs(output_dir) | |
| # Path for the uploaded audio file | |
| audio_path = input_audio.name | |
| separated_path = os.path.join(output_dir, 'separated') | |
| # Separate the audio file | |
| separator.separate(audio_path) | |
| # Paths for the separated tracks | |
| main_vocal_file = os.path.join(separated_path, 'vocals.wav') | |
| harmony_vocal_file = os.path.join(separated_path, 'harmonics.wav') | |
| adlib_vocal_file = os.path.join(separated_path, 'adlibs.wav') | |
| accompaniment_file = os.path.join(separated_path, 'accompaniment.wav') | |
| # Return the separated files | |
| return main_vocal_file, harmony_vocal_file, adlib_vocal_file, accompaniment_file | |
| # Gradio interface setup | |
| def create_interface(): | |
| with gr.Blocks() as demo: | |
| with gr.Row(): | |
| audio_input = gr.Audio(label="Upload Audio File", type="file") | |
| main_vocal_output = gr.Audio(label="Main Vocals", type="file", interactive=False) | |
| harmony_vocal_output = gr.Audio(label="Harmony Vocals", type="file", interactive=False) | |
| adlib_vocal_output = gr.Audio(label="Ad-lib Vocals", type="file", interactive=False) | |
| accompaniment_output = gr.Audio(label="Accompaniment", type="file", interactive=False) | |
| # When the audio file is uploaded, separate the audio and return the files | |
| audio_input.change(separate_vocals, inputs=audio_input, outputs=[main_vocal_output, harmony_vocal_output, adlib_vocal_output, accompaniment_output]) | |
| demo.launch() | |
| # Run the Gradio interface | |
| create_interface() | |