Update webui.py
Browse files
webui.py
CHANGED
|
@@ -1,33 +1,31 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
import subprocess
|
| 3 |
import os
|
|
|
|
|
|
|
|
|
|
| 4 |
|
| 5 |
def audio_model_inference(files, output_folder, model_path, denoise, margin, chunks, n_fft, dim_t, dim_f):
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
result = subprocess.run(cmd, shell=True, capture_output=True, text=True)
|
| 27 |
-
|
| 28 |
-
# 检查命令是否成功执行
|
| 29 |
-
if result.returncode != 0:
|
| 30 |
-
return f"错误:{result.stderr}"
|
| 31 |
|
| 32 |
# 读取输出文件
|
| 33 |
vocals_file = f"{os.path.splitext(os.path.basename(files[0]))[0]}_vocals.wav"
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import subprocess
|
| 3 |
import os
|
| 4 |
+
import soundfile as sf
|
| 5 |
+
from pathlib import Path
|
| 6 |
+
import separate
|
| 7 |
|
| 8 |
def audio_model_inference(files, output_folder, model_path, denoise, margin, chunks, n_fft, dim_t, dim_f):
|
| 9 |
+
filename = files.split('/')[-1]
|
| 10 |
+
# 执行调用
|
| 11 |
+
audio_worker = separate.Predictor(args={
|
| 12 |
+
"files": [files],
|
| 13 |
+
"output": Path(output_folder),
|
| 14 |
+
"model_path": Path(model_path),
|
| 15 |
+
"denoise": denoise,
|
| 16 |
+
"margin": margin,
|
| 17 |
+
"chunks": chunks,
|
| 18 |
+
"n_fft": n_fft,
|
| 19 |
+
"dim_t": dim_t,
|
| 20 |
+
"dim_f": dim_f
|
| 21 |
+
})
|
| 22 |
+
vocals, no_vocals, sampling_rate = audio_worker.predict(files)
|
| 23 |
+
sf.write(os.path.join(output_folder, mp3_filename + "_no_vocals.wav"), no_vocals, sampling_rate)
|
| 24 |
+
sf.write(os.path.join(output_folder, mp3_filename + "_vocals.wav"), vocals, sampling_rate)
|
| 25 |
+
|
| 26 |
+
# 生成分离后的文件名
|
| 27 |
+
vocals_filename = f"{os.path.splitext(filename)[0]}_vocals.wav"
|
| 28 |
+
no_vocals_filename = f"{os.path.splitext(filename)[0]}_no_vocals.wav"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 29 |
|
| 30 |
# 读取输出文件
|
| 31 |
vocals_file = f"{os.path.splitext(os.path.basename(files[0]))[0]}_vocals.wav"
|