next-playground's picture
Create webui.py
a37cef9 verified
raw
history blame
2.45 kB
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)
# Gradio 界面组件
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()