sumandeng commited on
Commit
29466fc
·
1 Parent(s): 87d5e31

rename webui.py to app.py

Browse files
Files changed (1) hide show
  1. app.py +792 -0
app.py ADDED
@@ -0,0 +1,792 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os,shutil,sys,pdb,re
2
+ now_dir = os.getcwd()
3
+ sys.path.append(now_dir)
4
+ import json,yaml,warnings,torch
5
+ import platform
6
+ import psutil
7
+ import signal
8
+
9
+ warnings.filterwarnings("ignore")
10
+ torch.manual_seed(233333)
11
+ tmp = os.path.join(now_dir, "TEMP")
12
+ os.makedirs(tmp, exist_ok=True)
13
+ os.environ["TEMP"] = tmp
14
+ if(os.path.exists(tmp)):
15
+ for name in os.listdir(tmp):
16
+ if(name=="jieba.cache"):continue
17
+ path="%s/%s"%(tmp,name)
18
+ delete=os.remove if os.path.isfile(path) else shutil.rmtree
19
+ try:
20
+ delete(path)
21
+ except Exception as e:
22
+ print(str(e))
23
+ pass
24
+ import site
25
+ site_packages_roots = []
26
+ for path in site.getsitepackages():
27
+ if "packages" in path:
28
+ site_packages_roots.append(path)
29
+ if(site_packages_roots==[]):site_packages_roots=["%s/runtime/Lib/site-packages" % now_dir]
30
+ #os.environ["OPENBLAS_NUM_THREADS"] = "4"
31
+ os.environ["no_proxy"] = "localhost, 127.0.0.1, ::1"
32
+ os.environ["all_proxy"] = ""
33
+ for site_packages_root in site_packages_roots:
34
+ if os.path.exists(site_packages_root):
35
+ try:
36
+ with open("%s/users.pth" % (site_packages_root), "w") as f:
37
+ f.write(
38
+ "%s\n%s/tools\n%s/tools/damo_asr\n%s/GPT_SoVITS\n%s/tools/uvr5"
39
+ % (now_dir, now_dir, now_dir, now_dir, now_dir)
40
+ )
41
+ break
42
+ except PermissionError:
43
+ pass
44
+ from tools import my_utils
45
+ import traceback
46
+ import shutil
47
+ import pdb
48
+ import gradio as gr
49
+ from subprocess import Popen
50
+ import signal
51
+ from config import python_exec,infer_device,is_half,exp_root,webui_port_main,webui_port_infer_tts,webui_port_uvr5,webui_port_subfix,is_share
52
+ from tools.i18n.i18n import I18nAuto
53
+ i18n = I18nAuto()
54
+ from scipy.io import wavfile
55
+ from tools.my_utils import load_audio
56
+ from multiprocessing import cpu_count
57
+
58
+ os.environ['PYTORCH_ENABLE_MPS_FALLBACK'] = '1' # 当遇到mps不支持的步骤时使用cpu
59
+
60
+ n_cpu=cpu_count()
61
+
62
+ ngpu = torch.cuda.device_count()
63
+ gpu_infos = []
64
+ mem = []
65
+ if_gpu_ok = False
66
+
67
+ # 判断是否有能用来训练和加速推理的N卡
68
+ if torch.cuda.is_available() or ngpu != 0:
69
+ for i in range(ngpu):
70
+ gpu_name = torch.cuda.get_device_name(i)
71
+ if any(value in gpu_name.upper()for value in ["10","16","20","30","40","A2","A3","A4","P4","A50","500","A60","70","80","90","M4","T4","TITAN","L4","4060"]):
72
+ # A10#A100#V100#A40#P40#M40#K80#A4500
73
+ if_gpu_ok = True # 至少有一张能用的N卡
74
+ gpu_infos.append("%s\t%s" % (i, gpu_name))
75
+ mem.append(int(torch.cuda.get_device_properties(i).total_memory/ 1024/ 1024/ 1024+ 0.4))
76
+ # 判断是否支持mps加速
77
+ if torch.backends.mps.is_available():
78
+ if_gpu_ok = True
79
+ gpu_infos.append("%s\t%s" % ("0", "Apple GPU"))
80
+ mem.append(psutil.virtual_memory().total/ 1024 / 1024 / 1024) # 实测使用系统内存作为显存不会爆显存
81
+
82
+ if if_gpu_ok and len(gpu_infos) > 0:
83
+ gpu_info = "\n".join(gpu_infos)
84
+ default_batch_size = min(mem) // 2
85
+ else:
86
+ gpu_info = i18n("很遗憾您这没有能用的显卡来支持您训练")
87
+ default_batch_size = 1
88
+ gpus = "-".join([i[0] for i in gpu_infos])
89
+
90
+ pretrained_sovits_name="GPT_SoVITS/pretrained_models/s2G488k.pth"
91
+ pretrained_gpt_name="GPT_SoVITS/pretrained_models/s1bert25hz-2kh-longer-epoch=68e-step=50232.ckpt"
92
+ def get_weights_names():
93
+ SoVITS_names = [pretrained_sovits_name]
94
+ for name in os.listdir(SoVITS_weight_root):
95
+ if name.endswith(".pth"):SoVITS_names.append(name)
96
+ GPT_names = [pretrained_gpt_name]
97
+ for name in os.listdir(GPT_weight_root):
98
+ if name.endswith(".ckpt"): GPT_names.append(name)
99
+ return SoVITS_names,GPT_names
100
+ SoVITS_weight_root="SoVITS_weights"
101
+ GPT_weight_root="GPT_weights"
102
+ os.makedirs(SoVITS_weight_root,exist_ok=True)
103
+ os.makedirs(GPT_weight_root,exist_ok=True)
104
+ SoVITS_names,GPT_names = get_weights_names()
105
+
106
+ def custom_sort_key(s):
107
+ # 使用正则表达式提取字符串中的数字部分和非数字部分
108
+ parts = re.split('(\d+)', s)
109
+ # 将数字部分转换为整数,非数字部分保持不变
110
+ parts = [int(part) if part.isdigit() else part for part in parts]
111
+ return parts
112
+
113
+ def change_choices():
114
+ SoVITS_names, GPT_names = get_weights_names()
115
+ return {"choices": sorted(SoVITS_names,key=custom_sort_key), "__type__": "update"}, {"choices": sorted(GPT_names,key=custom_sort_key), "__type__": "update"}
116
+
117
+ p_label=None
118
+ p_uvr5=None
119
+ p_asr=None
120
+ p_tts_inference=None
121
+
122
+ def kill_proc_tree(pid, including_parent=True):
123
+ try:
124
+ parent = psutil.Process(pid)
125
+ except psutil.NoSuchProcess:
126
+ # Process already terminated
127
+ return
128
+
129
+ children = parent.children(recursive=True)
130
+ for child in children:
131
+ try:
132
+ os.kill(child.pid, signal.SIGTERM) # or signal.SIGKILL
133
+ except OSError:
134
+ pass
135
+ if including_parent:
136
+ try:
137
+ os.kill(parent.pid, signal.SIGTERM) # or signal.SIGKILL
138
+ except OSError:
139
+ pass
140
+
141
+ system=platform.system()
142
+ def kill_process(pid):
143
+ if(system=="Windows"):
144
+ cmd = "taskkill /t /f /pid %s" % pid
145
+ os.system(cmd)
146
+ else:
147
+ kill_proc_tree(pid)
148
+
149
+
150
+ def change_label(if_label,path_list):
151
+ global p_label
152
+ if(if_label==True and p_label==None):
153
+ path_list=my_utils.clean_path(path_list)
154
+ cmd = '"%s" tools/subfix_webui.py --load_list "%s" --webui_port %s --is_share %s'%(python_exec,path_list,webui_port_subfix,is_share)
155
+ yield i18n("打标工具WebUI已开启")
156
+ print(cmd)
157
+ p_label = Popen(cmd, shell=True)
158
+ elif(if_label==False and p_label!=None):
159
+ kill_process(p_label.pid)
160
+ p_label=None
161
+ yield i18n("打标工具WebUI已关闭")
162
+
163
+ def change_uvr5(if_uvr5):
164
+ global p_uvr5
165
+ if(if_uvr5==True and p_uvr5==None):
166
+ cmd = '"%s" tools/uvr5/webui.py "%s" %s %s %s'%(python_exec,infer_device,is_half,webui_port_uvr5,is_share)
167
+ yield i18n("UVR5已开启")
168
+ print(cmd)
169
+ p_uvr5 = Popen(cmd, shell=True)
170
+ elif(if_uvr5==False and p_uvr5!=None):
171
+ kill_process(p_uvr5.pid)
172
+ p_uvr5=None
173
+ yield i18n("UVR5已关闭")
174
+
175
+ def change_tts_inference(if_tts,bert_path,cnhubert_base_path,gpu_number,gpt_path,sovits_path):
176
+ global p_tts_inference
177
+ if(if_tts==True and p_tts_inference==None):
178
+ os.environ["gpt_path"]=gpt_path if "/" in gpt_path else "%s/%s"%(GPT_weight_root,gpt_path)
179
+ os.environ["sovits_path"]=sovits_path if "/"in sovits_path else "%s/%s"%(SoVITS_weight_root,sovits_path)
180
+ os.environ["cnhubert_base_path"]=cnhubert_base_path
181
+ os.environ["bert_path"]=bert_path
182
+ os.environ["_CUDA_VISIBLE_DEVICES"]=gpu_number
183
+ os.environ["is_half"]=str(is_half)
184
+ os.environ["infer_ttswebui"]=str(webui_port_infer_tts)
185
+ os.environ["is_share"]=str(is_share)
186
+ cmd = '"%s" GPT_SoVITS/inference_webui.py'%(python_exec)
187
+ yield i18n("TTS推理进程已开启")
188
+ print(cmd)
189
+ p_tts_inference = Popen(cmd, shell=True)
190
+ elif(if_tts==False and p_tts_inference!=None):
191
+ kill_process(p_tts_inference.pid)
192
+ p_tts_inference=None
193
+ yield i18n("TTS推理进程已关闭")
194
+
195
+
196
+ def open_asr(asr_inp_dir):
197
+ global p_asr
198
+ if(p_asr==None):
199
+ asr_inp_dir=my_utils.clean_path(asr_inp_dir)
200
+ cmd = '"%s" tools/damo_asr/cmd-asr.py "%s"'%(python_exec,asr_inp_dir)
201
+ yield "ASR任务开启:%s"%cmd,{"__type__":"update","visible":False},{"__type__":"update","visible":True}
202
+ print(cmd)
203
+ p_asr = Popen(cmd, shell=True)
204
+ p_asr.wait()
205
+ p_asr=None
206
+ yield "ASR任务完成",{"__type__":"update","visible":True},{"__type__":"update","visible":False}
207
+ else:
208
+ yield "已有正在进行的ASR任务,需先终止才能开启下一次任务",{"__type__":"update","visible":False},{"__type__":"update","visible":True}
209
+
210
+ def close_asr():
211
+ global p_asr
212
+ if(p_asr!=None):
213
+ kill_process(p_asr.pid)
214
+ p_asr=None
215
+ return "已终止ASR进程",{"__type__":"update","visible":True},{"__type__":"update","visible":False}
216
+
217
+ p_train_SoVITS=None
218
+ def open1Ba(batch_size,total_epoch,exp_name,text_low_lr_rate,if_save_latest,if_save_every_weights,save_every_epoch,gpu_numbers1Ba,pretrained_s2G,pretrained_s2D):
219
+ global p_train_SoVITS
220
+ if(p_train_SoVITS==None):
221
+ with open("GPT_SoVITS/configs/s2.json")as f:
222
+ data=f.read()
223
+ data=json.loads(data)
224
+ s2_dir="%s/%s"%(exp_root,exp_name)
225
+ os.makedirs("%s/logs_s2"%(s2_dir),exist_ok=True)
226
+ if(is_half==False):
227
+ data["train"]["fp16_run"]=False
228
+ batch_size=max(1,batch_size//2)
229
+ data["train"]["batch_size"]=batch_size
230
+ data["train"]["epochs"]=total_epoch
231
+ data["train"]["text_low_lr_rate"]=text_low_lr_rate
232
+ data["train"]["pretrained_s2G"]=pretrained_s2G
233
+ data["train"]["pretrained_s2D"]=pretrained_s2D
234
+ data["train"]["if_save_latest"]=if_save_latest
235
+ data["train"]["if_save_every_weights"]=if_save_every_weights
236
+ data["train"]["save_every_epoch"]=save_every_epoch
237
+ data["train"]["gpu_numbers"]=gpu_numbers1Ba
238
+ data["data"]["exp_dir"]=data["s2_ckpt_dir"]=s2_dir
239
+ data["save_weight_dir"]=SoVITS_weight_root
240
+ data["name"]=exp_name
241
+ tmp_config_path="%s/tmp_s2.json"%tmp
242
+ with open(tmp_config_path,"w")as f:f.write(json.dumps(data))
243
+
244
+ cmd = '"%s" GPT_SoVITS/s2_train.py --config "%s"'%(python_exec,tmp_config_path)
245
+ yield "SoVITS训练开始:%s"%cmd,{"__type__":"update","visible":False},{"__type__":"update","visible":True}
246
+ print(cmd)
247
+ p_train_SoVITS = Popen(cmd, shell=True)
248
+ p_train_SoVITS.wait()
249
+ p_train_SoVITS=None
250
+ yield "SoVITS训练完成",{"__type__":"update","visible":True},{"__type__":"update","visible":False}
251
+ else:
252
+ yield "已有正在进行的SoVITS训练任务,需先终止才能开启下一次任务",{"__type__":"update","visible":False},{"__type__":"update","visible":True}
253
+
254
+ def close1Ba():
255
+ global p_train_SoVITS
256
+ if(p_train_SoVITS!=None):
257
+ kill_process(p_train_SoVITS.pid)
258
+ p_train_SoVITS=None
259
+ return "已终止SoVITS训练",{"__type__":"update","visible":True},{"__type__":"update","visible":False}
260
+
261
+ p_train_GPT=None
262
+ def open1Bb(batch_size,total_epoch,exp_name,if_save_latest,if_save_every_weights,save_every_epoch,gpu_numbers,pretrained_s1):
263
+ global p_train_GPT
264
+ if(p_train_GPT==None):
265
+ with open("GPT_SoVITS/configs/s1longer.yaml")as f:
266
+ data=f.read()
267
+ data=yaml.load(data, Loader=yaml.FullLoader)
268
+ s1_dir="%s/%s"%(exp_root,exp_name)
269
+ os.makedirs("%s/logs_s1"%(s1_dir),exist_ok=True)
270
+ if(is_half==False):
271
+ data["train"]["precision"]="32"
272
+ batch_size = max(1, batch_size // 2)
273
+ data["train"]["batch_size"]=batch_size
274
+ data["train"]["epochs"]=total_epoch
275
+ data["pretrained_s1"]=pretrained_s1
276
+ data["train"]["save_every_n_epoch"]=save_every_epoch
277
+ data["train"]["if_save_every_weights"]=if_save_every_weights
278
+ data["train"]["if_save_latest"]=if_save_latest
279
+ data["train"]["half_weights_save_dir"]=GPT_weight_root
280
+ data["train"]["exp_name"]=exp_name
281
+ data["train_semantic_path"]="%s/6-name2semantic.tsv"%s1_dir
282
+ data["train_phoneme_path"]="%s/2-name2text.txt"%s1_dir
283
+ data["output_dir"]="%s/logs_s1"%s1_dir
284
+
285
+ os.environ["_CUDA_VISIBLE_DEVICES"]=gpu_numbers.replace("-",",")
286
+ os.environ["hz"]="25hz"
287
+ tmp_config_path="%s/tmp_s1.yaml"%tmp
288
+ with open(tmp_config_path, "w") as f:f.write(yaml.dump(data, default_flow_style=False))
289
+ # cmd = '"%s" GPT_SoVITS/s1_train.py --config_file "%s" --train_semantic_path "%s/6-name2semantic.tsv" --train_phoneme_path "%s/2-name2text.txt" --output_dir "%s/logs_s1"'%(python_exec,tmp_config_path,s1_dir,s1_dir,s1_dir)
290
+ cmd = '"%s" GPT_SoVITS/s1_train.py --config_file "%s" '%(python_exec,tmp_config_path)
291
+ yield "GPT训练开始:%s"%cmd,{"__type__":"update","visible":False},{"__type__":"update","visible":True}
292
+ print(cmd)
293
+ p_train_GPT = Popen(cmd, shell=True)
294
+ p_train_GPT.wait()
295
+ p_train_GPT=None
296
+ yield "GPT训练完成",{"__type__":"update","visible":True},{"__type__":"update","visible":False}
297
+ else:
298
+ yield "已有正在进行的GPT训练任务,需先终止才能开启下一次任务",{"__type__":"update","visible":False},{"__type__":"update","visible":True}
299
+
300
+ def close1Bb():
301
+ global p_train_GPT
302
+ if(p_train_GPT!=None):
303
+ kill_process(p_train_GPT.pid)
304
+ p_train_GPT=None
305
+ return "已终止GPT训练",{"__type__":"update","visible":True},{"__type__":"update","visible":False}
306
+
307
+ ps_slice=[]
308
+ def open_slice(inp,opt_root,threshold,min_length,min_interval,hop_size,max_sil_kept,_max,alpha,n_parts):
309
+ global ps_slice
310
+ inp = my_utils.clean_path(inp)
311
+ opt_root = my_utils.clean_path(opt_root)
312
+ if(os.path.exists(inp)==False):
313
+ yield "输入路径不存在",{"__type__":"update","visible":True},{"__type__":"update","visible":False}
314
+ return
315
+ if os.path.isfile(inp):n_parts=1
316
+ elif os.path.isdir(inp):pass
317
+ else:
318
+ yield "输入路径存在但既不是文件也不是文件夹",{"__type__":"update","visible":True},{"__type__":"update","visible":False}
319
+ return
320
+ if (ps_slice == []):
321
+ for i_part in range(n_parts):
322
+ cmd = '"%s" tools/slice_audio.py "%s" "%s" %s %s %s %s %s %s %s %s %s''' % (python_exec,inp, opt_root, threshold, min_length, min_interval, hop_size, max_sil_kept, _max, alpha, i_part, n_parts)
323
+ print(cmd)
324
+ p = Popen(cmd, shell=True)
325
+ ps_slice.append(p)
326
+ yield "切割执行中", {"__type__": "update", "visible": False}, {"__type__": "update", "visible": True}
327
+ for p in ps_slice:
328
+ p.wait()
329
+ ps_slice=[]
330
+ yield "切割结束",{"__type__":"update","visible":True},{"__type__":"update","visible":False}
331
+ else:
332
+ yield "已有正在进行的切割任务,需先终止才能开启下一次任务", {"__type__": "update", "visible": False}, {"__type__": "update", "visible": True}
333
+
334
+ def close_slice():
335
+ global ps_slice
336
+ if (ps_slice != []):
337
+ for p_slice in ps_slice:
338
+ try:
339
+ kill_process(p_slice.pid)
340
+ except:
341
+ traceback.print_exc()
342
+ ps_slice=[]
343
+ return "已终止所有切割进程", {"__type__": "update", "visible": True}, {"__type__": "update", "visible": False}
344
+
345
+ ps1a=[]
346
+ def open1a(inp_text,inp_wav_dir,exp_name,gpu_numbers,bert_pretrained_dir):
347
+ global ps1a
348
+ inp_text = my_utils.clean_path(inp_text)
349
+ inp_wav_dir = my_utils.clean_path(inp_wav_dir)
350
+ if (ps1a == []):
351
+ opt_dir="%s/%s"%(exp_root,exp_name)
352
+ config={
353
+ "inp_text":inp_text,
354
+ "inp_wav_dir":inp_wav_dir,
355
+ "exp_name":exp_name,
356
+ "opt_dir":opt_dir,
357
+ "bert_pretrained_dir":bert_pretrained_dir,
358
+ }
359
+ gpu_names=gpu_numbers.split("-")
360
+ all_parts=len(gpu_names)
361
+ for i_part in range(all_parts):
362
+ config.update(
363
+ {
364
+ "i_part": str(i_part),
365
+ "all_parts": str(all_parts),
366
+ "_CUDA_VISIBLE_DEVICES": gpu_names[i_part],
367
+ "is_half": str(is_half)
368
+ }
369
+ )
370
+ os.environ.update(config)
371
+ cmd = '"%s" GPT_SoVITS/prepare_datasets/1-get-text.py'%python_exec
372
+ print(cmd)
373
+ p = Popen(cmd, shell=True)
374
+ ps1a.append(p)
375
+ yield "文本进程执行中", {"__type__": "update", "visible": False}, {"__type__": "update", "visible": True}
376
+ for p in ps1a:
377
+ p.wait()
378
+ opt = []
379
+ for i_part in range(all_parts):
380
+ txt_path = "%s/2-name2text-%s.txt" % (opt_dir, i_part)
381
+ with open(txt_path, "r", encoding="utf8") as f:
382
+ opt += f.read().strip("\n").split("\n")
383
+ os.remove(txt_path)
384
+ path_text = "%s/2-name2text.txt" % opt_dir
385
+ with open(path_text, "w", encoding="utf8") as f:
386
+ f.write("\n".join(opt) + "\n")
387
+ ps1a=[]
388
+ yield "文本进程结束",{"__type__":"update","visible":True},{"__type__":"update","visible":False}
389
+ else:
390
+ yield "已有正在进行的文本任务,需先终止才能开启下一次任务", {"__type__": "update", "visible": False}, {"__type__": "update", "visible": True}
391
+
392
+ def close1a():
393
+ global ps1a
394
+ if (ps1a != []):
395
+ for p1a in ps1a:
396
+ try:
397
+ kill_process(p1a.pid)
398
+ except:
399
+ traceback.print_exc()
400
+ ps1a=[]
401
+ return "已终止所有1a进程", {"__type__": "update", "visible": True}, {"__type__": "update", "visible": False}
402
+
403
+ ps1b=[]
404
+ def open1b(inp_text,inp_wav_dir,exp_name,gpu_numbers,ssl_pretrained_dir):
405
+ global ps1b
406
+ inp_text = my_utils.clean_path(inp_text)
407
+ inp_wav_dir = my_utils.clean_path(inp_wav_dir)
408
+ if (ps1b == []):
409
+ config={
410
+ "inp_text":inp_text,
411
+ "inp_wav_dir":inp_wav_dir,
412
+ "exp_name":exp_name,
413
+ "opt_dir":"%s/%s"%(exp_root,exp_name),
414
+ "cnhubert_base_dir":ssl_pretrained_dir,
415
+ "is_half": str(is_half)
416
+ }
417
+ gpu_names=gpu_numbers.split("-")
418
+ all_parts=len(gpu_names)
419
+ for i_part in range(all_parts):
420
+ config.update(
421
+ {
422
+ "i_part": str(i_part),
423
+ "all_parts": str(all_parts),
424
+ "_CUDA_VISIBLE_DEVICES": gpu_names[i_part],
425
+ }
426
+ )
427
+ os.environ.update(config)
428
+ cmd = '"%s" GPT_SoVITS/prepare_datasets/2-get-hubert-wav32k.py'%python_exec
429
+ print(cmd)
430
+ p = Popen(cmd, shell=True)
431
+ ps1b.append(p)
432
+ yield "SSL提取进程执行中", {"__type__": "update", "visible": False}, {"__type__": "update", "visible": True}
433
+ for p in ps1b:
434
+ p.wait()
435
+ ps1b=[]
436
+ yield "SSL提取进程结束",{"__type__":"update","visible":True},{"__type__":"update","visible":False}
437
+ else:
438
+ yield "已有正在进行的SSL提取任务,需先终止才能开启下一次任务", {"__type__": "update", "visible": False}, {"__type__": "update", "visible": True}
439
+
440
+ def close1b():
441
+ global ps1b
442
+ if (ps1b != []):
443
+ for p1b in ps1b:
444
+ try:
445
+ kill_process(p1b.pid)
446
+ except:
447
+ traceback.print_exc()
448
+ ps1b=[]
449
+ return "已终止所有1b进程", {"__type__": "update", "visible": True}, {"__type__": "update", "visible": False}
450
+
451
+ ps1c=[]
452
+ def open1c(inp_text,exp_name,gpu_numbers,pretrained_s2G_path):
453
+ global ps1c
454
+ inp_text = my_utils.clean_path(inp_text)
455
+ if (ps1c == []):
456
+ opt_dir="%s/%s"%(exp_root,exp_name)
457
+ config={
458
+ "inp_text":inp_text,
459
+ "exp_name":exp_name,
460
+ "opt_dir":opt_dir,
461
+ "pretrained_s2G":pretrained_s2G_path,
462
+ "s2config_path":"GPT_SoVITS/configs/s2.json",
463
+ "is_half": str(is_half)
464
+ }
465
+ gpu_names=gpu_numbers.split("-")
466
+ all_parts=len(gpu_names)
467
+ for i_part in range(all_parts):
468
+ config.update(
469
+ {
470
+ "i_part": str(i_part),
471
+ "all_parts": str(all_parts),
472
+ "_CUDA_VISIBLE_DEVICES": gpu_names[i_part],
473
+ }
474
+ )
475
+ os.environ.update(config)
476
+ cmd = '"%s" GPT_SoVITS/prepare_datasets/3-get-semantic.py'%python_exec
477
+ print(cmd)
478
+ p = Popen(cmd, shell=True)
479
+ ps1c.append(p)
480
+ yield "语义token提取进程执行中", {"__type__": "update", "visible": False}, {"__type__": "update", "visible": True}
481
+ for p in ps1c:
482
+ p.wait()
483
+ opt = ["item_name\tsemantic_audio"]
484
+ path_semantic = "%s/6-name2semantic.tsv" % opt_dir
485
+ for i_part in range(all_parts):
486
+ semantic_path = "%s/6-name2semantic-%s.tsv" % (opt_dir, i_part)
487
+ with open(semantic_path, "r", encoding="utf8") as f:
488
+ opt += f.read().strip("\n").split("\n")
489
+ os.remove(semantic_path)
490
+ with open(path_semantic, "w", encoding="utf8") as f:
491
+ f.write("\n".join(opt) + "\n")
492
+ ps1c=[]
493
+ yield "语义token提取进程结束",{"__type__":"update","visible":True},{"__type__":"update","visible":False}
494
+ else:
495
+ yield "已有正在进行的语义token提取任务,需先终止才能开启下一次任务", {"__type__": "update", "visible": False}, {"__type__": "update", "visible": True}
496
+
497
+ def close1c():
498
+ global ps1c
499
+ if (ps1c != []):
500
+ for p1c in ps1c:
501
+ try:
502
+ kill_process(p1c.pid)
503
+ except:
504
+ traceback.print_exc()
505
+ ps1c=[]
506
+ return "已终止所有语义token进程", {"__type__": "update", "visible": True}, {"__type__": "update", "visible": False}
507
+ #####inp_text,inp_wav_dir,exp_name,gpu_numbers1a,gpu_numbers1Ba,gpu_numbers1c,bert_pretrained_dir,cnhubert_base_dir,pretrained_s2G
508
+ ps1abc=[]
509
+ def open1abc(inp_text,inp_wav_dir,exp_name,gpu_numbers1a,gpu_numbers1Ba,gpu_numbers1c,bert_pretrained_dir,ssl_pretrained_dir,pretrained_s2G_path):
510
+ global ps1abc
511
+ inp_text = my_utils.clean_path(inp_text)
512
+ inp_wav_dir = my_utils.clean_path(inp_wav_dir)
513
+ if (ps1abc == []):
514
+ opt_dir="%s/%s"%(exp_root,exp_name)
515
+ try:
516
+ #############################1a
517
+ path_text="%s/2-name2text.txt" % opt_dir
518
+ if(os.path.exists(path_text)==False or (os.path.exists(path_text)==True and len(open(path_text,"r",encoding="utf8").read().strip("\n").split("\n"))<2)):
519
+ config={
520
+ "inp_text":inp_text,
521
+ "inp_wav_dir":inp_wav_dir,
522
+ "exp_name":exp_name,
523
+ "opt_dir":opt_dir,
524
+ "bert_pretrained_dir":bert_pretrained_dir,
525
+ "is_half": str(is_half)
526
+ }
527
+ gpu_names=gpu_numbers1a.split("-")
528
+ all_parts=len(gpu_names)
529
+ for i_part in range(all_parts):
530
+ config.update(
531
+ {
532
+ "i_part": str(i_part),
533
+ "all_parts": str(all_parts),
534
+ "_CUDA_VISIBLE_DEVICES": gpu_names[i_part],
535
+ }
536
+ )
537
+ os.environ.update(config)
538
+ cmd = '"%s" GPT_SoVITS/prepare_datasets/1-get-text.py'%python_exec
539
+ print(cmd)
540
+ p = Popen(cmd, shell=True)
541
+ ps1abc.append(p)
542
+ yield "进度:1a-ing", {"__type__": "update", "visible": False}, {"__type__": "update", "visible": True}
543
+ for p in ps1abc:p.wait()
544
+
545
+ opt = []
546
+ for i_part in range(all_parts):#txt_path="%s/2-name2text-%s.txt"%(opt_dir,i_part)
547
+ txt_path = "%s/2-name2text-%s.txt" % (opt_dir, i_part)
548
+ with open(txt_path, "r",encoding="utf8") as f:
549
+ opt += f.read().strip("\n").split("\n")
550
+ os.remove(txt_path)
551
+ with open(path_text, "w",encoding="utf8") as f:
552
+ f.write("\n".join(opt) + "\n")
553
+
554
+ yield "进度:1a-done", {"__type__": "update", "visible": False}, {"__type__": "update", "visible": True}
555
+ ps1abc=[]
556
+ #############################1b
557
+ config={
558
+ "inp_text":inp_text,
559
+ "inp_wav_dir":inp_wav_dir,
560
+ "exp_name":exp_name,
561
+ "opt_dir":opt_dir,
562
+ "cnhubert_base_dir":ssl_pretrained_dir,
563
+ }
564
+ gpu_names=gpu_numbers1Ba.split("-")
565
+ all_parts=len(gpu_names)
566
+ for i_part in range(all_parts):
567
+ config.update(
568
+ {
569
+ "i_part": str(i_part),
570
+ "all_parts": str(all_parts),
571
+ "_CUDA_VISIBLE_DEVICES": gpu_names[i_part],
572
+ }
573
+ )
574
+ os.environ.update(config)
575
+ cmd = '"%s" GPT_SoVITS/prepare_datasets/2-get-hubert-wav32k.py'%python_exec
576
+ print(cmd)
577
+ p = Popen(cmd, shell=True)
578
+ ps1abc.append(p)
579
+ yield "进度:1a-done, 1b-ing", {"__type__": "update", "visible": False}, {"__type__": "update", "visible": True}
580
+ for p in ps1abc:p.wait()
581
+ yield "进度:1a1b-done", {"__type__": "update", "visible": False}, {"__type__": "update", "visible": True}
582
+ ps1abc=[]
583
+ #############################1c
584
+ path_semantic = "%s/6-name2semantic.tsv" % opt_dir
585
+ if(os.path.exists(path_semantic)==False or (os.path.exists(path_semantic)==True and os.path.getsize(path_semantic)<31)):
586
+ config={
587
+ "inp_text":inp_text,
588
+ "exp_name":exp_name,
589
+ "opt_dir":opt_dir,
590
+ "pretrained_s2G":pretrained_s2G_path,
591
+ "s2config_path":"GPT_SoVITS/configs/s2.json",
592
+ }
593
+ gpu_names=gpu_numbers1c.split("-")
594
+ all_parts=len(gpu_names)
595
+ for i_part in range(all_parts):
596
+ config.update(
597
+ {
598
+ "i_part": str(i_part),
599
+ "all_parts": str(all_parts),
600
+ "_CUDA_VISIBLE_DEVICES": gpu_names[i_part],
601
+ }
602
+ )
603
+ os.environ.update(config)
604
+ cmd = '"%s" GPT_SoVITS/prepare_datasets/3-get-semantic.py'%python_exec
605
+ print(cmd)
606
+ p = Popen(cmd, shell=True)
607
+ ps1abc.append(p)
608
+ yield "进度:1a1b-done, 1cing", {"__type__": "update", "visible": False}, {"__type__": "update", "visible": True}
609
+ for p in ps1abc:p.wait()
610
+
611
+ opt = ["item_name\tsemantic_audio"]
612
+ for i_part in range(all_parts):
613
+ semantic_path = "%s/6-name2semantic-%s.tsv" % (opt_dir, i_part)
614
+ with open(semantic_path, "r",encoding="utf8") as f:
615
+ opt += f.read().strip("\n").split("\n")
616
+ os.remove(semantic_path)
617
+ with open(path_semantic, "w",encoding="utf8") as f:
618
+ f.write("\n".join(opt) + "\n")
619
+ yield "进度:all-done", {"__type__": "update", "visible": False}, {"__type__": "update", "visible": True}
620
+ ps1abc = []
621
+ yield "一键三连进程结束", {"__type__": "update", "visible": True}, {"__type__": "update", "visible": False}
622
+ except:
623
+ traceback.print_exc()
624
+ close1abc()
625
+ yield "一键三连中途报错", {"__type__": "update", "visible": True}, {"__type__": "update", "visible": False}
626
+ else:
627
+ yield "已有正在进行的一键三连任务,需先终止才能开启下一次任务", {"__type__": "update", "visible": False}, {"__type__": "update", "visible": True}
628
+
629
+ def close1abc():
630
+ global ps1abc
631
+ if (ps1abc != []):
632
+ for p1abc in ps1abc:
633
+ try:
634
+ kill_process(p1abc.pid)
635
+ except:
636
+ traceback.print_exc()
637
+ ps1abc=[]
638
+ return "已终止所有一键三连进程", {"__type__": "update", "visible": True}, {"__type__": "update", "visible": False}
639
+
640
+ with gr.Blocks(title="GPT-SoVITS WebUI") as app:
641
+ gr.Markdown(
642
+ value=
643
+ i18n("本软件以MIT协议开源, 作者不对软件具备任何控制力, 使用软件者、传播软件导出的声音者自负全责. <br>如不认可该条款, 则不能使用或引用软件包内任何代码和文件. 详见根目录<b>LICENSE</b>.")
644
+ )
645
+ with gr.Tabs():
646
+ with gr.TabItem(i18n("0-前置数据集获取工具")):#提前随机切片防止uvr5爆内存->uvr5->slicer->asr->打标
647
+ gr.Markdown(value=i18n("0a-UVR5人声伴奏分离&去混响去延迟工具"))
648
+ with gr.Row():
649
+ if_uvr5 = gr.Checkbox(label=i18n("是否开启UVR5-WebUI"),show_label=True)
650
+ uvr5_info = gr.Textbox(label=i18n("UVR5进程输出信息"))
651
+ gr.Markdown(value=i18n("0b-语音切分工具"))
652
+ with gr.Row():
653
+ with gr.Row():
654
+ slice_inp_path=gr.Textbox(label=i18n("音频自动切分输入路径,可文件可文件夹"),value="")
655
+ slice_opt_root=gr.Textbox(label=i18n("切分后的子音频的输出根目录"),value="output/slicer_opt")
656
+ threshold=gr.Textbox(label=i18n("threshold:音量小于这个值视作静音的备选切割点"),value="-34")
657
+ min_length=gr.Textbox(label=i18n("min_length:每段最小多长,如果第一段太短一直和后面段连起来直到超过这个值"),value="4000")
658
+ min_interval=gr.Textbox(label=i18n("min_interval:最短切割间隔"),value="300")
659
+ hop_size=gr.Textbox(label=i18n("hop_size:怎么算音量曲线,越小精度越大计算量越高(不是精度越大效果越好)"),value="10")
660
+ max_sil_kept=gr.Textbox(label=i18n("max_sil_kept:切完后静音最多留多长"),value="500")
661
+ with gr.Row():
662
+ open_slicer_button=gr.Button(i18n("开启语音切割"), variant="primary",visible=True)
663
+ close_slicer_button=gr.Button(i18n("终止语音切割"), variant="primary",visible=False)
664
+ _max=gr.Slider(minimum=0,maximum=1,step=0.05,label=i18n("max:归一化后最大值多少"),value=0.9,interactive=True)
665
+ alpha=gr.Slider(minimum=0,maximum=1,step=0.05,label=i18n("alpha_mix:混多少比例归一化后音频进来"),value=0.25,interactive=True)
666
+ n_process=gr.Slider(minimum=1,maximum=n_cpu,step=1,label=i18n("切割使用的进程数"),value=4,interactive=True)
667
+ slicer_info = gr.Textbox(label=i18n("语音切割进程输出信息"))
668
+ gr.Markdown(value=i18n("0c-中文批量离线ASR工具"))
669
+ with gr.Row():
670
+ open_asr_button = gr.Button(i18n("开启离线批量ASR"), variant="primary",visible=True)
671
+ close_asr_button = gr.Button(i18n("终止ASR进程"), variant="primary",visible=False)
672
+ asr_inp_dir = gr.Textbox(
673
+ label=i18n("批量ASR(中文only)输入文件夹路径"),
674
+ value="D:\\RVC1006\\GPT-SoVITS\\raw\\xxx",
675
+ interactive=True,
676
+ )
677
+ asr_info = gr.Textbox(label=i18n("ASR进程输出信息"))
678
+ gr.Markdown(value=i18n("0d-语音文本校对标注工具"))
679
+ with gr.Row():
680
+ if_label = gr.Checkbox(label=i18n("是否开启打标WebUI"),show_label=True)
681
+ path_list = gr.Textbox(
682
+ label=i18n(".list标注文件的路径"),
683
+ value="D:\\RVC1006\\GPT-SoVITS\\raw\\xxx.list",
684
+ interactive=True,
685
+ )
686
+ label_info = gr.Textbox(label=i18n("打标工具进程输出信息"))
687
+ if_label.change(change_label, [if_label,path_list], [label_info])
688
+ if_uvr5.change(change_uvr5, [if_uvr5], [uvr5_info])
689
+ open_asr_button.click(open_asr, [asr_inp_dir], [asr_info,open_asr_button,close_asr_button])
690
+ close_asr_button.click(close_asr, [], [asr_info,open_asr_button,close_asr_button])
691
+ open_slicer_button.click(open_slice, [slice_inp_path,slice_opt_root,threshold,min_length,min_interval,hop_size,max_sil_kept,_max,alpha,n_process], [slicer_info,open_slicer_button,close_slicer_button])
692
+ close_slicer_button.click(close_slice, [], [slicer_info,open_slicer_button,close_slicer_button])
693
+ with gr.TabItem(i18n("1-GPT-SoVITS-TTS")):
694
+ with gr.Row():
695
+ exp_name = gr.Textbox(label=i18n("*实验/模型名"), value="xxx", interactive=True)
696
+ gpu_info = gr.Textbox(label=i18n("显卡信息"), value=gpu_info, visible=True, interactive=False)
697
+ pretrained_s2G = gr.Textbox(label=i18n("预训练的SoVITS-G模型路径"), value="GPT_SoVITS/pretrained_models/s2G488k.pth", interactive=True)
698
+ pretrained_s2D = gr.Textbox(label=i18n("预训练的SoVITS-D模型路径"), value="GPT_SoVITS/pretrained_models/s2D488k.pth", interactive=True)
699
+ pretrained_s1 = gr.Textbox(label=i18n("预训练的GPT模型路径"), value="GPT_SoVITS/pretrained_models/s1bert25hz-2kh-longer-epoch=68e-step=50232.ckpt", interactive=True)
700
+ with gr.TabItem(i18n("1A-训练集格式化工具")):
701
+ gr.Markdown(value=i18n("输出logs/实验名目录下应有23456开头的文件和文件夹"))
702
+ with gr.Row():
703
+ inp_text = gr.Textbox(label=i18n("*文本标注文件"),value=r"D:\RVC1006\GPT-SoVITS\raw\xxx.list",interactive=True)
704
+ inp_wav_dir = gr.Textbox(
705
+ label=i18n("*训练集音频文件目录"),
706
+ # value=r"D:\RVC1006\GPT-SoVITS\raw\xxx",
707
+ interactive=True,
708
+ placeholder=i18n("填切割后音频所在目录!读取的音频文件完整路径=该目录-拼接-list文件里波形对应的文件名(不是全路径)。")
709
+ )
710
+ gr.Markdown(value=i18n("1Aa-文本内容"))
711
+ with gr.Row():
712
+ gpu_numbers1a = gr.Textbox(label=i18n("GPU卡号以-分割,每个卡号一个进程"),value="%s-%s"%(gpus,gpus),interactive=True)
713
+ bert_pretrained_dir = gr.Textbox(label=i18n("预训练的中文BERT模型路径"),value="GPT_SoVITS/pretrained_models/chinese-roberta-wwm-ext-large",interactive=False)
714
+ button1a_open = gr.Button(i18n("开启文本获取"), variant="primary",visible=True)
715
+ button1a_close = gr.Button(i18n("终止文本获取进程"), variant="primary",visible=False)
716
+ info1a=gr.Textbox(label=i18n("文本进程输出信息"))
717
+ gr.Markdown(value=i18n("1Ab-SSL自监督特征提取"))
718
+ with gr.Row():
719
+ gpu_numbers1Ba = gr.Textbox(label=i18n("GPU卡号以-分割,每个卡号一个进程"),value="%s-%s"%(gpus,gpus),interactive=True)
720
+ cnhubert_base_dir = gr.Textbox(label=i18n("预训练的SSL模型路径"),value="GPT_SoVITS/pretrained_models/chinese-hubert-base",interactive=False)
721
+ button1b_open = gr.Button(i18n("开启SSL提取"), variant="primary",visible=True)
722
+ button1b_close = gr.Button(i18n("终止SSL提取进程"), variant="primary",visible=False)
723
+ info1b=gr.Textbox(label=i18n("SSL进程输出信息"))
724
+ gr.Markdown(value=i18n("1Ac-语义token提取"))
725
+ with gr.Row():
726
+ gpu_numbers1c = gr.Textbox(label=i18n("GPU卡号以-分割,每个卡号一个进程"),value="%s-%s"%(gpus,gpus),interactive=True)
727
+ button1c_open = gr.Button(i18n("开启语义token提取"), variant="primary",visible=True)
728
+ button1c_close = gr.Button(i18n("终止语义token提取进程"), variant="primary",visible=False)
729
+ info1c=gr.Textbox(label=i18n("语义token提取进程输出信息"))
730
+ gr.Markdown(value=i18n("1Aabc-训练集格式化一键三连"))
731
+ with gr.Row():
732
+ button1abc_open = gr.Button(i18n("开启一键三连"), variant="primary",visible=True)
733
+ button1abc_close = gr.Button(i18n("终止一键三连"), variant="primary",visible=False)
734
+ info1abc=gr.Textbox(label=i18n("一键三连进程输出信息"))
735
+ button1a_open.click(open1a, [inp_text,inp_wav_dir,exp_name,gpu_numbers1a,bert_pretrained_dir], [info1a,button1a_open,button1a_close])
736
+ button1a_close.click(close1a, [], [info1a,button1a_open,button1a_close])
737
+ button1b_open.click(open1b, [inp_text,inp_wav_dir,exp_name,gpu_numbers1Ba,cnhubert_base_dir], [info1b,button1b_open,button1b_close])
738
+ button1b_close.click(close1b, [], [info1b,button1b_open,button1b_close])
739
+ button1c_open.click(open1c, [inp_text,exp_name,gpu_numbers1c,pretrained_s2G], [info1c,button1c_open,button1c_close])
740
+ button1c_close.click(close1c, [], [info1c,button1c_open,button1c_close])
741
+ button1abc_open.click(open1abc, [inp_text,inp_wav_dir,exp_name,gpu_numbers1a,gpu_numbers1Ba,gpu_numbers1c,bert_pretrained_dir,cnhubert_base_dir,pretrained_s2G], [info1abc,button1abc_open,button1abc_close])
742
+ button1abc_close.click(close1abc, [], [info1abc,button1abc_open,button1abc_close])
743
+ with gr.TabItem(i18n("1B-微调训练")):
744
+ gr.Markdown(value=i18n("1Ba-SoVITS训练。用于分享的模型文件输出在SoVITS_weights下。"))
745
+ with gr.Row():
746
+ batch_size = gr.Slider(minimum=1,maximum=40,step=1,label=i18n("每张显卡的batch_size"),value=default_batch_size,interactive=True)
747
+ total_epoch = gr.Slider(minimum=1,maximum=25,step=1,label=i18n("总训练轮数total_epoch,不建议太高"),value=8,interactive=True)
748
+ text_low_lr_rate = gr.Slider(minimum=0.2,maximum=0.6,step=0.05,label=i18n("文本模块学习率权重"),value=0.4,interactive=True)
749
+ save_every_epoch = gr.Slider(minimum=1,maximum=25,step=1,label=i18n("保存频率save_every_epoch"),value=4,interactive=True)
750
+ if_save_latest = gr.Checkbox(label=i18n("是否仅保存最新的ckpt文件以节省硬盘空间"), value=True, interactive=True, show_label=True)
751
+ if_save_every_weights = gr.Checkbox(label=i18n("是否在每次保存时间点将最终小模型保存至weights文件夹"), value=True, interactive=True, show_label=True)
752
+ gpu_numbers1Ba = gr.Textbox(label=i18n("GPU卡号以-分割,每个卡号一个进程"), value="%s" % (gpus), interactive=True)
753
+ with gr.Row():
754
+ button1Ba_open = gr.Button(i18n("开启SoVITS训练"), variant="primary",visible=True)
755
+ button1Ba_close = gr.Button(i18n("终止SoVITS训练"), variant="primary",visible=False)
756
+ info1Ba=gr.Textbox(label=i18n("SoVITS训练进程输出信息"))
757
+ gr.Markdown(value=i18n("1Bb-GPT训练。用于分享的模型文件输出在GPT_weights下。"))
758
+ with gr.Row():
759
+ batch_size1Bb = gr.Slider(minimum=1,maximum=40,step=1,label=i18n("每张显卡的batch_size"),value=default_batch_size,interactive=True)
760
+ total_epoch1Bb = gr.Slider(minimum=2,maximum=50,step=1,label=i18n("总训练轮数total_epoch"),value=15,interactive=True)
761
+ if_save_latest1Bb = gr.Checkbox(label=i18n("是否仅保存最新的ckpt文件以节省硬盘空间"), value=True, interactive=True, show_label=True)
762
+ if_save_every_weights1Bb = gr.Checkbox(label=i18n("是否在每次保存时间点将最终小模型保存至weights文件夹"), value=True, interactive=True, show_label=True)
763
+ save_every_epoch1Bb = gr.Slider(minimum=1,maximum=50,step=1,label=i18n("保存频率save_every_epoch"),value=5,interactive=True)
764
+ gpu_numbers1Bb = gr.Textbox(label=i18n("GPU卡号以-分割,每个卡号一个进程"), value="%s" % (gpus), interactive=True)
765
+ with gr.Row():
766
+ button1Bb_open = gr.Button(i18n("开启GPT训练"), variant="primary",visible=True)
767
+ button1Bb_close = gr.Button(i18n("终止GPT训练"), variant="primary",visible=False)
768
+ info1Bb=gr.Textbox(label=i18n("GPT训练进程输出信息"))
769
+ button1Ba_open.click(open1Ba, [batch_size,total_epoch,exp_name,text_low_lr_rate,if_save_latest,if_save_every_weights,save_every_epoch,gpu_numbers1Ba,pretrained_s2G,pretrained_s2D], [info1Ba,button1Ba_open,button1Ba_close])
770
+ button1Ba_close.click(close1Ba, [], [info1Ba,button1Ba_open,button1Ba_close])
771
+ button1Bb_open.click(open1Bb, [batch_size1Bb,total_epoch1Bb,exp_name,if_save_latest1Bb,if_save_every_weights1Bb,save_every_epoch1Bb,gpu_numbers1Bb,pretrained_s1], [info1Bb,button1Bb_open,button1Bb_close])
772
+ button1Bb_close.click(close1Bb, [], [info1Bb,button1Bb_open,button1Bb_close])
773
+ with gr.TabItem(i18n("1C-推理")):
774
+ gr.Markdown(value=i18n("选择训练完存放在SoVITS_weights和GPT_weights下的模型。默认的一个是底模,体验5秒Zero Shot TTS用。"))
775
+ with gr.Row():
776
+ GPT_dropdown = gr.Dropdown(label=i18n("*GPT模型列表"), choices=sorted(GPT_names,key=custom_sort_key),value=pretrained_gpt_name,interactive=True)
777
+ SoVITS_dropdown = gr.Dropdown(label=i18n("*SoVITS模型列表"), choices=sorted(SoVITS_names,key=custom_sort_key),value=pretrained_sovits_name,interactive=True)
778
+ gpu_number_1C=gr.Textbox(label=i18n("GPU卡号,只能填1个整数"), value=gpus, interactive=True)
779
+ refresh_button = gr.Button(i18n("刷新模型路径"), variant="primary")
780
+ refresh_button.click(fn=change_choices,inputs=[],outputs=[SoVITS_dropdown,GPT_dropdown])
781
+ with gr.Row():
782
+ if_tts = gr.Checkbox(label=i18n("是否开启TTS推理WebUI"), show_label=True)
783
+ tts_info = gr.Textbox(label=i18n("TTS推理WebUI进程输出信息"))
784
+ if_tts.change(change_tts_inference, [if_tts,bert_pretrained_dir,cnhubert_base_dir,gpu_number_1C,GPT_dropdown,SoVITS_dropdown], [tts_info])
785
+ with gr.TabItem(i18n("2-GPT-SoVITS-变声")):gr.Markdown(value=i18n("施工中,请静候佳音"))
786
+ app.queue(concurrency_count=511, max_size=1022).launch(
787
+ server_name="0.0.0.0",
788
+ inbrowser=True,
789
+ share=is_share,
790
+ server_port=webui_port_main,
791
+ quiet=True,
792
+ )