Marcis commited on
Commit
271c994
·
verified ·
1 Parent(s): ecfefe5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +1471 -270
app.py CHANGED
@@ -1,38 +1,136 @@
1
  import os
2
- import torch
 
3
 
4
- # os.system("wget -P cvec/ https://huggingface.co/lj1995/VoiceConversionWebUI/resolve/main/hubert_base.pt")
5
- import gradio as gr
6
- import librosa
 
 
 
 
 
 
 
 
 
 
 
 
7
  import numpy as np
8
- import logging
9
- from fairseq import checkpoint_utils
10
- from vc_infer_pipeline import VC
 
 
 
 
 
 
11
  import traceback
12
- from config import Config
13
- from lib.infer_pack.models import (
14
- SynthesizerTrnMs256NSFsid,
15
- SynthesizerTrnMs256NSFsid_nono,
16
- SynthesizerTrnMs768NSFsid,
17
- SynthesizerTrnMs768NSFsid_nono,
18
- )
19
- from i18n import I18nAuto
20
 
21
  logging.getLogger("numba").setLevel(logging.WARNING)
22
- logging.getLogger("markdown_it").setLevel(logging.WARNING)
23
- logging.getLogger("urllib3").setLevel(logging.WARNING)
24
- logging.getLogger("matplotlib").setLevel(logging.WARNING)
25
 
26
- i18n = I18nAuto()
27
- i18n.print()
 
 
 
 
 
 
 
 
 
 
 
28
 
29
  config = Config()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
30
 
31
- weight_root = "weights"
32
- weight_uvr5_root = "uvr5_weights"
33
- index_root = "logs"
34
  names = []
35
- hubert_model = None
36
  for name in os.listdir(weight_root):
37
  if name.endswith(".pth"):
38
  names.append(name)
@@ -41,181 +139,650 @@ for root, dirs, files in os.walk(index_root, topdown=False):
41
  for name in files:
42
  if name.endswith(".index") and "trained" not in name:
43
  index_paths.append("%s/%s" % (root, name))
 
 
 
 
44
 
45
 
46
- def get_vc(sid):
47
- global n_spk, tgt_sr, net_g, vc, cpt, version
48
- if sid == "" or sid == []:
49
- global hubert_model
50
- if hubert_model != None: # 考虑到轮询, 需要加个判断看是否 sid 是由有模型切换到无模型的
51
- print("clean_empty_cache")
52
- del net_g, n_spk, vc, hubert_model, tgt_sr # ,cpt
53
- hubert_model = net_g = n_spk = vc = hubert_model = tgt_sr = None
54
- if torch.cuda.is_available():
55
- torch.cuda.empty_cache()
56
- ###楼下不这么折腾清理不干净
57
- if_f0 = cpt.get("f0", 1)
58
- version = cpt.get("version", "v1")
59
- if version == "v1":
60
- if if_f0 == 1:
61
- net_g = SynthesizerTrnMs256NSFsid(
62
- *cpt["config"], is_half=config.is_half
63
- )
64
- else:
65
- net_g = SynthesizerTrnMs256NSFsid_nono(*cpt["config"])
66
- elif version == "v2":
67
- if if_f0 == 1:
68
- net_g = SynthesizerTrnMs768NSFsid(
69
- *cpt["config"], is_half=config.is_half
70
- )
71
- else:
72
- net_g = SynthesizerTrnMs768NSFsid_nono(*cpt["config"])
73
- del net_g, cpt
74
- if torch.cuda.is_available():
75
- torch.cuda.empty_cache()
76
- cpt = None
77
- return {"visible": False, "__type__": "update"}
78
- person = "%s/%s" % (weight_root, sid)
79
- print("loading %s" % person)
80
- cpt = torch.load(person, map_location="cpu")
81
- tgt_sr = cpt["config"][-1]
82
- cpt["config"][-3] = cpt["weight"]["emb_g.weight"].shape[0] # n_spk
83
- if_f0 = cpt.get("f0", 1)
84
- version = cpt.get("version", "v1")
85
- if version == "v1":
86
- if if_f0 == 1:
87
- net_g = SynthesizerTrnMs256NSFsid(*cpt["config"], is_half=config.is_half)
88
  else:
89
- net_g = SynthesizerTrnMs256NSFsid_nono(*cpt["config"])
90
- elif version == "v2":
91
- if if_f0 == 1:
92
- net_g = SynthesizerTrnMs768NSFsid(*cpt["config"], is_half=config.is_half)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
93
  else:
94
- net_g = SynthesizerTrnMs768NSFsid_nono(*cpt["config"])
95
- del net_g.enc_q
96
- print(net_g.load_state_dict(cpt["weight"], strict=False))
97
- net_g.eval().to(config.device)
98
- if config.is_half:
99
- net_g = net_g.half()
100
- else:
101
- net_g = net_g.float()
102
- vc = VC(tgt_sr, config)
103
- n_spk = cpt["config"][-3]
104
- return {"visible": True, "maximum": n_spk, "__type__": "update"}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
105
 
106
 
107
- def load_hubert():
108
- global hubert_model
109
- models, _, _ = checkpoint_utils.load_model_ensemble_and_task(
110
- ["hubert_base.pt"],
111
- suffix="",
 
 
 
112
  )
113
- hubert_model = models[0]
114
- hubert_model = hubert_model.to(config.device)
115
- if config.is_half:
116
- hubert_model = hubert_model.half()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
117
  else:
118
- hubert_model = hubert_model.float()
119
- hubert_model.eval()
120
-
121
-
122
- def vc_single(
123
- sid,
124
- input_audio_path,
125
- f0_up_key,
126
- f0_file,
127
- f0_method,
128
- file_index,
129
- file_index2,
130
- # file_big_npy,
131
- index_rate,
132
- filter_radius,
133
- resample_sr,
134
- rms_mix_rate,
135
- protect,
136
- ): # spk_item, input_audio0, vc_transform0,f0_file,f0method0
137
- global tgt_sr, net_g, vc, hubert_model, version
138
- if input_audio_path is None:
139
- return "You need to upload an audio", None
140
- f0_up_key = int(f0_up_key)
141
- try:
142
- audio = input_audio_path[1] / 32768.0
143
- if len(audio.shape) == 2:
144
- audio = np.mean(audio, -1)
145
- audio = librosa.resample(audio, orig_sr=input_audio_path[0], target_sr=16000)
146
- audio_max = np.abs(audio).max() / 0.95
147
- if audio_max > 1:
148
- audio /= audio_max
149
- times = [0, 0, 0]
150
- if hubert_model == None:
151
- load_hubert()
152
- if_f0 = cpt.get("f0", 1)
153
- file_index = (
154
- (
155
- file_index.strip(" ")
156
- .strip('"')
157
- .strip("\n")
158
- .strip('"')
159
- .strip(" ")
160
- .replace("trained", "added")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
161
  )
162
- if file_index != ""
163
- else file_index2
164
- ) # 防止小白写错,自动帮他替换掉
165
- # file_big_npy = (
166
- # file_big_npy.strip(" ").strip('"').strip("\n").strip('"').strip(" ")
167
- # )
168
- audio_opt = vc.pipeline(
169
- hubert_model,
170
- net_g,
171
- sid,
172
- audio,
173
- input_audio_path,
174
- times,
175
- f0_up_key,
176
- f0_method,
177
- file_index,
178
- # file_big_npy,
179
- index_rate,
180
- if_f0,
181
- filter_radius,
182
- tgt_sr,
183
- resample_sr,
184
- rms_mix_rate,
185
- version,
186
- protect,
187
- f0_file=f0_file,
188
  )
189
- if resample_sr >= 16000 and tgt_sr != resample_sr:
190
- tgt_sr = resample_sr
191
- index_info = (
192
- "Using index:%s." % file_index
193
- if os.path.exists(file_index)
194
- else "Index not used."
 
 
 
 
 
 
 
 
 
 
 
 
195
  )
196
- return "Success.\n %s\nTime:\n npy:%ss, f0:%ss, infer:%ss" % (
197
- index_info,
198
- times[0],
199
- times[1],
200
- times[2],
201
- ), (tgt_sr, audio_opt)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
202
  except:
203
- info = traceback.format_exc()
204
- print(info)
205
- return info, (None, None)
206
 
207
 
208
- app = gr.Blocks()
209
- with app:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
210
  with gr.Tabs():
211
- with gr.TabItem("在线demo"):
212
- gr.Markdown(
213
- value="""
214
- RVC 在线demo
215
- """
216
- )
217
- sid = gr.Dropdown(label=i18n("推理音色"), choices=sorted(names))
218
- with gr.Column():
219
  spk_item = gr.Slider(
220
  minimum=0,
221
  maximum=2333,
@@ -225,95 +792,729 @@ with app:
225
  visible=False,
226
  interactive=True,
227
  )
228
- sid.change(
229
- fn=get_vc,
230
- inputs=[sid],
231
- outputs=[spk_item],
232
- )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
233
  gr.Markdown(
234
- value=i18n("男转女推荐+12key, 女转男推荐-12key, 如果音域爆炸导致音色失真也可以自己调整到合适音域. ")
235
- )
236
- vc_input3 = gr.Audio(label="上传音频(长度小于90秒)")
237
- vc_transform0 = gr.Number(label=i18n("变调(整数, 半音数量, 升八度12降八度-12)"), value=0)
238
- f0method0 = gr.Radio(
239
- label=i18n("选择音高提取算法,输入歌声可用pm提速,harvest低音好但巨慢无比,crepe效果好但吃GPU"),
240
- choices=["pm", "harvest", "crepe"],
241
- value="pm",
242
- interactive=True,
243
- )
244
- filter_radius0 = gr.Slider(
245
- minimum=0,
246
- maximum=7,
247
- label=i18n(">=3则使用对harvest音高识别的结果使用中值滤波,数值为滤波半径,使用可以削弱哑音"),
248
- value=3,
249
- step=1,
250
- interactive=True,
251
- )
252
- with gr.Column():
253
- file_index1 = gr.Textbox(
254
- label=i18n("特征检索库文件路径,为空则使用下拉的选择结果"),
255
- value="",
256
- interactive=False,
257
- visible=False,
258
  )
259
- file_index2 = gr.Dropdown(
260
- label=i18n("自动检测index路径,下拉式选择(dropdown)"),
261
- choices=sorted(index_paths),
262
- interactive=True,
263
- )
264
- index_rate1 = gr.Slider(
265
- minimum=0,
266
- maximum=1,
267
- label=i18n("检索特征占比"),
268
- value=0.88,
269
- interactive=True,
270
  )
271
- resample_sr0 = gr.Slider(
272
- minimum=0,
273
- maximum=48000,
274
- label=i18n("后处理重采样至最终采样率,0为不进行重采样"),
275
- value=0,
276
- step=1,
277
- interactive=True,
278
- )
279
- rms_mix_rate0 = gr.Slider(
280
- minimum=0,
281
- maximum=1,
282
- label=i18n("输入源音量包络替换输出音量包络融合比例,越靠近1越使用输出包络"),
283
- value=1,
284
- interactive=True,
285
- )
286
- protect0 = gr.Slider(
287
- minimum=0,
288
- maximum=0.5,
289
- label=i18n("保护清辅音和呼吸声,防止电音撕裂等artifact,拉满0.5不开启,调低加大保护力度但可能降低索引效果"),
290
- value=0.33,
291
- step=0.01,
292
- interactive=True,
293
- )
294
- f0_file = gr.File(label=i18n("F0曲线文件, 可选, 一行一个音高, 代替默认F0及升降调"))
295
- but0 = gr.Button(i18n("转换"), variant="primary")
296
- vc_output1 = gr.Textbox(label=i18n("输出信息"))
297
- vc_output2 = gr.Audio(label=i18n("输出音频(右下角三个点,点了可以下载)"))
298
- but0.click(
299
- vc_single,
300
- [
301
- spk_item,
302
- vc_input3,
303
- vc_transform0,
304
- f0_file,
305
- f0method0,
306
- file_index1,
307
- file_index2,
308
- # file_big_npy1,
309
- index_rate1,
310
- filter_radius0,
311
- resample_sr0,
312
- rms_mix_rate0,
313
- protect0,
314
- ],
315
- [vc_output1, vc_output2],
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
316
  )
317
 
 
 
 
 
 
 
 
 
 
 
 
 
318
 
319
- app.launch()
 
 
 
 
 
 
 
 
 
1
  import os
2
+ import sys
3
+ from dotenv import load_dotenv
4
 
5
+ now_dir = os.getcwd()
6
+ sys.path.append(now_dir)
7
+ load_dotenv()
8
+ from infer.modules.vc.modules import VC
9
+ from infer.modules.uvr5.modules import uvr
10
+ from infer.lib.train.process_ckpt import (
11
+ change_info,
12
+ extract_small_model,
13
+ merge,
14
+ show_info,
15
+ )
16
+ from i18n.i18n import I18nAuto
17
+ from configs.config import Config
18
+ from sklearn.cluster import MiniBatchKMeans
19
+ import torch
20
  import numpy as np
21
+ import gradio as gr
22
+ import faiss
23
+ import fairseq
24
+ import pathlib
25
+ import json
26
+ from time import sleep
27
+ from subprocess import Popen
28
+ from random import shuffle
29
+ import warnings
30
  import traceback
31
+ import threading
32
+ import shutil
33
+ import logging
34
+
 
 
 
 
35
 
36
  logging.getLogger("numba").setLevel(logging.WARNING)
 
 
 
37
 
38
+ logger = logging.getLogger(__name__)
39
+
40
+ tmp = os.path.join(now_dir, "TEMP")
41
+ shutil.rmtree(tmp, ignore_errors=True)
42
+ shutil.rmtree("%s/runtime/Lib/site-packages/infer_pack" % (now_dir), ignore_errors=True)
43
+ shutil.rmtree("%s/runtime/Lib/site-packages/uvr5_pack" % (now_dir), ignore_errors=True)
44
+ os.makedirs(tmp, exist_ok=True)
45
+ os.makedirs(os.path.join(now_dir, "logs"), exist_ok=True)
46
+ os.makedirs(os.path.join(now_dir, "assets/weights"), exist_ok=True)
47
+ os.environ["TEMP"] = tmp
48
+ warnings.filterwarnings("ignore")
49
+ torch.manual_seed(114514)
50
+
51
 
52
  config = Config()
53
+ vc = VC(config)
54
+
55
+
56
+ if config.dml == True:
57
+
58
+ def forward_dml(ctx, x, scale):
59
+ ctx.scale = scale
60
+ res = x.clone().detach()
61
+ return res
62
+
63
+ fairseq.modules.grad_multiply.GradMultiply.forward = forward_dml
64
+ i18n = I18nAuto()
65
+ logger.info(i18n)
66
+ # 判断是否有能用来训练和加速推理的N卡
67
+ ngpu = torch.cuda.device_count()
68
+ gpu_infos = []
69
+ mem = []
70
+ if_gpu_ok = False
71
+
72
+ if torch.cuda.is_available() or ngpu != 0:
73
+ for i in range(ngpu):
74
+ gpu_name = torch.cuda.get_device_name(i)
75
+ if any(
76
+ value in gpu_name.upper()
77
+ for value in [
78
+ "10",
79
+ "16",
80
+ "20",
81
+ "30",
82
+ "40",
83
+ "A2",
84
+ "A3",
85
+ "A4",
86
+ "P4",
87
+ "A50",
88
+ "500",
89
+ "A60",
90
+ "70",
91
+ "80",
92
+ "90",
93
+ "M4",
94
+ "T4",
95
+ "TITAN",
96
+ ]
97
+ ):
98
+ # A10#A100#V100#A40#P40#M40#K80#A4500
99
+ if_gpu_ok = True # 至少有一张能用的N卡
100
+ gpu_infos.append("%s\t%s" % (i, gpu_name))
101
+ mem.append(
102
+ int(
103
+ torch.cuda.get_device_properties(i).total_memory
104
+ / 1024
105
+ / 1024
106
+ / 1024
107
+ + 0.4
108
+ )
109
+ )
110
+ if if_gpu_ok and len(gpu_infos) > 0:
111
+ gpu_info = "\n".join(gpu_infos)
112
+ default_batch_size = min(mem) // 2
113
+ else:
114
+ gpu_info = i18n("很遗憾您这没有能用的显卡来支持您训练")
115
+ default_batch_size = 1
116
+ gpus = "-".join([i[0] for i in gpu_infos])
117
+
118
+
119
+ class ToolButton(gr.Button, gr.components.FormComponent):
120
+ """Small button with single emoji as text, fits inside gradio forms"""
121
+
122
+ def __init__(self, **kwargs):
123
+ super().__init__(variant="tool", **kwargs)
124
+
125
+ def get_block_name(self):
126
+ return "button"
127
+
128
+
129
+ weight_root = os.getenv("weight_root")
130
+ weight_uvr5_root = os.getenv("weight_uvr5_root")
131
+ index_root = os.getenv("index_root")
132
 
 
 
 
133
  names = []
 
134
  for name in os.listdir(weight_root):
135
  if name.endswith(".pth"):
136
  names.append(name)
 
139
  for name in files:
140
  if name.endswith(".index") and "trained" not in name:
141
  index_paths.append("%s/%s" % (root, name))
142
+ uvr5_names = []
143
+ for name in os.listdir(weight_uvr5_root):
144
+ if name.endswith(".pth") or "onnx" in name:
145
+ uvr5_names.append(name.replace(".pth", ""))
146
 
147
 
148
+ def change_choices():
149
+ names = []
150
+ for name in os.listdir(weight_root):
151
+ if name.endswith(".pth"):
152
+ names.append(name)
153
+ index_paths = []
154
+ for root, dirs, files in os.walk(index_root, topdown=False):
155
+ for name in files:
156
+ if name.endswith(".index") and "trained" not in name:
157
+ index_paths.append("%s/%s" % (root, name))
158
+ return {"choices": sorted(names), "__type__": "update"}, {
159
+ "choices": sorted(index_paths),
160
+ "__type__": "update",
161
+ }
162
+
163
+
164
+ def clean():
165
+ return {"value": "", "__type__": "update"}
166
+
167
+
168
+ def export_onnx(ModelPath, ExportedPath):
169
+ from infer.modules.onnx.export import export_onnx as eo
170
+
171
+ eo(ModelPath, ExportedPath)
172
+
173
+
174
+ sr_dict = {
175
+ "32k": 32000,
176
+ "40k": 40000,
177
+ "48k": 48000,
178
+ }
179
+
180
+
181
+ def if_done(done, p):
182
+ while 1:
183
+ if p.poll() is None:
184
+ sleep(0.5)
 
 
 
 
 
185
  else:
186
+ break
187
+ done[0] = True
188
+
189
+
190
+ def if_done_multi(done, ps):
191
+ while 1:
192
+ # poll==None代表进程未结束
193
+ # 只要有一个进程未结束都不停
194
+ flag = 1
195
+ for p in ps:
196
+ if p.poll() is None:
197
+ flag = 0
198
+ sleep(0.5)
199
+ break
200
+ if flag == 1:
201
+ break
202
+ done[0] = True
203
+
204
+
205
+ def preprocess_dataset(trainset_dir, exp_dir, sr, n_p):
206
+ sr = sr_dict[sr]
207
+ os.makedirs("%s/logs/%s" % (now_dir, exp_dir), exist_ok=True)
208
+ f = open("%s/logs/%s/preprocess.log" % (now_dir, exp_dir), "w")
209
+ f.close()
210
+ per = 3.0 if config.is_half else 3.7
211
+ cmd = '"%s" infer/modules/train/preprocess.py "%s" %s %s "%s/logs/%s" %s %.1f' % (
212
+ config.python_cmd,
213
+ trainset_dir,
214
+ sr,
215
+ n_p,
216
+ now_dir,
217
+ exp_dir,
218
+ config.noparallel,
219
+ per,
220
+ )
221
+ logger.info(cmd)
222
+ # , stdin=PIPE, stdout=PIPE,stderr=PIPE,cwd=now_dir
223
+ p = Popen(cmd, shell=True)
224
+ # 煞笔gr, popen read都非得全跑完了再一次性读取, 不用gr就正常读一句输出一句;只能额外弄出一个文本流定时读
225
+ done = [False]
226
+ threading.Thread(
227
+ target=if_done,
228
+ args=(
229
+ done,
230
+ p,
231
+ ),
232
+ ).start()
233
+ while 1:
234
+ with open("%s/logs/%s/preprocess.log" % (now_dir, exp_dir), "r") as f:
235
+ yield (f.read())
236
+ sleep(1)
237
+ if done[0]:
238
+ break
239
+ with open("%s/logs/%s/preprocess.log" % (now_dir, exp_dir), "r") as f:
240
+ log = f.read()
241
+ logger.info(log)
242
+ yield log
243
+
244
+
245
+ # but2.click(extract_f0,[gpus6,np7,f0method8,if_f0_3,trainset_dir4],[info2])
246
+ def extract_f0_feature(gpus, n_p, f0method, if_f0, exp_dir, version19, gpus_rmvpe):
247
+ gpus = gpus.split("-")
248
+ os.makedirs("%s/logs/%s" % (now_dir, exp_dir), exist_ok=True)
249
+ f = open("%s/logs/%s/extract_f0_feature.log" % (now_dir, exp_dir), "w")
250
+ f.close()
251
+ if if_f0:
252
+ if f0method != "rmvpe_gpu":
253
+ cmd = (
254
+ '"%s" infer/modules/train/extract/extract_f0_print.py "%s/logs/%s" %s %s'
255
+ % (
256
+ config.python_cmd,
257
+ now_dir,
258
+ exp_dir,
259
+ n_p,
260
+ f0method,
261
+ )
262
+ )
263
+ logger.info(cmd)
264
+ p = Popen(
265
+ cmd, shell=True, cwd=now_dir
266
+ ) # , stdin=PIPE, stdout=PIPE,stderr=PIPE
267
+ # 煞笔gr, popen read都非得全跑完了再一次性读取, 不用gr就正常读一句输出一句;只能额外弄出一个文本流定时读
268
+ done = [False]
269
+ threading.Thread(
270
+ target=if_done,
271
+ args=(
272
+ done,
273
+ p,
274
+ ),
275
+ ).start()
276
  else:
277
+ if gpus_rmvpe != "-":
278
+ gpus_rmvpe = gpus_rmvpe.split("-")
279
+ leng = len(gpus_rmvpe)
280
+ ps = []
281
+ for idx, n_g in enumerate(gpus_rmvpe):
282
+ cmd = (
283
+ '"%s" infer/modules/train/extract/extract_f0_rmvpe.py %s %s %s "%s/logs/%s" %s '
284
+ % (
285
+ config.python_cmd,
286
+ leng,
287
+ idx,
288
+ n_g,
289
+ now_dir,
290
+ exp_dir,
291
+ config.is_half,
292
+ )
293
+ )
294
+ logger.info(cmd)
295
+ p = Popen(
296
+ cmd, shell=True, cwd=now_dir
297
+ ) # , shell=True, stdin=PIPE, stdout=PIPE, stderr=PIPE, cwd=now_dir
298
+ ps.append(p)
299
+ # 煞笔gr, popen read都非得全跑完了再一次性读取, 不用gr就正常读一句输出一句;只能额外弄出一个文本流定时读
300
+ done = [False]
301
+ threading.Thread(
302
+ target=if_done_multi, #
303
+ args=(
304
+ done,
305
+ ps,
306
+ ),
307
+ ).start()
308
+ else:
309
+ cmd = (
310
+ config.python_cmd
311
+ + ' infer/modules/train/extract/extract_f0_rmvpe_dml.py "%s/logs/%s" '
312
+ % (
313
+ now_dir,
314
+ exp_dir,
315
+ )
316
+ )
317
+ logger.info(cmd)
318
+ p = Popen(
319
+ cmd, shell=True, cwd=now_dir
320
+ ) # , shell=True, stdin=PIPE, stdout=PIPE, stderr=PIPE, cwd=now_dir
321
+ p.wait()
322
+ done = [True]
323
+ while 1:
324
+ with open(
325
+ "%s/logs/%s/extract_f0_feature.log" % (now_dir, exp_dir), "r"
326
+ ) as f:
327
+ yield (f.read())
328
+ sleep(1)
329
+ if done[0]:
330
+ break
331
+ with open("%s/logs/%s/extract_f0_feature.log" % (now_dir, exp_dir), "r") as f:
332
+ log = f.read()
333
+ logger.info(log)
334
+ yield log
335
+ # 对不同part分别开多进程
336
+ """
337
+ n_part=int(sys.argv[1])
338
+ i_part=int(sys.argv[2])
339
+ i_gpu=sys.argv[3]
340
+ exp_dir=sys.argv[4]
341
+ os.environ["CUDA_VISIBLE_DEVICES"]=str(i_gpu)
342
+ """
343
+ leng = len(gpus)
344
+ ps = []
345
+ for idx, n_g in enumerate(gpus):
346
+ cmd = (
347
+ '"%s" infer/modules/train/extract_feature_print.py %s %s %s %s "%s/logs/%s" %s'
348
+ % (
349
+ config.python_cmd,
350
+ config.device,
351
+ leng,
352
+ idx,
353
+ n_g,
354
+ now_dir,
355
+ exp_dir,
356
+ version19,
357
+ )
358
+ )
359
+ logger.info(cmd)
360
+ p = Popen(
361
+ cmd, shell=True, cwd=now_dir
362
+ ) # , shell=True, stdin=PIPE, stdout=PIPE, stderr=PIPE, cwd=now_dir
363
+ ps.append(p)
364
+ # 煞笔gr, popen read都非得全跑完了再一次性读取, 不用gr就正常读一句输出一句;只能额外弄出一个文本流定时读
365
+ done = [False]
366
+ threading.Thread(
367
+ target=if_done_multi,
368
+ args=(
369
+ done,
370
+ ps,
371
+ ),
372
+ ).start()
373
+ while 1:
374
+ with open("%s/logs/%s/extract_f0_feature.log" % (now_dir, exp_dir), "r") as f:
375
+ yield (f.read())
376
+ sleep(1)
377
+ if done[0]:
378
+ break
379
+ with open("%s/logs/%s/extract_f0_feature.log" % (now_dir, exp_dir), "r") as f:
380
+ log = f.read()
381
+ logger.info(log)
382
+ yield log
383
+
384
+
385
+ def get_pretrained_models(path_str, f0_str, sr2):
386
+ if_pretrained_generator_exist = os.access(
387
+ "assets/pretrained%s/%sG%s.pth" % (path_str, f0_str, sr2), os.F_OK
388
+ )
389
+ if_pretrained_discriminator_exist = os.access(
390
+ "assets/pretrained%s/%sD%s.pth" % (path_str, f0_str, sr2), os.F_OK
391
+ )
392
+ if not if_pretrained_generator_exist:
393
+ logger.warning(
394
+ "assets/pretrained%s/%sG%s.pth not exist, will not use pretrained model",
395
+ path_str,
396
+ f0_str,
397
+ sr2,
398
+ )
399
+ if not if_pretrained_discriminator_exist:
400
+ logger.warning(
401
+ "assets/pretrained%s/%sD%s.pth not exist, will not use pretrained model",
402
+ path_str,
403
+ f0_str,
404
+ sr2,
405
+ )
406
+ return (
407
+ "assets/pretrained%s/%sG%s.pth" % (path_str, f0_str, sr2)
408
+ if if_pretrained_generator_exist
409
+ else "",
410
+ "assets/pretrained%s/%sD%s.pth" % (path_str, f0_str, sr2)
411
+ if if_pretrained_discriminator_exist
412
+ else "",
413
+ )
414
+
415
+
416
+ def change_sr2(sr2, if_f0_3, version19):
417
+ path_str = "" if version19 == "v1" else "_v2"
418
+ f0_str = "f0" if if_f0_3 else ""
419
+ return get_pretrained_models(path_str, f0_str, sr2)
420
 
421
 
422
+ def change_version19(sr2, if_f0_3, version19):
423
+ path_str = "" if version19 == "v1" else "_v2"
424
+ if sr2 == "32k" and version19 == "v1":
425
+ sr2 = "40k"
426
+ to_return_sr2 = (
427
+ {"choices": ["40k", "48k"], "__type__": "update", "value": sr2}
428
+ if version19 == "v1"
429
+ else {"choices": ["40k", "48k", "32k"], "__type__": "update", "value": sr2}
430
  )
431
+ f0_str = "f0" if if_f0_3 else ""
432
+ return (
433
+ *get_pretrained_models(path_str, f0_str, sr2),
434
+ to_return_sr2,
435
+ )
436
+
437
+
438
+ def change_f0(if_f0_3, sr2, version19): # f0method8,pretrained_G14,pretrained_D15
439
+ path_str = "" if version19 == "v1" else "_v2"
440
+ return (
441
+ {"visible": if_f0_3, "__type__": "update"},
442
+ {"visible": if_f0_3, "__type__": "update"},
443
+ *get_pretrained_models(path_str, "f0" if if_f0_3 == True else "", sr2),
444
+ )
445
+
446
+
447
+ # but3.click(click_train,[exp_dir1,sr2,if_f0_3,save_epoch10,total_epoch11,batch_size12,if_save_latest13,pretrained_G14,pretrained_D15,gpus16])
448
+ def click_train(
449
+ exp_dir1,
450
+ sr2,
451
+ if_f0_3,
452
+ spk_id5,
453
+ save_epoch10,
454
+ total_epoch11,
455
+ batch_size12,
456
+ if_save_latest13,
457
+ pretrained_G14,
458
+ pretrained_D15,
459
+ gpus16,
460
+ if_cache_gpu17,
461
+ if_save_every_weights18,
462
+ version19,
463
+ ):
464
+ # 生成filelist
465
+ exp_dir = "%s/logs/%s" % (now_dir, exp_dir1)
466
+ os.makedirs(exp_dir, exist_ok=True)
467
+ gt_wavs_dir = "%s/0_gt_wavs" % (exp_dir)
468
+ feature_dir = (
469
+ "%s/3_feature256" % (exp_dir)
470
+ if version19 == "v1"
471
+ else "%s/3_feature768" % (exp_dir)
472
+ )
473
+ if if_f0_3:
474
+ f0_dir = "%s/2a_f0" % (exp_dir)
475
+ f0nsf_dir = "%s/2b-f0nsf" % (exp_dir)
476
+ names = (
477
+ set([name.split(".")[0] for name in os.listdir(gt_wavs_dir)])
478
+ & set([name.split(".")[0] for name in os.listdir(feature_dir)])
479
+ & set([name.split(".")[0] for name in os.listdir(f0_dir)])
480
+ & set([name.split(".")[0] for name in os.listdir(f0nsf_dir)])
481
+ )
482
  else:
483
+ names = set([name.split(".")[0] for name in os.listdir(gt_wavs_dir)]) & set(
484
+ [name.split(".")[0] for name in os.listdir(feature_dir)]
485
+ )
486
+ opt = []
487
+ for name in names:
488
+ if if_f0_3:
489
+ opt.append(
490
+ "%s/%s.wav|%s/%s.npy|%s/%s.wav.npy|%s/%s.wav.npy|%s"
491
+ % (
492
+ gt_wavs_dir.replace("\\", "\\\\"),
493
+ name,
494
+ feature_dir.replace("\\", "\\\\"),
495
+ name,
496
+ f0_dir.replace("\\", "\\\\"),
497
+ name,
498
+ f0nsf_dir.replace("\\", "\\\\"),
499
+ name,
500
+ spk_id5,
501
+ )
502
+ )
503
+ else:
504
+ opt.append(
505
+ "%s/%s.wav|%s/%s.npy|%s"
506
+ % (
507
+ gt_wavs_dir.replace("\\", "\\\\"),
508
+ name,
509
+ feature_dir.replace("\\", "\\\\"),
510
+ name,
511
+ spk_id5,
512
+ )
513
+ )
514
+ fea_dim = 256 if version19 == "v1" else 768
515
+ if if_f0_3:
516
+ for _ in range(2):
517
+ opt.append(
518
+ "%s/logs/mute/0_gt_wavs/mute%s.wav|%s/logs/mute/3_feature%s/mute.npy|%s/logs/mute/2a_f0/mute.wav.npy|%s/logs/mute/2b-f0nsf/mute.wav.npy|%s"
519
+ % (now_dir, sr2, now_dir, fea_dim, now_dir, now_dir, spk_id5)
520
+ )
521
+ else:
522
+ for _ in range(2):
523
+ opt.append(
524
+ "%s/logs/mute/0_gt_wavs/mute%s.wav|%s/logs/mute/3_feature%s/mute.npy|%s"
525
+ % (now_dir, sr2, now_dir, fea_dim, spk_id5)
526
+ )
527
+ shuffle(opt)
528
+ with open("%s/filelist.txt" % exp_dir, "w") as f:
529
+ f.write("\n".join(opt))
530
+ logger.debug("Write filelist done")
531
+ # 生成config#无需生成config
532
+ # cmd = python_cmd + " train_nsf_sim_cache_sid_load_pretrain.py -e mi-test -sr 40k -f0 1 -bs 4 -g 0 -te 10 -se 5 -pg pretrained/f0G40k.pth -pd pretrained/f0D40k.pth -l 1 -c 0"
533
+ logger.info("Use gpus: %s", str(gpus16))
534
+ if pretrained_G14 == "":
535
+ logger.info("No pretrained Generator")
536
+ if pretrained_D15 == "":
537
+ logger.info("No pretrained Discriminator")
538
+ if version19 == "v1" or sr2 == "40k":
539
+ config_path = "v1/%s.json" % sr2
540
+ else:
541
+ config_path = "v2/%s.json" % sr2
542
+ config_save_path = os.path.join(exp_dir, "config.json")
543
+ if not pathlib.Path(config_save_path).exists():
544
+ with open(config_save_path, "w", encoding="utf-8") as f:
545
+ json.dump(
546
+ config.json_config[config_path],
547
+ f,
548
+ ensure_ascii=False,
549
+ indent=4,
550
+ sort_keys=True,
551
+ )
552
+ f.write("\n")
553
+ if gpus16:
554
+ cmd = (
555
+ '"%s" infer/modules/train/train.py -e "%s" -sr %s -f0 %s -bs %s -g %s -te %s -se %s %s %s -l %s -c %s -sw %s -v %s'
556
+ % (
557
+ config.python_cmd,
558
+ exp_dir1,
559
+ sr2,
560
+ 1 if if_f0_3 else 0,
561
+ batch_size12,
562
+ gpus16,
563
+ total_epoch11,
564
+ save_epoch10,
565
+ "-pg %s" % pretrained_G14 if pretrained_G14 != "" else "",
566
+ "-pd %s" % pretrained_D15 if pretrained_D15 != "" else "",
567
+ 1 if if_save_latest13 == i18n("是") else 0,
568
+ 1 if if_cache_gpu17 == i18n("是") else 0,
569
+ 1 if if_save_every_weights18 == i18n("是") else 0,
570
+ version19,
571
  )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
572
  )
573
+ else:
574
+ cmd = (
575
+ '"%s" infer/modules/train/train.py -e "%s" -sr %s -f0 %s -bs %s -te %s -se %s %s %s -l %s -c %s -sw %s -v %s'
576
+ % (
577
+ config.python_cmd,
578
+ exp_dir1,
579
+ sr2,
580
+ 1 if if_f0_3 else 0,
581
+ batch_size12,
582
+ total_epoch11,
583
+ save_epoch10,
584
+ "-pg %s" % pretrained_G14 if pretrained_G14 != "" else "",
585
+ "-pd %s" % pretrained_D15 if pretrained_D15 != "" else "",
586
+ 1 if if_save_latest13 == i18n("是") else 0,
587
+ 1 if if_cache_gpu17 == i18n("是") else 0,
588
+ 1 if if_save_every_weights18 == i18n("是") else 0,
589
+ version19,
590
+ )
591
  )
592
+ logger.info(cmd)
593
+ p = Popen(cmd, shell=True, cwd=now_dir)
594
+ p.wait()
595
+ return "训练结束, 您可查看控制台训练日志或实验文件夹下的train.log"
596
+
597
+
598
+ # but4.click(train_index, [exp_dir1], info3)
599
+ def train_index(exp_dir1, version19):
600
+ # exp_dir = "%s/logs/%s" % (now_dir, exp_dir1)
601
+ exp_dir = "logs/%s" % (exp_dir1)
602
+ os.makedirs(exp_dir, exist_ok=True)
603
+ feature_dir = (
604
+ "%s/3_feature256" % (exp_dir)
605
+ if version19 == "v1"
606
+ else "%s/3_feature768" % (exp_dir)
607
+ )
608
+ if not os.path.exists(feature_dir):
609
+ return "请先进行特征提取!"
610
+ listdir_res = list(os.listdir(feature_dir))
611
+ if len(listdir_res) == 0:
612
+ return "请先进行特征提取!"
613
+ infos = []
614
+ npys = []
615
+ for name in sorted(listdir_res):
616
+ phone = np.load("%s/%s" % (feature_dir, name))
617
+ npys.append(phone)
618
+ big_npy = np.concatenate(npys, 0)
619
+ big_npy_idx = np.arange(big_npy.shape[0])
620
+ np.random.shuffle(big_npy_idx)
621
+ big_npy = big_npy[big_npy_idx]
622
+ if big_npy.shape[0] > 2e5:
623
+ infos.append("Trying doing kmeans %s shape to 10k centers." % big_npy.shape[0])
624
+ yield "\n".join(infos)
625
+ try:
626
+ big_npy = (
627
+ MiniBatchKMeans(
628
+ n_clusters=10000,
629
+ verbose=True,
630
+ batch_size=256 * config.n_cpu,
631
+ compute_labels=False,
632
+ init="random",
633
+ )
634
+ .fit(big_npy)
635
+ .cluster_centers_
636
+ )
637
+ except:
638
+ info = traceback.format_exc()
639
+ logger.info(info)
640
+ infos.append(info)
641
+ yield "\n".join(infos)
642
+
643
+ np.save("%s/total_fea.npy" % exp_dir, big_npy)
644
+ n_ivf = min(int(16 * np.sqrt(big_npy.shape[0])), big_npy.shape[0] // 39)
645
+ infos.append("%s,%s" % (big_npy.shape, n_ivf))
646
+ yield "\n".join(infos)
647
+ index = faiss.index_factory(256 if version19 == "v1" else 768, "IVF%s,Flat" % n_ivf)
648
+ # index = faiss.index_factory(256if version19=="v1"else 768, "IVF%s,PQ128x4fs,RFlat"%n_ivf)
649
+ infos.append("training")
650
+ yield "\n".join(infos)
651
+ index_ivf = faiss.extract_index_ivf(index) #
652
+ index_ivf.nprobe = 1
653
+ index.train(big_npy)
654
+ faiss.write_index(
655
+ index,
656
+ "%s/trained_IVF%s_Flat_nprobe_%s_%s_%s.index"
657
+ % (exp_dir, n_ivf, index_ivf.nprobe, exp_dir1, version19),
658
+ )
659
+
660
+ infos.append("adding")
661
+ yield "\n".join(infos)
662
+ batch_size_add = 8192
663
+ for i in range(0, big_npy.shape[0], batch_size_add):
664
+ index.add(big_npy[i : i + batch_size_add])
665
+ faiss.write_index(
666
+ index,
667
+ "%s/added_IVF%s_Flat_nprobe_%s_%s_%s.index"
668
+ % (exp_dir, n_ivf, index_ivf.nprobe, exp_dir1, version19),
669
+ )
670
+ infos.append(
671
+ "成功构建索引,added_IVF%s_Flat_nprobe_%s_%s_%s.index"
672
+ % (n_ivf, index_ivf.nprobe, exp_dir1, version19)
673
+ )
674
+ # faiss.write_index(index, '%s/added_IVF%s_Flat_FastScan_%s.index'%(exp_dir,n_ivf,version19))
675
+ # infos.append("成功构建索引,added_IVF%s_Flat_FastScan_%s.index"%(n_ivf,version19))
676
+ yield "\n".join(infos)
677
+
678
+
679
+ # but5.click(train1key, [exp_dir1, sr2, if_f0_3, trainset_dir4, spk_id5, gpus6, np7, f0method8, save_epoch10, total_epoch11, batch_size12, if_save_latest13, pretrained_G14, pretrained_D15, gpus16, if_cache_gpu17], info3)
680
+ def train1key(
681
+ exp_dir1,
682
+ sr2,
683
+ if_f0_3,
684
+ trainset_dir4,
685
+ spk_id5,
686
+ np7,
687
+ f0method8,
688
+ save_epoch10,
689
+ total_epoch11,
690
+ batch_size12,
691
+ if_save_latest13,
692
+ pretrained_G14,
693
+ pretrained_D15,
694
+ gpus16,
695
+ if_cache_gpu17,
696
+ if_save_every_weights18,
697
+ version19,
698
+ gpus_rmvpe,
699
+ ):
700
+ infos = []
701
+
702
+ def get_info_str(strr):
703
+ infos.append(strr)
704
+ return "\n".join(infos)
705
+
706
+ # step1:处理数据
707
+ yield get_info_str(i18n("step1:正在处理数据"))
708
+ [get_info_str(_) for _ in preprocess_dataset(trainset_dir4, exp_dir1, sr2, np7)]
709
+
710
+ # step2a:提取音高
711
+ yield get_info_str(i18n("step2:正在提取音高&正在提取特征"))
712
+ [
713
+ get_info_str(_)
714
+ for _ in extract_f0_feature(
715
+ gpus16, np7, f0method8, if_f0_3, exp_dir1, version19, gpus_rmvpe
716
+ )
717
+ ]
718
+
719
+ # step3a:训练模型
720
+ yield get_info_str(i18n("step3a:正在训练模型"))
721
+ click_train(
722
+ exp_dir1,
723
+ sr2,
724
+ if_f0_3,
725
+ spk_id5,
726
+ save_epoch10,
727
+ total_epoch11,
728
+ batch_size12,
729
+ if_save_latest13,
730
+ pretrained_G14,
731
+ pretrained_D15,
732
+ gpus16,
733
+ if_cache_gpu17,
734
+ if_save_every_weights18,
735
+ version19,
736
+ )
737
+ yield get_info_str(i18n("训练结束, 您可查看控制台训练日志或实验文件夹下的train.log"))
738
+
739
+ # step3b:训练索引
740
+ [get_info_str(_) for _ in train_index(exp_dir1, version19)]
741
+ yield get_info_str(i18n("全流程结束!"))
742
+
743
+
744
+ # ckpt_path2.change(change_info_,[ckpt_path2],[sr__,if_f0__])
745
+ def change_info_(ckpt_path):
746
+ if not os.path.exists(ckpt_path.replace(os.path.basename(ckpt_path), "train.log")):
747
+ return {"__type__": "update"}, {"__type__": "update"}, {"__type__": "update"}
748
+ try:
749
+ with open(
750
+ ckpt_path.replace(os.path.basename(ckpt_path), "train.log"), "r"
751
+ ) as f:
752
+ info = eval(f.read().strip("\n").split("\n")[0].split("\t")[-1])
753
+ sr, f0 = info["sample_rate"], info["if_f0"]
754
+ version = "v2" if ("version" in info and info["version"] == "v2") else "v1"
755
+ return sr, str(f0), version
756
  except:
757
+ traceback.print_exc()
758
+ return {"__type__": "update"}, {"__type__": "update"}, {"__type__": "update"}
 
759
 
760
 
761
+ F0GPUVisible = config.dml == False
762
+
763
+
764
+ def change_f0_method(f0method8):
765
+ if f0method8 == "rmvpe_gpu":
766
+ visible = F0GPUVisible
767
+ else:
768
+ visible = False
769
+ return {"visible": visible, "__type__": "update"}
770
+
771
+
772
+ with gr.Blocks(title="RVC WebUI") as app:
773
+ gr.Markdown("## RVC WebUI")
774
+ gr.Markdown(
775
+ value=i18n(
776
+ "本软件以MIT协议开源, 作者不对软件具备任何控制力, 使用软件者、传播软件导出的声音者自负全责. <br>如不认可该条款, 则不能使用或引用软件包内任何代码和文件. 详见根目录<b>LICENSE</b>."
777
+ )
778
+ )
779
  with gr.Tabs():
780
+ with gr.TabItem(i18n("模型推理")):
781
+ with gr.Row():
782
+ sid0 = gr.Dropdown(label=i18n("推理音色"), choices=sorted(names))
783
+ with gr.Column():
784
+ refresh_button = gr.Button(i18n("刷新音色列表和索引路径"), variant="primary")
785
+ clean_button = gr.Button(i18n("卸载音色省显存"), variant="primary")
 
 
786
  spk_item = gr.Slider(
787
  minimum=0,
788
  maximum=2333,
 
792
  visible=False,
793
  interactive=True,
794
  )
795
+ clean_button.click(
796
+ fn=clean, inputs=[], outputs=[sid0], api_name="infer_clean"
797
+ )
798
+ with gr.TabItem(i18n("单次推理")):
799
+ with gr.Group():
800
+ with gr.Row():
801
+ with gr.Column():
802
+ vc_transform0 = gr.Number(
803
+ label=i18n("变调(整数, 半音数量, 升八度12降八度-12)"), value=0
804
+ )
805
+ input_audio0 = gr.Textbox(
806
+ label=i18n("输入待处理音频文件路径(默认是正确格式示例)"),
807
+ placeholder="C:\\Users\\Desktop\\audio_example.wav",
808
+ )
809
+ file_index1 = gr.Textbox(
810
+ label=i18n("特征检索库文件路径,为空则使用下拉的选择结果"),
811
+ placeholder="C:\\Users\\Desktop\\model_example.index",
812
+ interactive=True,
813
+ )
814
+ file_index2 = gr.Dropdown(
815
+ label=i18n("自动检测index路径,下拉式选择(dropdown)"),
816
+ choices=sorted(index_paths),
817
+ interactive=True,
818
+ )
819
+ f0method0 = gr.Radio(
820
+ label=i18n(
821
+ "选择音高提取算法,输入歌声可用pm提速,harvest低音好但巨慢无比,crepe效果好但吃GPU,rmvpe效果最好且微吃GPU"
822
+ ),
823
+ choices=["pm", "harvest", "crepe", "rmvpe"]
824
+ if config.dml == False
825
+ else ["pm", "harvest", "rmvpe"],
826
+ value="rmvpe",
827
+ interactive=True,
828
+ )
829
+
830
+ with gr.Column():
831
+ resample_sr0 = gr.Slider(
832
+ minimum=0,
833
+ maximum=48000,
834
+ label=i18n("后处理重采样至最终采样率,0为不进行重采样"),
835
+ value=0,
836
+ step=1,
837
+ interactive=True,
838
+ )
839
+ rms_mix_rate0 = gr.Slider(
840
+ minimum=0,
841
+ maximum=1,
842
+ label=i18n("输入源音量包络替换输出音量包络融合比例,越靠近1越使用输出包络"),
843
+ value=0.25,
844
+ interactive=True,
845
+ )
846
+ protect0 = gr.Slider(
847
+ minimum=0,
848
+ maximum=0.5,
849
+ label=i18n(
850
+ "保护清辅音和呼吸声,防止电音撕裂等artifact,拉满0.5不开启,调低加大保护力度但可能降低索引效果"
851
+ ),
852
+ value=0.33,
853
+ step=0.01,
854
+ interactive=True,
855
+ )
856
+ filter_radius0 = gr.Slider(
857
+ minimum=0,
858
+ maximum=7,
859
+ label=i18n(
860
+ ">=3则使用对harvest音高识别的结果使用中值滤波,数值为滤波半径,使用可以削弱哑音"
861
+ ),
862
+ value=3,
863
+ step=1,
864
+ interactive=True,
865
+ )
866
+ index_rate1 = gr.Slider(
867
+ minimum=0,
868
+ maximum=1,
869
+ label=i18n("检索特征占比"),
870
+ value=0.75,
871
+ interactive=True,
872
+ )
873
+ f0_file = gr.File(
874
+ label=i18n("F0曲线文件, 可选, 一行一个音高, 代替默认F0及升降调"),
875
+ visible=False,
876
+ )
877
+
878
+ refresh_button.click(
879
+ fn=change_choices,
880
+ inputs=[],
881
+ outputs=[sid0, file_index2],
882
+ api_name="infer_refresh",
883
+ )
884
+ # file_big_npy1 = gr.Textbox(
885
+ # label=i18n("特征文件路径"),
886
+ # value="E:\\codes\py39\\vits_vc_gpu_train\\logs\\mi-test-1key\\total_fea.npy",
887
+ # interactive=True,
888
+ # )
889
+ with gr.Group():
890
+ with gr.Column():
891
+ but0 = gr.Button(i18n("转换"), variant="primary")
892
+ with gr.Row():
893
+ vc_output1 = gr.Textbox(label=i18n("输出信息"))
894
+ vc_output2 = gr.Audio(label=i18n("输出音频(右下角三个点,点了可以下载)"))
895
+
896
+ but0.click(
897
+ vc.vc_single,
898
+ [
899
+ spk_item,
900
+ input_audio0,
901
+ vc_transform0,
902
+ f0_file,
903
+ f0method0,
904
+ file_index1,
905
+ file_index2,
906
+ # file_big_npy1,
907
+ index_rate1,
908
+ filter_radius0,
909
+ resample_sr0,
910
+ rms_mix_rate0,
911
+ protect0,
912
+ ],
913
+ [vc_output1, vc_output2],
914
+ api_name="infer_convert",
915
+ )
916
+ with gr.TabItem(i18n("批量推理")):
917
+ gr.Markdown(
918
+ value=i18n("批量转换, 输入待转换音频文件夹, 或上传多个音频文件, 在指定文件夹(默认opt)下输出转换的音频. ")
919
+ )
920
+ with gr.Row():
921
+ with gr.Column():
922
+ vc_transform1 = gr.Number(
923
+ label=i18n("变调(整数, 半音数量, 升八度12降八度-12)"), value=0
924
+ )
925
+ opt_input = gr.Textbox(label=i18n("指定输出文件夹"), value="opt")
926
+ file_index3 = gr.Textbox(
927
+ label=i18n("特征检索库文件路径,为空则使用下拉的选择结果"),
928
+ value="",
929
+ interactive=True,
930
+ )
931
+ file_index4 = gr.Dropdown(
932
+ label=i18n("自动检测index路径,下拉式选择(dropdown)"),
933
+ choices=sorted(index_paths),
934
+ interactive=True,
935
+ )
936
+ f0method1 = gr.Radio(
937
+ label=i18n(
938
+ "选择音高提取算法,输入歌声可用pm提速,harvest低音好但巨慢无比,crepe效果好但吃GPU,rmvpe效果最好且微吃GPU"
939
+ ),
940
+ choices=["pm", "harvest", "crepe", "rmvpe"]
941
+ if config.dml == False
942
+ else ["pm", "harvest", "rmvpe"],
943
+ value="rmvpe",
944
+ interactive=True,
945
+ )
946
+ format1 = gr.Radio(
947
+ label=i18n("导出文件格式"),
948
+ choices=["wav", "flac", "mp3", "m4a"],
949
+ value="wav",
950
+ interactive=True,
951
+ )
952
+
953
+ refresh_button.click(
954
+ fn=lambda: change_choices()[1],
955
+ inputs=[],
956
+ outputs=file_index4,
957
+ api_name="infer_refresh_batch",
958
+ )
959
+ # file_big_npy2 = gr.Textbox(
960
+ # label=i18n("特征文件路径"),
961
+ # value="E:\\codes\\py39\\vits_vc_gpu_train\\logs\\mi-test-1key\\total_fea.npy",
962
+ # interactive=True,
963
+ # )
964
+
965
+ with gr.Column():
966
+ resample_sr1 = gr.Slider(
967
+ minimum=0,
968
+ maximum=48000,
969
+ label=i18n("后处理重采样至最终采样率,0为不进行重采样"),
970
+ value=0,
971
+ step=1,
972
+ interactive=True,
973
+ )
974
+ rms_mix_rate1 = gr.Slider(
975
+ minimum=0,
976
+ maximum=1,
977
+ label=i18n("输入源音量包络替换输出音量包络融合比例,越靠近1越使用输出包络"),
978
+ value=1,
979
+ interactive=True,
980
+ )
981
+ protect1 = gr.Slider(
982
+ minimum=0,
983
+ maximum=0.5,
984
+ label=i18n(
985
+ "保护清辅音和呼吸声,防止电音撕裂等artifact,拉满0.5不开启,调低加大保护力度但可能降低索引效果"
986
+ ),
987
+ value=0.33,
988
+ step=0.01,
989
+ interactive=True,
990
+ )
991
+ filter_radius1 = gr.Slider(
992
+ minimum=0,
993
+ maximum=7,
994
+ label=i18n(">=3则使用对harvest音高识别的结果使用中值滤波,数值为滤波半径,使用可以削弱哑音"),
995
+ value=3,
996
+ step=1,
997
+ interactive=True,
998
+ )
999
+ index_rate2 = gr.Slider(
1000
+ minimum=0,
1001
+ maximum=1,
1002
+ label=i18n("检索特征占比"),
1003
+ value=1,
1004
+ interactive=True,
1005
+ )
1006
+ with gr.Row():
1007
+ dir_input = gr.Textbox(
1008
+ label=i18n("输入待处理音频文件夹路径(去文件管理器地址栏拷就行了)"),
1009
+ placeholder="C:\\Users\\Desktop\\input_vocal_dir",
1010
+ )
1011
+ inputs = gr.File(
1012
+ file_count="multiple", label=i18n("也可批量输入音频文件, 二选一, 优先读文件夹")
1013
+ )
1014
+
1015
+ with gr.Row():
1016
+ but1 = gr.Button(i18n("转换"), variant="primary")
1017
+ vc_output3 = gr.Textbox(label=i18n("输出信息"))
1018
+
1019
+ but1.click(
1020
+ vc.vc_multi,
1021
+ [
1022
+ spk_item,
1023
+ dir_input,
1024
+ opt_input,
1025
+ inputs,
1026
+ vc_transform1,
1027
+ f0method1,
1028
+ file_index3,
1029
+ file_index4,
1030
+ # file_big_npy2,
1031
+ index_rate2,
1032
+ filter_radius1,
1033
+ resample_sr1,
1034
+ rms_mix_rate1,
1035
+ protect1,
1036
+ format1,
1037
+ ],
1038
+ [vc_output3],
1039
+ api_name="infer_convert_batch",
1040
+ )
1041
+ sid0.change(
1042
+ fn=vc.get_vc,
1043
+ inputs=[sid0, protect0, protect1],
1044
+ outputs=[spk_item, protect0, protect1, file_index2, file_index4],
1045
+ api_name="infer_change_voice",
1046
+ )
1047
+ with gr.TabItem(i18n("伴奏人声分离&去混响&去回声")):
1048
+ with gr.Group():
1049
+ gr.Markdown(
1050
+ value=i18n(
1051
+ "人声伴奏分离批量处理, 使用UVR5模型。 <br>合格的文件夹路径格式举例: E:\\codes\\py39\\vits_vc_gpu\\白鹭霜华测试样例(去文件管理器地址栏拷就行了)。 <br>模型分为三类: <br>1、保留人声:不带和声的音频选这个,对主人声保留比HP5更好。内置HP2和HP3两个模型,HP3可能轻微漏伴奏但对主人声保留比HP2稍微好一丁点; <br>2、仅保留主人声:带和声的音频选这个,对主人声可能有削弱。内置HP5一个模型; <br> 3、去混响、去延迟模型(by FoxJoy):<br>  (1)MDX-Net(onnx_dereverb):对于双通道混响是最好的选择,不能去除单通道混响;<br>&emsp;(234)DeEcho:去除延迟效果。Aggressive比Normal去除得更彻底,DeReverb额外去除混响,可去除单声道混响,但是对高频重的板式混响去不干净。<br>去混响/去延迟,附:<br>1、DeEcho-DeReverb模型的耗时是另外2个DeEcho模型的接近2倍;<br>2、MDX-Net-Dereverb模型挺慢的;<br>3、个人推荐的最干净的配置是先MDX-Net再DeEcho-Aggressive。"
1052
+ )
1053
+ )
1054
+ with gr.Row():
1055
+ with gr.Column():
1056
+ dir_wav_input = gr.Textbox(
1057
+ label=i18n("输入待处理音频文件夹路径"),
1058
+ placeholder="C:\\Users\\Desktop\\todo-songs",
1059
+ )
1060
+ wav_inputs = gr.File(
1061
+ file_count="multiple", label=i18n("也可批量输入音频文件, 二选一, 优先读文件夹")
1062
+ )
1063
+ with gr.Column():
1064
+ model_choose = gr.Dropdown(label=i18n("模型"), choices=uvr5_names)
1065
+ agg = gr.Slider(
1066
+ minimum=0,
1067
+ maximum=20,
1068
+ step=1,
1069
+ label="人声提取激进程度",
1070
+ value=10,
1071
+ interactive=True,
1072
+ visible=False, # 先不开放调整
1073
+ )
1074
+ opt_vocal_root = gr.Textbox(
1075
+ label=i18n("指定输出主人声文件夹"), value="opt"
1076
+ )
1077
+ opt_ins_root = gr.Textbox(
1078
+ label=i18n("指定输出非主人声文件夹"), value="opt"
1079
+ )
1080
+ format0 = gr.Radio(
1081
+ label=i18n("导出文件格式"),
1082
+ choices=["wav", "flac", "mp3", "m4a"],
1083
+ value="flac",
1084
+ interactive=True,
1085
+ )
1086
+ but2 = gr.Button(i18n("转换"), variant="primary")
1087
+ vc_output4 = gr.Textbox(label=i18n("输出信息"))
1088
+ but2.click(
1089
+ uvr,
1090
+ [
1091
+ model_choose,
1092
+ dir_wav_input,
1093
+ opt_vocal_root,
1094
+ wav_inputs,
1095
+ opt_ins_root,
1096
+ agg,
1097
+ format0,
1098
+ ],
1099
+ [vc_output4],
1100
+ api_name="uvr_convert",
1101
+ )
1102
+ with gr.TabItem(i18n("训练")):
1103
  gr.Markdown(
1104
+ value=i18n(
1105
+ "step1: 填写实验配置. 实验数据放在logs下, 每个实验一个文件夹, 需手工输入实验名路径, 内含实验配置, 日志, 训练得到的模型文件. "
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1106
  )
 
 
 
 
 
 
 
 
 
 
 
1107
  )
1108
+ with gr.Row():
1109
+ exp_dir1 = gr.Textbox(label=i18n("输入实验名"), value="mi-test")
1110
+ sr2 = gr.Radio(
1111
+ label=i18n("目标采样率"),
1112
+ choices=["40k", "48k"],
1113
+ value="40k",
1114
+ interactive=True,
1115
+ )
1116
+ if_f0_3 = gr.Radio(
1117
+ label=i18n("模型是否带音高指导(唱歌一定要, 语音可以不要)"),
1118
+ choices=[True, False],
1119
+ value=True,
1120
+ interactive=True,
1121
+ )
1122
+ version19 = gr.Radio(
1123
+ label=i18n("版本"),
1124
+ choices=["v1", "v2"],
1125
+ value="v2",
1126
+ interactive=True,
1127
+ visible=True,
1128
+ )
1129
+ np7 = gr.Slider(
1130
+ minimum=0,
1131
+ maximum=config.n_cpu,
1132
+ step=1,
1133
+ label=i18n("提取音高和处理数据使用的CPU进程数"),
1134
+ value=int(np.ceil(config.n_cpu / 1.5)),
1135
+ interactive=True,
1136
+ )
1137
+ with gr.Group(): # 暂时单人的, 后面支持最多4人的#数据处理
1138
+ gr.Markdown(
1139
+ value=i18n(
1140
+ "step2a: 自动遍历训练文件夹下所有可解码成音频的文件并进行切片归一化, 在实验目录下生成2个wav文件夹; 暂时只支持单人训练. "
1141
+ )
1142
+ )
1143
+ with gr.Row():
1144
+ trainset_dir4 = gr.Textbox(
1145
+ label=i18n("输入训练文件夹路径"), value=i18n("E:\\语音音频+标注\\米津玄师\\src")
1146
+ )
1147
+ spk_id5 = gr.Slider(
1148
+ minimum=0,
1149
+ maximum=4,
1150
+ step=1,
1151
+ label=i18n("请指定说话人id"),
1152
+ value=0,
1153
+ interactive=True,
1154
+ )
1155
+ but1 = gr.Button(i18n("处理数据"), variant="primary")
1156
+ info1 = gr.Textbox(label=i18n("输出信息"), value="")
1157
+ but1.click(
1158
+ preprocess_dataset,
1159
+ [trainset_dir4, exp_dir1, sr2, np7],
1160
+ [info1],
1161
+ api_name="train_preprocess",
1162
+ )
1163
+ with gr.Group():
1164
+ gr.Markdown(value=i18n("step2b: 使用CPU提取音高(如果模型带音高), 使用GPU提取特征(选择卡号)"))
1165
+ with gr.Row():
1166
+ with gr.Column():
1167
+ gpus6 = gr.Textbox(
1168
+ label=i18n("以-分隔输入使用的卡号, 例如 0-1-2 使用卡0和卡1和卡2"),
1169
+ value=gpus,
1170
+ interactive=True,
1171
+ visible=F0GPUVisible,
1172
+ )
1173
+ gpu_info9 = gr.Textbox(
1174
+ label=i18n("显卡信息"), value=gpu_info, visible=F0GPUVisible
1175
+ )
1176
+ with gr.Column():
1177
+ f0method8 = gr.Radio(
1178
+ label=i18n(
1179
+ "选择音高提取算法:输入歌声可用pm提速,高质量语音但CPU差可用dio提速,harvest质量更好但慢,rmvpe效果最好且微吃CPU/GPU"
1180
+ ),
1181
+ choices=["pm", "harvest", "dio", "rmvpe", "rmvpe_gpu"],
1182
+ value="rmvpe_gpu",
1183
+ interactive=True,
1184
+ )
1185
+ gpus_rmvpe = gr.Textbox(
1186
+ label=i18n(
1187
+ "rmvpe卡号配置:以-分隔输入使用的不同进程卡号,例如0-0-1使用在卡0上跑2个进程并在卡1上跑1个进程"
1188
+ ),
1189
+ value="%s-%s" % (gpus, gpus),
1190
+ interactive=True,
1191
+ visible=F0GPUVisible,
1192
+ )
1193
+ but2 = gr.Button(i18n("特征提取"), variant="primary")
1194
+ info2 = gr.Textbox(label=i18n("输出信息"), value="", max_lines=8)
1195
+ f0method8.change(
1196
+ fn=change_f0_method,
1197
+ inputs=[f0method8],
1198
+ outputs=[gpus_rmvpe],
1199
+ )
1200
+ but2.click(
1201
+ extract_f0_feature,
1202
+ [
1203
+ gpus6,
1204
+ np7,
1205
+ f0method8,
1206
+ if_f0_3,
1207
+ exp_dir1,
1208
+ version19,
1209
+ gpus_rmvpe,
1210
+ ],
1211
+ [info2],
1212
+ api_name="train_extract_f0_feature",
1213
+ )
1214
+ with gr.Group():
1215
+ gr.Markdown(value=i18n("step3: 填写训练设置, 开始训练模型和索引"))
1216
+ with gr.Row():
1217
+ save_epoch10 = gr.Slider(
1218
+ minimum=1,
1219
+ maximum=50,
1220
+ step=1,
1221
+ label=i18n("保存频率save_every_epoch"),
1222
+ value=5,
1223
+ interactive=True,
1224
+ )
1225
+ total_epoch11 = gr.Slider(
1226
+ minimum=2,
1227
+ maximum=1000,
1228
+ step=1,
1229
+ label=i18n("总训练轮数total_epoch"),
1230
+ value=20,
1231
+ interactive=True,
1232
+ )
1233
+ batch_size12 = gr.Slider(
1234
+ minimum=1,
1235
+ maximum=40,
1236
+ step=1,
1237
+ label=i18n("每张显卡的batch_size"),
1238
+ value=default_batch_size,
1239
+ interactive=True,
1240
+ )
1241
+ if_save_latest13 = gr.Radio(
1242
+ label=i18n("是否仅保存最新的ckpt文件以节省硬盘空间"),
1243
+ choices=[i18n("是"), i18n("否")],
1244
+ value=i18n("否"),
1245
+ interactive=True,
1246
+ )
1247
+ if_cache_gpu17 = gr.Radio(
1248
+ label=i18n(
1249
+ "是否缓存所有训练集至显存. 10min以下小数据可缓存以加速训练, 大数据缓存会炸显存也加不了多少速"
1250
+ ),
1251
+ choices=[i18n("是"), i18n("否")],
1252
+ value=i18n("否"),
1253
+ interactive=True,
1254
+ )
1255
+ if_save_every_weights18 = gr.Radio(
1256
+ label=i18n("是否在每次保存时间点将最终小模型保存至weights文件夹"),
1257
+ choices=[i18n("是"), i18n("否")],
1258
+ value=i18n("否"),
1259
+ interactive=True,
1260
+ )
1261
+ with gr.Row():
1262
+ pretrained_G14 = gr.Textbox(
1263
+ label=i18n("加载预训练底模G路径"),
1264
+ value="assets/pretrained_v2/f0G40k.pth",
1265
+ interactive=True,
1266
+ )
1267
+ pretrained_D15 = gr.Textbox(
1268
+ label=i18n("加载预训练底模D路径"),
1269
+ value="assets/pretrained_v2/f0D40k.pth",
1270
+ interactive=True,
1271
+ )
1272
+ sr2.change(
1273
+ change_sr2,
1274
+ [sr2, if_f0_3, version19],
1275
+ [pretrained_G14, pretrained_D15],
1276
+ )
1277
+ version19.change(
1278
+ change_version19,
1279
+ [sr2, if_f0_3, version19],
1280
+ [pretrained_G14, pretrained_D15, sr2],
1281
+ )
1282
+ if_f0_3.change(
1283
+ change_f0,
1284
+ [if_f0_3, sr2, version19],
1285
+ [f0method8, gpus_rmvpe, pretrained_G14, pretrained_D15],
1286
+ )
1287
+ gpus16 = gr.Textbox(
1288
+ label=i18n("以-分隔输入使用的卡号, 例如 0-1-2 使用卡0和卡1和卡2"),
1289
+ value=gpus,
1290
+ interactive=True,
1291
+ )
1292
+ but3 = gr.Button(i18n("训练模型"), variant="primary")
1293
+ but4 = gr.Button(i18n("训练特征索引"), variant="primary")
1294
+ but5 = gr.Button(i18n("一键训练"), variant="primary")
1295
+ info3 = gr.Textbox(label=i18n("输出信息"), value="", max_lines=10)
1296
+ but3.click(
1297
+ click_train,
1298
+ [
1299
+ exp_dir1,
1300
+ sr2,
1301
+ if_f0_3,
1302
+ spk_id5,
1303
+ save_epoch10,
1304
+ total_epoch11,
1305
+ batch_size12,
1306
+ if_save_latest13,
1307
+ pretrained_G14,
1308
+ pretrained_D15,
1309
+ gpus16,
1310
+ if_cache_gpu17,
1311
+ if_save_every_weights18,
1312
+ version19,
1313
+ ],
1314
+ info3,
1315
+ api_name="train_start",
1316
+ )
1317
+ but4.click(train_index, [exp_dir1, version19], info3)
1318
+ but5.click(
1319
+ train1key,
1320
+ [
1321
+ exp_dir1,
1322
+ sr2,
1323
+ if_f0_3,
1324
+ trainset_dir4,
1325
+ spk_id5,
1326
+ np7,
1327
+ f0method8,
1328
+ save_epoch10,
1329
+ total_epoch11,
1330
+ batch_size12,
1331
+ if_save_latest13,
1332
+ pretrained_G14,
1333
+ pretrained_D15,
1334
+ gpus16,
1335
+ if_cache_gpu17,
1336
+ if_save_every_weights18,
1337
+ version19,
1338
+ gpus_rmvpe,
1339
+ ],
1340
+ info3,
1341
+ api_name="train_start_all",
1342
+ )
1343
+
1344
+ with gr.TabItem(i18n("ckpt处理")):
1345
+ with gr.Group():
1346
+ gr.Markdown(value=i18n("模型融合, 可用于测试音色融合"))
1347
+ with gr.Row():
1348
+ ckpt_a = gr.Textbox(label=i18n("A模型路径"), value="", interactive=True)
1349
+ ckpt_b = gr.Textbox(label=i18n("B模型路径"), value="", interactive=True)
1350
+ alpha_a = gr.Slider(
1351
+ minimum=0,
1352
+ maximum=1,
1353
+ label=i18n("A模型权重"),
1354
+ value=0.5,
1355
+ interactive=True,
1356
+ )
1357
+ with gr.Row():
1358
+ sr_ = gr.Radio(
1359
+ label=i18n("目标采样率"),
1360
+ choices=["40k", "48k"],
1361
+ value="40k",
1362
+ interactive=True,
1363
+ )
1364
+ if_f0_ = gr.Radio(
1365
+ label=i18n("模型是否带音高指导"),
1366
+ choices=[i18n("是"), i18n("否")],
1367
+ value=i18n("是"),
1368
+ interactive=True,
1369
+ )
1370
+ info__ = gr.Textbox(
1371
+ label=i18n("要置入的模型信息"), value="", max_lines=8, interactive=True
1372
+ )
1373
+ name_to_save0 = gr.Textbox(
1374
+ label=i18n("保存的模型名不带后缀"),
1375
+ value="",
1376
+ max_lines=1,
1377
+ interactive=True,
1378
+ )
1379
+ version_2 = gr.Radio(
1380
+ label=i18n("模型版本型号"),
1381
+ choices=["v1", "v2"],
1382
+ value="v1",
1383
+ interactive=True,
1384
+ )
1385
+ with gr.Row():
1386
+ but6 = gr.Button(i18n("融合"), variant="primary")
1387
+ info4 = gr.Textbox(label=i18n("输出信息"), value="", max_lines=8)
1388
+ but6.click(
1389
+ merge,
1390
+ [
1391
+ ckpt_a,
1392
+ ckpt_b,
1393
+ alpha_a,
1394
+ sr_,
1395
+ if_f0_,
1396
+ info__,
1397
+ name_to_save0,
1398
+ version_2,
1399
+ ],
1400
+ info4,
1401
+ api_name="ckpt_merge",
1402
+ ) # def merge(path1,path2,alpha1,sr,f0,info):
1403
+ with gr.Group():
1404
+ gr.Markdown(value=i18n("修改模型信息(仅支持weights文件夹下提取的小模型文件)"))
1405
+ with gr.Row():
1406
+ ckpt_path0 = gr.Textbox(
1407
+ label=i18n("模型路径"), value="", interactive=True
1408
+ )
1409
+ info_ = gr.Textbox(
1410
+ label=i18n("要改的模型信息"), value="", max_lines=8, interactive=True
1411
+ )
1412
+ name_to_save1 = gr.Textbox(
1413
+ label=i18n("保存的文件名, 默认空为和源文件同名"),
1414
+ value="",
1415
+ max_lines=8,
1416
+ interactive=True,
1417
+ )
1418
+ with gr.Row():
1419
+ but7 = gr.Button(i18n("修改"), variant="primary")
1420
+ info5 = gr.Textbox(label=i18n("输出信息"), value="", max_lines=8)
1421
+ but7.click(
1422
+ change_info,
1423
+ [ckpt_path0, info_, name_to_save1],
1424
+ info5,
1425
+ api_name="ckpt_modify",
1426
+ )
1427
+ with gr.Group():
1428
+ gr.Markdown(value=i18n("查看模型信息(仅支持weights文件夹下提取的小模型文件)"))
1429
+ with gr.Row():
1430
+ ckpt_path1 = gr.Textbox(
1431
+ label=i18n("模型路径"), value="", interactive=True
1432
+ )
1433
+ but8 = gr.Button(i18n("查看"), variant="primary")
1434
+ info6 = gr.Textbox(label=i18n("输出信息"), value="", max_lines=8)
1435
+ but8.click(show_info, [ckpt_path1], info6, api_name="ckpt_show")
1436
+ with gr.Group():
1437
+ gr.Markdown(
1438
+ value=i18n(
1439
+ "模型提取(输入logs文件夹下大文件模型路径),适用于训一半不想训了模型没有自动提取保存小文件模型,或者想测试中间模型的情况"
1440
+ )
1441
+ )
1442
+ with gr.Row():
1443
+ ckpt_path2 = gr.Textbox(
1444
+ label=i18n("模型路径"),
1445
+ value="E:\\codes\\py39\\logs\\mi-test_f0_48k\\G_23333.pth",
1446
+ interactive=True,
1447
+ )
1448
+ save_name = gr.Textbox(
1449
+ label=i18n("保存名"), value="", interactive=True
1450
+ )
1451
+ sr__ = gr.Radio(
1452
+ label=i18n("目标采样率"),
1453
+ choices=["32k", "40k", "48k"],
1454
+ value="40k",
1455
+ interactive=True,
1456
+ )
1457
+ if_f0__ = gr.Radio(
1458
+ label=i18n("模型是否带音高指导,1是0否"),
1459
+ choices=["1", "0"],
1460
+ value="1",
1461
+ interactive=True,
1462
+ )
1463
+ version_1 = gr.Radio(
1464
+ label=i18n("模型版本型号"),
1465
+ choices=["v1", "v2"],
1466
+ value="v2",
1467
+ interactive=True,
1468
+ )
1469
+ info___ = gr.Textbox(
1470
+ label=i18n("要置入的模型信息"), value="", max_lines=8, interactive=True
1471
+ )
1472
+ but9 = gr.Button(i18n("提取"), variant="primary")
1473
+ info7 = gr.Textbox(label=i18n("输出信息"), value="", max_lines=8)
1474
+ ckpt_path2.change(
1475
+ change_info_, [ckpt_path2], [sr__, if_f0__, version_1]
1476
+ )
1477
+ but9.click(
1478
+ extract_small_model,
1479
+ [ckpt_path2, save_name, sr__, if_f0__, info___, version_1],
1480
+ info7,
1481
+ api_name="ckpt_extract",
1482
+ )
1483
+
1484
+ with gr.TabItem(i18n("Onnx导出")):
1485
+ with gr.Row():
1486
+ ckpt_dir = gr.Textbox(label=i18n("RVC模型路径"), value="", interactive=True)
1487
+ with gr.Row():
1488
+ onnx_dir = gr.Textbox(
1489
+ label=i18n("Onnx输出路径"), value="", interactive=True
1490
+ )
1491
+ with gr.Row():
1492
+ infoOnnx = gr.Label(label="info")
1493
+ with gr.Row():
1494
+ butOnnx = gr.Button(i18n("导出Onnx模型"), variant="primary")
1495
+ butOnnx.click(
1496
+ export_onnx, [ckpt_dir, onnx_dir], infoOnnx, api_name="export_onnx"
1497
  )
1498
 
1499
+ tab_faq = i18n("常见问题解答")
1500
+ with gr.TabItem(tab_faq):
1501
+ try:
1502
+ if tab_faq == "常见问题解答":
1503
+ with open("docs/cn/faq.md", "r", encoding="utf8") as f:
1504
+ info = f.read()
1505
+ else:
1506
+ with open("docs/en/faq_en.md", "r", encoding="utf8") as f:
1507
+ info = f.read()
1508
+ gr.Markdown(value=info)
1509
+ except:
1510
+ gr.Markdown(traceback.format_exc())
1511
 
1512
+ if config.iscolab:
1513
+ app.queue(concurrency_count=511, max_size=1022).launch(share=True)
1514
+ else:
1515
+ app.queue(concurrency_count=511, max_size=1022).launch(
1516
+ server_name="0.0.0.0",
1517
+ inbrowser=not config.noautoopen,
1518
+ server_port=config.listen_port,
1519
+ quiet=True,
1520
+ )