|
import gradio as gr |
|
import subprocess |
|
import os |
|
|
|
def audio_model_inference(files, output_folder, model_path, denoise, margin, chunks, n_fft, dim_t, dim_f): |
|
|
|
cmd = f"separate.py {' '.join(files)}" |
|
if output_folder: |
|
cmd += f" -o {output_folder}" |
|
if model_path: |
|
cmd += f" -m {model_path}" |
|
if denoise: |
|
cmd += " -d" |
|
if margin: |
|
cmd += f" -M {margin}" |
|
if chunks: |
|
cmd += f" -c {chunks}" |
|
if n_fft: |
|
cmd += f" -F {n_fft}" |
|
if dim_t: |
|
cmd += f" -t {dim_t}" |
|
if dim_f: |
|
cmd += f" -f {dim_f}" |
|
|
|
|
|
result = subprocess.run(cmd, shell=True, capture_output=True, text=True) |
|
|
|
|
|
if result.returncode != 0: |
|
return f"Error: {result.stderr}" |
|
|
|
|
|
vocals_file = f"{os.path.splitext(os.path.basename(files[0]))[0]}_vocals.wav" |
|
no_vocals_file = f"{os.path.splitext(os.path.basename(files[0]))[0]}_no_vocals.wav" |
|
vocals_path = os.path.join(output_folder, vocals_file) |
|
no_vocals_path = os.path.join(output_folder, no_vocals_file) |
|
|
|
|
|
if not os.path.exists(vocals_path) or not os.path.exists(no_vocals_path): |
|
return "Error: Output files not found." |
|
|
|
|
|
vocals_audio = open(vocals_path, 'rb').read() |
|
no_vocals_audio = open(no_vocals_path, 'rb').read() |
|
|
|
return (vocals_audio, no_vocals_audio) |
|
|
|
|
|
inputs = [ |
|
gr.inputs.File(label="Source Audio Files", type='file', file_count='multiple'), |
|
gr.inputs.Textbox(label="Output Folder", default="output/"), |
|
gr.inputs.Textbox(label="Model Path", default="model.onnx"), |
|
gr.inputs.Checkbox(label="Enable Denoising", default=False), |
|
gr.inputs.Number(label="Margin", default=0.1), |
|
gr.inputs.Number(label="Chunk Size", default=1024), |
|
gr.inputs.Number(label="FFT Size", default=2048), |
|
gr.inputs.Number(label="Time Dimension", default=512), |
|
gr.inputs.Number(label="Frequency Dimension", default=64) |
|
] |
|
|
|
outputs = [gr.outputs.Audio(label="Vocals"), gr.outputs.Audio(label="No Vocals")] |
|
|
|
|
|
iface = gr.Interface( |
|
fn=audio_model_inference, |
|
inputs=inputs, |
|
outputs=outputs, |
|
title="Audio Separation Model", |
|
description="Upload audio files and configure parameters to process them using the audio separation model." |
|
) |
|
|
|
iface.launch() |
|
|