next-playground commited on
Commit
c469af8
·
verified ·
1 Parent(s): 4648be3

Update webui.py

Browse files
Files changed (1) hide show
  1. webui.py +23 -25
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
- cmd = f"separate.py {' '.join(files)}"
8
- if output_folder:
9
- cmd += f" -o {output_folder}"
10
- if model_path:
11
- cmd += f" -m {model_path}"
12
- if denoise:
13
- cmd += " -d"
14
- if margin:
15
- cmd += f" -M {margin}"
16
- if chunks:
17
- cmd += f" -c {chunks}"
18
- if n_fft:
19
- cmd += f" -F {n_fft}"
20
- if dim_t:
21
- cmd += f" -t {dim_t}"
22
- if dim_f:
23
- cmd += f" -f {dim_f}"
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"