kevinwang676 commited on
Commit
546a15c
·
verified ·
1 Parent(s): 2c3577a

Delete .ipynb_checkpoints

Browse files
Files changed (1) hide show
  1. .ipynb_checkpoints/webui-checkpoint.py +0 -1080
.ipynb_checkpoints/webui-checkpoint.py DELETED
@@ -1,1080 +0,0 @@
1
- import os,sys
2
- if len(sys.argv)==1:sys.argv.append('v2')
3
- version="v1"if sys.argv[1]=="v1" else"v2"
4
- os.environ["version"]=version
5
- now_dir = os.getcwd()
6
- sys.path.insert(0, now_dir)
7
- import warnings
8
- warnings.filterwarnings("ignore")
9
- import json,yaml,torch,pdb,re,shutil
10
- import platform
11
- import psutil
12
- import signal
13
- os.environ['TORCH_DISTRIBUTED_DEBUG'] = 'INFO'
14
- torch.manual_seed(233333)
15
- tmp = os.path.join(now_dir, "TEMP")
16
- os.makedirs(tmp, exist_ok=True)
17
- os.environ["TEMP"] = tmp
18
- if(os.path.exists(tmp)):
19
- for name in os.listdir(tmp):
20
- if(name=="jieba.cache"):continue
21
- path="%s/%s"%(tmp,name)
22
- delete=os.remove if os.path.isfile(path) else shutil.rmtree
23
- try:
24
- delete(path)
25
- except Exception as e:
26
- print(str(e))
27
- pass
28
- import site
29
- import traceback
30
- site_packages_roots = []
31
- for path in site.getsitepackages():
32
- if "packages" in path:
33
- site_packages_roots.append(path)
34
- if(site_packages_roots==[]):site_packages_roots=["%s/runtime/Lib/site-packages" % now_dir]
35
- #os.environ["OPENBLAS_NUM_THREADS"] = "4"
36
- os.environ["no_proxy"] = "localhost, 127.0.0.1, ::1"
37
- os.environ["all_proxy"] = ""
38
- for site_packages_root in site_packages_roots:
39
- if os.path.exists(site_packages_root):
40
- try:
41
- with open("%s/users.pth" % (site_packages_root), "w") as f:
42
- f.write(
43
- # "%s\n%s/runtime\n%s/tools\n%s/tools/asr\n%s/GPT_SoVITS\n%s/tools/uvr5"
44
- "%s\n%s/GPT_SoVITS/BigVGAN\n%s/tools\n%s/tools/asr\n%s/GPT_SoVITS\n%s/tools/uvr5"
45
- % (now_dir, now_dir, now_dir, now_dir, now_dir, now_dir)
46
- )
47
- break
48
- except PermissionError as e:
49
- traceback.print_exc()
50
- from tools import my_utils
51
- import shutil
52
- import pdb
53
- from subprocess import Popen
54
- import signal
55
- 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
56
- from tools.i18n.i18n import I18nAuto, scan_language_list
57
- language=sys.argv[-1] if sys.argv[-1] in scan_language_list() else "Auto"
58
- os.environ["language"]=language
59
- i18n = I18nAuto(language=language)
60
- from scipy.io import wavfile
61
- from tools.my_utils import load_audio, check_for_existance, check_details
62
- from multiprocessing import cpu_count
63
- # os.environ['PYTORCH_ENABLE_MPS_FALLBACK'] = '1' # 当遇到mps不支持的步骤时使用cpu
64
- try:
65
- import gradio.analytics as analytics
66
- analytics.version_check = lambda:None
67
- except:...
68
- import gradio as gr
69
- n_cpu=cpu_count()
70
-
71
- ngpu = torch.cuda.device_count()
72
- gpu_infos = []
73
- mem = []
74
- if_gpu_ok = False
75
-
76
- # 判断是否有能用来训练和加速推理的N卡
77
- ok_gpu_keywords={"10","16","20","30","40","A2","A3","A4","P4","A50","500","A60","70","80","90","M4","T4","TITAN","L4","4060","H","600","506","507","508","509"}
78
- set_gpu_numbers=set()
79
- if torch.cuda.is_available() or ngpu != 0:
80
- for i in range(ngpu):
81
- gpu_name = torch.cuda.get_device_name(i)
82
- if any(value in gpu_name.upper()for value in ok_gpu_keywords):
83
- # A10#A100#V100#A40#P40#M40#K80#A4500
84
- if_gpu_ok = True # 至少有一张能用的N卡
85
- gpu_infos.append("%s\t%s" % (i, gpu_name))
86
- set_gpu_numbers.add(i)
87
- mem.append(int(torch.cuda.get_device_properties(i).total_memory/ 1024/ 1024/ 1024+ 0.4))
88
- # # 判断是否支持mps加速
89
- # if torch.backends.mps.is_available():
90
- # if_gpu_ok = True
91
- # gpu_infos.append("%s\t%s" % ("0", "Apple GPU"))
92
- # mem.append(psutil.virtual_memory().total/ 1024 / 1024 / 1024) # 实测使用系统内存作为显存不会爆显存
93
-
94
-
95
- def set_default():
96
- global default_batch_size,default_max_batch_size,gpu_info,default_sovits_epoch,default_sovits_save_every_epoch,max_sovits_epoch,max_sovits_save_every_epoch,default_batch_size_s1
97
- if if_gpu_ok and len(gpu_infos) > 0:
98
- gpu_info = "\n".join(gpu_infos)
99
- minmem = min(mem)
100
- default_batch_size = minmem // 2 if version!="v3"else minmem//14
101
- default_batch_size_s1=minmem // 2
102
- else:
103
- gpu_info = ("%s\t%s" % ("0", "CPU"))
104
- gpu_infos.append("%s\t%s" % ("0", "CPU"))
105
- set_gpu_numbers.add(0)
106
- default_batch_size = default_batch_size_s1=int(psutil.virtual_memory().total/ 1024 / 1024 / 1024 / 2)
107
- if version!="v3":
108
- default_sovits_epoch=8
109
- default_sovits_save_every_epoch=4
110
- max_sovits_epoch=25
111
- max_sovits_save_every_epoch=25
112
- else:
113
- default_sovits_epoch=2
114
- default_sovits_save_every_epoch=1
115
- max_sovits_epoch=3
116
- max_sovits_save_every_epoch=3
117
- default_max_batch_size=default_batch_size*3
118
-
119
- set_default()
120
-
121
- gpus = "-".join([i[0] for i in gpu_infos])
122
- default_gpu_numbers=str(sorted(list(set_gpu_numbers))[0])
123
- def fix_gpu_number(input):#将越界的number强制改到界内
124
- try:
125
- if(int(input)not in set_gpu_numbers):return default_gpu_numbers
126
- except:return input
127
- return input
128
- def fix_gpu_numbers(inputs):
129
- output=[]
130
- try:
131
- for input in inputs.split(","):output.append(str(fix_gpu_number(input)))
132
- return ",".join(output)
133
- except:
134
- return inputs
135
-
136
- pretrained_sovits_name=["GPT_SoVITS/pretrained_models/s2G488k.pth", "GPT_SoVITS/pretrained_models/gsv-v2final-pretrained/s2G2333k.pth","GPT_SoVITS/pretrained_models/s2Gv3.pth"]
137
- pretrained_gpt_name=["GPT_SoVITS/pretrained_models/s1bert25hz-2kh-longer-epoch=68e-step=50232.ckpt","GPT_SoVITS/pretrained_models/gsv-v2final-pretrained/s1bert25hz-5kh-longer-epoch=12-step=369668.ckpt", "GPT_SoVITS/pretrained_models/s1v3.ckpt"]
138
-
139
- pretrained_model_list = (pretrained_sovits_name[int(version[-1])-1],pretrained_sovits_name[int(version[-1])-1].replace("s2G","s2D"),pretrained_gpt_name[int(version[-1])-1],"GPT_SoVITS/pretrained_models/chinese-roberta-wwm-ext-large","GPT_SoVITS/pretrained_models/chinese-hubert-base")
140
-
141
- _=''
142
- for i in pretrained_model_list:
143
- if "s2Dv3"not in i and os.path.exists(i)==False:_+=f'\n {i}'
144
- if _:
145
- print("warning:",i18n('以下模型不存在:')+_)
146
-
147
- _ =[[],[]]
148
- for i in range(3):
149
- if os.path.exists(pretrained_gpt_name[i]):_[0].append(pretrained_gpt_name[i])
150
- else:_[0].append("")##没有下pretrained模型的,说不定他们是想自己从零训底模呢
151
- if os.path.exists(pretrained_sovits_name[i]):_[-1].append(pretrained_sovits_name[i])
152
- else:_[-1].append("")
153
- pretrained_gpt_name,pretrained_sovits_name = _
154
-
155
- SoVITS_weight_root=["SoVITS_weights","SoVITS_weights_v2","SoVITS_weights_v3"]
156
- GPT_weight_root=["GPT_weights","GPT_weights_v2","GPT_weights_v3"]
157
- for root in SoVITS_weight_root+GPT_weight_root:
158
- os.makedirs(root,exist_ok=True)
159
- def get_weights_names():
160
- SoVITS_names = [name for name in pretrained_sovits_name if name!=""]
161
- for path in SoVITS_weight_root:
162
- for name in os.listdir(path):
163
- if name.endswith(".pth"): SoVITS_names.append("%s/%s" % (path, name))
164
- GPT_names = [name for name in pretrained_gpt_name if name!=""]
165
- for path in GPT_weight_root:
166
- for name in os.listdir(path):
167
- if name.endswith(".ckpt"): GPT_names.append("%s/%s" % (path, name))
168
- return SoVITS_names, GPT_names
169
-
170
- SoVITS_names,GPT_names = get_weights_names()
171
- for path in SoVITS_weight_root+GPT_weight_root:
172
- os.makedirs(path,exist_ok=True)
173
-
174
-
175
- def custom_sort_key(s):
176
- # 使用正则表达式提取字符串中的数字部分和非数字部分
177
- parts = re.split('(\d+)', s)
178
- # 将数字部分转换为整数,非数字部分保持不变
179
- parts = [int(part) if part.isdigit() else part for part in parts]
180
- return parts
181
-
182
- def change_choices():
183
- SoVITS_names, GPT_names = get_weights_names()
184
- return {"choices": sorted(SoVITS_names,key=custom_sort_key), "__type__": "update"}, {"choices": sorted(GPT_names,key=custom_sort_key), "__type__": "update"}
185
-
186
- p_label=None
187
- p_uvr5=None
188
- p_asr=None
189
- p_denoise=None
190
- p_tts_inference=None
191
-
192
- def kill_proc_tree(pid, including_parent=True):
193
- try:
194
- parent = psutil.Process(pid)
195
- except psutil.NoSuchProcess:
196
- # Process already terminated
197
- return
198
-
199
- children = parent.children(recursive=True)
200
- for child in children:
201
- try:
202
- os.kill(child.pid, signal.SIGTERM) # or signal.SIGKILL
203
- except OSError:
204
- pass
205
- if including_parent:
206
- try:
207
- os.kill(parent.pid, signal.SIGTERM) # or signal.SIGKILL
208
- except OSError:
209
- pass
210
-
211
- system=platform.system()
212
- def kill_process(pid):
213
- if(system=="Windows"):
214
- cmd = "taskkill /t /f /pid %s" % pid
215
- os.system(cmd)
216
- else:
217
- kill_proc_tree(pid)
218
-
219
-
220
- def change_label(path_list):
221
- global p_label
222
- if(p_label==None):
223
- check_for_existance([path_list])
224
- path_list=my_utils.clean_path(path_list)
225
- cmd = '"%s" tools/subfix_webui.py --load_list "%s" --webui_port %s --is_share %s'%(python_exec,path_list,webui_port_subfix,is_share)
226
- yield i18n("打标工具WebUI已开启"), {'__type__':'update','visible':False}, {'__type__':'update','visible':True}
227
- print(cmd)
228
- p_label = Popen(cmd, shell=True)
229
- elif(p_label!=None):
230
- kill_process(p_label.pid)
231
- p_label=None
232
- yield i18n("打标工具WebUI已关闭"), {'__type__':'update','visible':True}, {'__type__':'update','visible':False}
233
-
234
- def change_uvr5():
235
- global p_uvr5
236
- if(p_uvr5==None):
237
- cmd = '"%s" tools/uvr5/webui.py "%s" %s %s %s'%(python_exec,infer_device,is_half,webui_port_uvr5,is_share)
238
- yield i18n("UVR5已开启"), {'__type__':'update','visible':False}, {'__type__':'update','visible':True}
239
- print(cmd)
240
- p_uvr5 = Popen(cmd, shell=True)
241
- elif(p_uvr5!=None):
242
- kill_process(p_uvr5.pid)
243
- p_uvr5=None
244
- yield i18n("UVR5���关闭"), {'__type__':'update','visible':True}, {'__type__':'update','visible':False}
245
-
246
- def change_tts_inference(bert_path,cnhubert_base_path,gpu_number,gpt_path,sovits_path, batched_infer_enabled):
247
- global p_tts_inference
248
- if batched_infer_enabled:
249
- cmd = '"%s" GPT_SoVITS/inference_webui_fast.py "%s"'%(python_exec, language)
250
- else:
251
- cmd = '"%s" GPT_SoVITS/inference_webui.py "%s"'%(python_exec, language)
252
- #####v3暂不支持加速推理
253
- if version=="v3":
254
- cmd = '"%s" GPT_SoVITS/inference_webui.py "%s"'%(python_exec, language)
255
- if(p_tts_inference==None):
256
- os.environ["gpt_path"]=gpt_path if "/" in gpt_path else "%s/%s"%(GPT_weight_root,gpt_path)
257
- os.environ["sovits_path"]=sovits_path if "/"in sovits_path else "%s/%s"%(SoVITS_weight_root,sovits_path)
258
- os.environ["cnhubert_base_path"]=cnhubert_base_path
259
- os.environ["bert_path"]=bert_path
260
- os.environ["_CUDA_VISIBLE_DEVICES"]=fix_gpu_number(gpu_number)
261
- os.environ["is_half"]=str(is_half)
262
- os.environ["infer_ttswebui"]=str(webui_port_infer_tts)
263
- os.environ["is_share"]=str(is_share)
264
- yield i18n("TTS推理进程已开启"), {'__type__':'update','visible':False}, {'__type__':'update','visible':True}
265
- print(cmd)
266
- p_tts_inference = Popen(cmd, shell=True)
267
- elif(p_tts_inference!=None):
268
- kill_process(p_tts_inference.pid)
269
- p_tts_inference=None
270
- yield i18n("TTS推理进程已关闭"), {'__type__':'update','visible':True}, {'__type__':'update','visible':False}
271
-
272
- from tools.asr.config import asr_dict
273
- def open_asr(asr_inp_dir, asr_opt_dir, asr_model, asr_model_size, asr_lang, asr_precision):
274
- global p_asr
275
- if(p_asr==None):
276
- asr_inp_dir=my_utils.clean_path(asr_inp_dir)
277
- asr_opt_dir=my_utils.clean_path(asr_opt_dir)
278
- check_for_existance([asr_inp_dir])
279
- cmd = f'"{python_exec}" tools/asr/{asr_dict[asr_model]["path"]}'
280
- cmd += f' -i "{asr_inp_dir}"'
281
- cmd += f' -o "{asr_opt_dir}"'
282
- cmd += f' -s {asr_model_size}'
283
- cmd += f' -l {asr_lang}'
284
- cmd += f" -p {asr_precision}"
285
- output_file_name = os.path.basename(asr_inp_dir)
286
- output_folder = asr_opt_dir or "output/asr_opt"
287
- output_file_path = os.path.abspath(f'{output_folder}/{output_file_name}.list')
288
- yield "ASR任务开启:%s"%cmd, {"__type__":"update","visible":False}, {"__type__":"update","visible":True}, {"__type__":"update"}, {"__type__":"update"}, {"__type__":"update"}
289
- print(cmd)
290
- p_asr = Popen(cmd, shell=True)
291
- p_asr.wait()
292
- p_asr=None
293
- yield f"ASR任务完成, 查看终端进行下一步", {"__type__":"update","visible":True}, {"__type__":"update","visible":False}, {"__type__":"update","value":output_file_path}, {"__type__":"update","value":output_file_path}, {"__type__":"update","value":asr_inp_dir}
294
- else:
295
- yield "已有正在进行的ASR任务,需先终止才能开启下一次任务", {"__type__":"update","visible":False}, {"__type__":"update","visible":True}, {"__type__":"update"}, {"__type__":"update"}, {"__type__":"update"}
296
- # return None
297
-
298
- def close_asr():
299
- global p_asr
300
- if(p_asr!=None):
301
- kill_process(p_asr.pid)
302
- p_asr=None
303
- return "已终止ASR进程", {"__type__":"update","visible":True}, {"__type__":"update","visible":False}
304
- def open_denoise(denoise_inp_dir, denoise_opt_dir):
305
- global p_denoise
306
- if(p_denoise==None):
307
- denoise_inp_dir=my_utils.clean_path(denoise_inp_dir)
308
- denoise_opt_dir=my_utils.clean_path(denoise_opt_dir)
309
- check_for_existance([denoise_inp_dir])
310
- cmd = '"%s" tools/cmd-denoise.py -i "%s" -o "%s" -p %s'%(python_exec,denoise_inp_dir,denoise_opt_dir,"float16"if is_half==True else "float32")
311
-
312
- yield "语音降噪任务开启:%s"%cmd, {"__type__":"update","visible":False}, {"__type__":"update","visible":True}, {"__type__":"update"}, {"__type__":"update"}
313
- print(cmd)
314
- p_denoise = Popen(cmd, shell=True)
315
- p_denoise.wait()
316
- p_denoise=None
317
- yield f"语音降噪任务完成, 查看终端进行下一步", {"__type__":"update","visible":True}, {"__type__":"update","visible":False}, {"__type__":"update","value":denoise_opt_dir}, {"__type__":"update","value":denoise_opt_dir}
318
- else:
319
- yield "已有正在进行的语音降噪任务,需先终止才能开启下一次任务", {"__type__":"update","visible":False}, {"__type__":"update","visible":True}, {"__type__":"update"}, {"__type__":"update"}
320
- # return None
321
-
322
- def close_denoise():
323
- global p_denoise
324
- if(p_denoise!=None):
325
- kill_process(p_denoise.pid)
326
- p_denoise=None
327
- return "已终止语音降噪进程", {"__type__":"update","visible":True}, {"__type__":"update","visible":False}
328
-
329
- p_train_SoVITS=None
330
- 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,if_grad_ckpt):
331
- global p_train_SoVITS
332
- if(p_train_SoVITS==None):
333
- with open("GPT_SoVITS/configs/s2.json")as f:
334
- data=f.read()
335
- data=json.loads(data)
336
- s2_dir="%s/%s"%(exp_root,exp_name)
337
- os.makedirs("%s/logs_s2_%s"%(s2_dir,version),exist_ok=True)
338
- if check_for_existance([s2_dir],is_train=True):
339
- check_details([s2_dir],is_train=True)
340
- if(is_half==False):
341
- data["train"]["fp16_run"]=False
342
- batch_size=max(1,batch_size//2)
343
- data["train"]["batch_size"]=batch_size
344
- data["train"]["epochs"]=total_epoch
345
- data["train"]["text_low_lr_rate"]=text_low_lr_rate
346
- data["train"]["pretrained_s2G"]=pretrained_s2G
347
- data["train"]["pretrained_s2D"]=pretrained_s2D
348
- data["train"]["if_save_latest"]=if_save_latest
349
- data["train"]["if_save_every_weights"]=if_save_every_weights
350
- data["train"]["save_every_epoch"]=save_every_epoch
351
- data["train"]["gpu_numbers"]=gpu_numbers1Ba
352
- data["train"]["grad_ckpt"]=if_grad_ckpt
353
- data["model"]["version"]=version
354
- data["data"]["exp_dir"]=data["s2_ckpt_dir"]=s2_dir
355
- data["save_weight_dir"]=SoVITS_weight_root[int(version[-1])-1]
356
- data["name"]=exp_name
357
- data["version"]=version
358
- tmp_config_path="%s/tmp_s2.json"%tmp
359
- with open(tmp_config_path,"w")as f:f.write(json.dumps(data))
360
- if version in ["v1","v2"]:
361
- cmd = '"%s" GPT_SoVITS/s2_train.py --config "%s"'%(python_exec,tmp_config_path)
362
- else:
363
- cmd = '"%s" GPT_SoVITS/s2_train_v3.py --config "%s"'%(python_exec,tmp_config_path)
364
- yield "SoVITS训练开始:%s"%cmd, {"__type__":"update","visible":False}, {"__type__":"update","visible":True}
365
- print(cmd)
366
- p_train_SoVITS = Popen(cmd, shell=True)
367
- p_train_SoVITS.wait()
368
- p_train_SoVITS=None
369
- yield "SoVITS训练完成", {"__type__":"update","visible":True}, {"__type__":"update","visible":False}
370
- else:
371
- yield "已有正在进行的SoVITS训练任务,需先终止才能开启下一次任务", {"__type__":"update","visible":False}, {"__type__":"update","visible":True}
372
-
373
- def close1Ba():
374
- global p_train_SoVITS
375
- if(p_train_SoVITS!=None):
376
- kill_process(p_train_SoVITS.pid)
377
- p_train_SoVITS=None
378
- return "已终止SoVITS训练", {"__type__":"update","visible":True}, {"__type__":"update","visible":False}
379
-
380
- p_train_GPT=None
381
- def open1Bb(batch_size,total_epoch,exp_name,if_dpo,if_save_latest,if_save_every_weights,save_every_epoch,gpu_numbers,pretrained_s1):
382
- global p_train_GPT
383
- if(p_train_GPT==None):
384
- with open("GPT_SoVITS/configs/s1longer.yaml"if version=="v1"else "GPT_SoVITS/configs/s1longer-v2.yaml")as f:
385
- data=f.read()
386
- data=yaml.load(data, Loader=yaml.FullLoader)
387
- s1_dir="%s/%s"%(exp_root,exp_name)
388
- os.makedirs("%s/logs_s1"%(s1_dir),exist_ok=True)
389
- if check_for_existance([s1_dir],is_train=True):
390
- check_details([s1_dir],is_train=True)
391
- if(is_half==False):
392
- data["train"]["precision"]="32"
393
- batch_size = max(1, batch_size // 2)
394
- data["train"]["batch_size"]=batch_size
395
- data["train"]["epochs"]=total_epoch
396
- data["pretrained_s1"]=pretrained_s1
397
- data["train"]["save_every_n_epoch"]=save_every_epoch
398
- data["train"]["if_save_every_weights"]=if_save_every_weights
399
- data["train"]["if_save_latest"]=if_save_latest
400
- data["train"]["if_dpo"]=if_dpo
401
- data["train"]["half_weights_save_dir"]=GPT_weight_root[int(version[-1])-1]
402
- data["train"]["exp_name"]=exp_name
403
- data["train_semantic_path"]="%s/6-name2semantic.tsv"%s1_dir
404
- data["train_phoneme_path"]="%s/2-name2text.txt"%s1_dir
405
- data["output_dir"]="%s/logs_s1_%s"%(s1_dir,version)
406
- # data["version"]=version
407
-
408
- os.environ["_CUDA_VISIBLE_DEVICES"]=fix_gpu_numbers(gpu_numbers.replace("-",","))
409
- os.environ["hz"]="25hz"
410
- tmp_config_path="%s/tmp_s1.yaml"%tmp
411
- with open(tmp_config_path, "w") as f:f.write(yaml.dump(data, default_flow_style=False))
412
- # 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)
413
- cmd = '"%s" GPT_SoVITS/s1_train.py --config_file "%s" '%(python_exec,tmp_config_path)
414
- yield "GPT训练开始:%s"%cmd, {"__type__":"update","visible":False}, {"__type__":"update","visible":True}
415
- print(cmd)
416
- p_train_GPT = Popen(cmd, shell=True)
417
- p_train_GPT.wait()
418
- p_train_GPT=None
419
- yield "GPT训练完成", {"__type__":"update","visible":True}, {"__type__":"update","visible":False}
420
- else:
421
- yield "已有正在进行的GPT训练任务,需先终止才能开启下一次任务", {"__type__":"update","visible":False}, {"__type__":"update","visible":True}
422
-
423
- def close1Bb():
424
- global p_train_GPT
425
- if(p_train_GPT!=None):
426
- kill_process(p_train_GPT.pid)
427
- p_train_GPT=None
428
- return "已终止GPT训练", {"__type__":"update","visible":True}, {"__type__":"update","visible":False}
429
-
430
- ps_slice=[]
431
- def open_slice(inp,opt_root,threshold,min_length,min_interval,hop_size,max_sil_kept,_max,alpha,n_parts):
432
- global ps_slice
433
- inp = my_utils.clean_path(inp)
434
- opt_root = my_utils.clean_path(opt_root)
435
- check_for_existance([inp])
436
- if(os.path.exists(inp)==False):
437
- yield "输入路径不存在", {"__type__":"update","visible":True}, {"__type__":"update","visible":False}, {"__type__": "update"}, {"__type__": "update"}, {"__type__": "update"}
438
- return
439
- if os.path.isfile(inp):n_parts=1
440
- elif os.path.isdir(inp):pass
441
- else:
442
- yield "输入路径存在但既不是文件也不是文件夹", {"__type__":"update","visible":True}, {"__type__":"update","visible":False}, {"__type__": "update"}, {"__type__": "update"}, {"__type__": "update"}
443
- return
444
- if (ps_slice == []):
445
- for i_part in range(n_parts):
446
- 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)
447
- print(cmd)
448
- p = Popen(cmd, shell=True)
449
- ps_slice.append(p)
450
- yield "切割执行中", {"__type__": "update", "visible": False}, {"__type__": "update", "visible": True}, {"__type__": "update"}, {"__type__": "update"}, {"__type__": "update"}
451
- for p in ps_slice:
452
- p.wait()
453
- ps_slice=[]
454
- yield "切割结束", {"__type__":"update","visible":True}, {"__type__":"update","visible":False}, {"__type__": "update", "value":opt_root}, {"__type__": "update", "value":opt_root}, {"__type__": "update", "value":opt_root}
455
- else:
456
- yield "已有正在进行的切割任务,需先终止才能开启下一次任务", {"__type__": "update", "visible": False}, {"__type__": "update", "visible": True}, {"__type__": "update"}, {"__type__": "update"}, {"__type__": "update"}
457
-
458
- def close_slice():
459
- global ps_slice
460
- if (ps_slice != []):
461
- for p_slice in ps_slice:
462
- try:
463
- kill_process(p_slice.pid)
464
- except:
465
- traceback.print_exc()
466
- ps_slice=[]
467
- return "已终止所有切割进程", {"__type__": "update", "visible": True}, {"__type__": "update", "visible": False}
468
-
469
- ps1a=[]
470
- def open1a(inp_text,inp_wav_dir,exp_name,gpu_numbers,bert_pretrained_dir):
471
- global ps1a
472
- inp_text = my_utils.clean_path(inp_text)
473
- inp_wav_dir = my_utils.clean_path(inp_wav_dir)
474
- if check_for_existance([inp_text,inp_wav_dir], is_dataset_processing=True):
475
- check_details([inp_text,inp_wav_dir], is_dataset_processing=True)
476
- if (ps1a == []):
477
- opt_dir="%s/%s"%(exp_root,exp_name)
478
- config={
479
- "inp_text":inp_text,
480
- "inp_wav_dir":inp_wav_dir,
481
- "exp_name":exp_name,
482
- "opt_dir":opt_dir,
483
- "bert_pretrained_dir":bert_pretrained_dir,
484
- }
485
- gpu_names=gpu_numbers.split("-")
486
- all_parts=len(gpu_names)
487
- for i_part in range(all_parts):
488
- config.update(
489
- {
490
- "i_part": str(i_part),
491
- "all_parts": str(all_parts),
492
- "_CUDA_VISIBLE_DEVICES": fix_gpu_number(gpu_names[i_part]),
493
- "is_half": str(is_half)
494
- }
495
- )
496
- os.environ.update(config)
497
- cmd = '"%s" GPT_SoVITS/prepare_datasets/1-get-text.py'%python_exec
498
- print(cmd)
499
- p = Popen(cmd, shell=True)
500
- ps1a.append(p)
501
- yield "文本进程执行中", {"__type__": "update", "visible": False}, {"__type__": "update", "visible": True}
502
- for p in ps1a:
503
- p.wait()
504
- opt = []
505
- for i_part in range(all_parts):
506
- txt_path = "%s/2-name2text-%s.txt" % (opt_dir, i_part)
507
- with open(txt_path, "r", encoding="utf8") as f:
508
- opt += f.read().strip("\n").split("\n")
509
- os.remove(txt_path)
510
- path_text = "%s/2-name2text.txt" % opt_dir
511
- with open(path_text, "w", encoding="utf8") as f:
512
- f.write("\n".join(opt) + "\n")
513
- ps1a=[]
514
- if len("".join(opt)) > 0:
515
- yield "文本进程成功", {"__type__": "update", "visible": True}, {"__type__": "update", "visible": False}
516
- else:
517
- yield "文本进程失败", {"__type__": "update", "visible": True}, {"__type__": "update", "visible": False}
518
- else:
519
- yield "已有正在进行的文本任务,需先终止才能开启下一次任务", {"__type__": "update", "visible": False}, {"__type__": "update", "visible": True}
520
-
521
- def close1a():
522
- global ps1a
523
- if (ps1a != []):
524
- for p1a in ps1a:
525
- try:
526
- kill_process(p1a.pid)
527
- except:
528
- traceback.print_exc()
529
- ps1a=[]
530
- return "已终止所有1a进程", {"__type__": "update", "visible": True}, {"__type__": "update", "visible": False}
531
-
532
- ps1b=[]
533
- def open1b(inp_text,inp_wav_dir,exp_name,gpu_numbers,ssl_pretrained_dir):
534
- global ps1b
535
- inp_text = my_utils.clean_path(inp_text)
536
- inp_wav_dir = my_utils.clean_path(inp_wav_dir)
537
- if check_for_existance([inp_text,inp_wav_dir], is_dataset_processing=True):
538
- check_details([inp_text,inp_wav_dir], is_dataset_processing=True)
539
- if (ps1b == []):
540
- config={
541
- "inp_text":inp_text,
542
- "inp_wav_dir":inp_wav_dir,
543
- "exp_name":exp_name,
544
- "opt_dir":"%s/%s"%(exp_root,exp_name),
545
- "cnhubert_base_dir":ssl_pretrained_dir,
546
- "is_half": str(is_half)
547
- }
548
- gpu_names=gpu_numbers.split("-")
549
- all_parts=len(gpu_names)
550
- for i_part in range(all_parts):
551
- config.update(
552
- {
553
- "i_part": str(i_part),
554
- "all_parts": str(all_parts),
555
- "_CUDA_VISIBLE_DEVICES": fix_gpu_number(gpu_names[i_part]),
556
- }
557
- )
558
- os.environ.update(config)
559
- cmd = '"%s" GPT_SoVITS/prepare_datasets/2-get-hubert-wav32k.py'%python_exec
560
- print(cmd)
561
- p = Popen(cmd, shell=True)
562
- ps1b.append(p)
563
- yield "SSL提取进程执行中", {"__type__": "update", "visible": False}, {"__type__": "update", "visible": True}
564
- for p in ps1b:
565
- p.wait()
566
- ps1b=[]
567
- yield "SSL提取进程结束", {"__type__":"update","visible":True}, {"__type__":"update","visible":False}
568
- else:
569
- yield "已有正在进行的SSL提取任务,需先终止才能开启下一次任务", {"__type__": "update", "visible": False}, {"__type__": "update", "visible": True}
570
-
571
- def close1b():
572
- global ps1b
573
- if (ps1b != []):
574
- for p1b in ps1b:
575
- try:
576
- kill_process(p1b.pid)
577
- except:
578
- traceback.print_exc()
579
- ps1b=[]
580
- return "已终止所有1b进程", {"__type__": "update", "visible": True}, {"__type__": "update", "visible": False}
581
-
582
- ps1c=[]
583
- def open1c(inp_text,exp_name,gpu_numbers,pretrained_s2G_path):
584
- global ps1c
585
- inp_text = my_utils.clean_path(inp_text)
586
- if check_for_existance([inp_text,''], is_dataset_processing=True):
587
- check_details([inp_text,''], is_dataset_processing=True)
588
- if (ps1c == []):
589
- opt_dir="%s/%s"%(exp_root,exp_name)
590
- config={
591
- "inp_text":inp_text,
592
- "exp_name":exp_name,
593
- "opt_dir":opt_dir,
594
- "pretrained_s2G":pretrained_s2G_path,
595
- "s2config_path":"GPT_SoVITS/configs/s2.json",
596
- "is_half": str(is_half)
597
- }
598
- gpu_names=gpu_numbers.split("-")
599
- all_parts=len(gpu_names)
600
- for i_part in range(all_parts):
601
- config.update(
602
- {
603
- "i_part": str(i_part),
604
- "all_parts": str(all_parts),
605
- "_CUDA_VISIBLE_DEVICES": fix_gpu_number(gpu_names[i_part]),
606
- }
607
- )
608
- os.environ.update(config)
609
- cmd = '"%s" GPT_SoVITS/prepare_datasets/3-get-semantic.py'%python_exec
610
- print(cmd)
611
- p = Popen(cmd, shell=True)
612
- ps1c.append(p)
613
- yield "语义token提取进程执行中", {"__type__": "update", "visible": False}, {"__type__": "update", "visible": True}
614
- for p in ps1c:
615
- p.wait()
616
- opt = ["item_name\tsemantic_audio"]
617
- path_semantic = "%s/6-name2semantic.tsv" % opt_dir
618
- for i_part in range(all_parts):
619
- semantic_path = "%s/6-name2semantic-%s.tsv" % (opt_dir, i_part)
620
- with open(semantic_path, "r", encoding="utf8") as f:
621
- opt += f.read().strip("\n").split("\n")
622
- os.remove(semantic_path)
623
- with open(path_semantic, "w", encoding="utf8") as f:
624
- f.write("\n".join(opt) + "\n")
625
- ps1c=[]
626
- yield "语义token提取进程结束", {"__type__":"update","visible":True}, {"__type__":"update","visible":False}
627
- else:
628
- yield "已有正在进行的语义token提取任务,需先终止才能开启下一次任务", {"__type__": "update", "visible": False}, {"__type__": "update", "visible": True}
629
-
630
- def close1c():
631
- global ps1c
632
- if (ps1c != []):
633
- for p1c in ps1c:
634
- try:
635
- kill_process(p1c.pid)
636
- except:
637
- traceback.print_exc()
638
- ps1c=[]
639
- return "已终止所有语义token进程", {"__type__": "update", "visible": True}, {"__type__": "update", "visible": False}
640
- #####inp_text,inp_wav_dir,exp_name,gpu_numbers1a,gpu_numbers1Ba,gpu_numbers1c,bert_pretrained_dir,cnhubert_base_dir,pretrained_s2G
641
- ps1abc=[]
642
- def open1abc(inp_text,inp_wav_dir,exp_name,gpu_numbers1a,gpu_numbers1Ba,gpu_numbers1c,bert_pretrained_dir,ssl_pretrained_dir,pretrained_s2G_path):
643
- global ps1abc
644
- inp_text = my_utils.clean_path(inp_text)
645
- inp_wav_dir = my_utils.clean_path(inp_wav_dir)
646
- if check_for_existance([inp_text,inp_wav_dir], is_dataset_processing=True):
647
- check_details([inp_text,inp_wav_dir], is_dataset_processing=True)
648
- if (ps1abc == []):
649
- opt_dir="%s/%s"%(exp_root,exp_name)
650
- try:
651
- #############################1a
652
- path_text="%s/2-name2text.txt" % opt_dir
653
- 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)):
654
- config={
655
- "inp_text":inp_text,
656
- "inp_wav_dir":inp_wav_dir,
657
- "exp_name":exp_name,
658
- "opt_dir":opt_dir,
659
- "bert_pretrained_dir":bert_pretrained_dir,
660
- "is_half": str(is_half)
661
- }
662
- gpu_names=gpu_numbers1a.split("-")
663
- all_parts=len(gpu_names)
664
- for i_part in range(all_parts):
665
- config.update(
666
- {
667
- "i_part": str(i_part),
668
- "all_parts": str(all_parts),
669
- "_CUDA_VISIBLE_DEVICES": fix_gpu_number(gpu_names[i_part]),
670
- }
671
- )
672
- os.environ.update(config)
673
- cmd = '"%s" GPT_SoVITS/prepare_datasets/1-get-text.py'%python_exec
674
- print(cmd)
675
- p = Popen(cmd, shell=True)
676
- ps1abc.append(p)
677
- yield "进度:1a-ing", {"__type__": "update", "visible": False}, {"__type__": "update", "visible": True}
678
- for p in ps1abc:p.wait()
679
-
680
- opt = []
681
- for i_part in range(all_parts):#txt_path="%s/2-name2text-%s.txt"%(opt_dir,i_part)
682
- txt_path = "%s/2-name2text-%s.txt" % (opt_dir, i_part)
683
- with open(txt_path, "r",encoding="utf8") as f:
684
- opt += f.read().strip("\n").split("\n")
685
- os.remove(txt_path)
686
- with open(path_text, "w",encoding="utf8") as f:
687
- f.write("\n".join(opt) + "\n")
688
- assert len("".join(opt)) > 0, "1Aa-文本获取进程失败"
689
- yield "进度:1a-done", {"__type__": "update", "visible": False}, {"__type__": "update", "visible": True}
690
- ps1abc=[]
691
- #############################1b
692
- config={
693
- "inp_text":inp_text,
694
- "inp_wav_dir":inp_wav_dir,
695
- "exp_name":exp_name,
696
- "opt_dir":opt_dir,
697
- "cnhubert_base_dir":ssl_pretrained_dir,
698
- }
699
- gpu_names=gpu_numbers1Ba.split("-")
700
- all_parts=len(gpu_names)
701
- for i_part in range(all_parts):
702
- config.update(
703
- {
704
- "i_part": str(i_part),
705
- "all_parts": str(all_parts),
706
- "_CUDA_VISIBLE_DEVICES": fix_gpu_number(gpu_names[i_part]),
707
- }
708
- )
709
- os.environ.update(config)
710
- cmd = '"%s" GPT_SoVITS/prepare_datasets/2-get-hubert-wav32k.py'%python_exec
711
- print(cmd)
712
- p = Popen(cmd, shell=True)
713
- ps1abc.append(p)
714
- yield "进度:1a-done, 1b-ing", {"__type__": "update", "visible": False}, {"__type__": "update", "visible": True}
715
- for p in ps1abc:p.wait()
716
- yield "进度:1a1b-done", {"__type__": "update", "visible": False}, {"__type__": "update", "visible": True}
717
- ps1abc=[]
718
- #############################1c
719
- path_semantic = "%s/6-name2semantic.tsv" % opt_dir
720
- if(os.path.exists(path_semantic)==False or (os.path.exists(path_semantic)==True and os.path.getsize(path_semantic)<31)):
721
- config={
722
- "inp_text":inp_text,
723
- "exp_name":exp_name,
724
- "opt_dir":opt_dir,
725
- "pretrained_s2G":pretrained_s2G_path,
726
- "s2config_path":"GPT_SoVITS/configs/s2.json",
727
- }
728
- gpu_names=gpu_numbers1c.split("-")
729
- all_parts=len(gpu_names)
730
- for i_part in range(all_parts):
731
- config.update(
732
- {
733
- "i_part": str(i_part),
734
- "all_parts": str(all_parts),
735
- "_CUDA_VISIBLE_DEVICES": fix_gpu_number(gpu_names[i_part]),
736
- }
737
- )
738
- os.environ.update(config)
739
- cmd = '"%s" GPT_SoVITS/prepare_datasets/3-get-semantic.py'%python_exec
740
- print(cmd)
741
- p = Popen(cmd, shell=True)
742
- ps1abc.append(p)
743
- yield "进度:1a1b-done, 1cing", {"__type__": "update", "visible": False}, {"__type__": "update", "visible": True}
744
- for p in ps1abc:p.wait()
745
-
746
- opt = ["item_name\tsemantic_audio"]
747
- for i_part in range(all_parts):
748
- semantic_path = "%s/6-name2semantic-%s.tsv" % (opt_dir, i_part)
749
- with open(semantic_path, "r",encoding="utf8") as f:
750
- opt += f.read().strip("\n").split("\n")
751
- os.remove(semantic_path)
752
- with open(path_semantic, "w",encoding="utf8") as f:
753
- f.write("\n".join(opt) + "\n")
754
- yield "进度:all-done", {"__type__": "update", "visible": False}, {"__type__": "update", "visible": True}
755
- ps1abc = []
756
- yield "一键三连进程结束", {"__type__": "update", "visible": True}, {"__type__": "update", "visible": False}
757
- except:
758
- traceback.print_exc()
759
- close1abc()
760
- yield "一键三连中途报错", {"__type__": "update", "visible": True}, {"__type__": "update", "visible": False}
761
- else:
762
- yield "已有正在进行的一键三连任务,需先终止才能开启下一次任务", {"__type__": "update", "visible": False}, {"__type__": "update", "visible": True}
763
-
764
- def close1abc():
765
- global ps1abc
766
- if (ps1abc != []):
767
- for p1abc in ps1abc:
768
- try:
769
- kill_process(p1abc.pid)
770
- except:
771
- traceback.print_exc()
772
- ps1abc=[]
773
- return "已终止所有一键三连进程", {"__type__": "update", "visible": True}, {"__type__": "update", "visible": False}
774
-
775
- def switch_version(version_):
776
- os.environ["version"]=version_
777
- global version
778
- version = version_
779
- if pretrained_sovits_name[int(version[-1])-1] !='' and pretrained_gpt_name[int(version[-1])-1] !='':...
780
- else:
781
- gr.Warning(i18n(f'未下载{version.upper()}模型'))
782
- set_default()
783
- return {'__type__':'update', 'value':pretrained_sovits_name[int(version[-1])-1]}, {'__type__':'update', 'value':pretrained_sovits_name[int(version[-1])-1].replace("s2G","s2D")}, {'__type__':'update', 'value':pretrained_gpt_name[int(version[-1])-1]}, {'__type__':'update', 'value':pretrained_gpt_name[int(version[-1])-1]}, {'__type__':'update', 'value':pretrained_sovits_name[int(version[-1])-1]},{'__type__':'update',"value":default_batch_size,"maximum":default_max_batch_size},{'__type__':'update',"value":default_sovits_epoch,"maximum":max_sovits_epoch},{'__type__':'update',"value":default_sovits_save_every_epoch,"maximum":max_sovits_save_every_epoch},{'__type__':'update',"interactive":True if version!="v3"else False},{'__type__':'update',"interactive":True if version == "v3" else False},{'__type__':'update',"interactive":False if version == "v3" else True,"value":False}
784
-
785
- if os.path.exists('GPT_SoVITS/text/G2PWModel'):...
786
- else:
787
- cmd = '"%s" GPT_SoVITS/download.py'%python_exec
788
- p = Popen(cmd, shell=True)
789
- p.wait()
790
-
791
- def sync(text):
792
- return {'__type__':'update','value':text}
793
- with gr.Blocks(title="GPT-SoVITS WebUI") as app:
794
- gr.Markdown(
795
- value=
796
- i18n("本软件以MIT协议开源, 作者不对软件具备任何控制力, 使用软件者、传播软件导出的声音者自负全责. <br>如不认可该条款, 则不能使用或引用软件包内任何代码和文件. 详见根目录<b>LICENSE</b>.")
797
- )
798
- gr.Markdown(
799
- value=
800
- i18n("中文教程文档:https://www.yuque.com/baicaigongchang1145haoyuangong/ib3g1e")
801
- )
802
-
803
- with gr.Tabs():
804
- with gr.TabItem(i18n("0-前置数据集获取工具")):#提前随机切片防止uvr5爆内存->uvr5->slicer->asr->打标
805
- gr.Markdown(value=i18n("0a-UVR5人声伴奏分离&去混响去延迟工具"))
806
- with gr.Row():
807
- with gr.Column(scale=3):
808
- with gr.Row():
809
- uvr5_info = gr.Textbox(label=i18n("UVR5进程输出信息"))
810
- open_uvr5 = gr.Button(value=i18n("开启UVR5-WebUI"),variant="primary",visible=True)
811
- close_uvr5 = gr.Button(value=i18n("关闭UVR5-WebUI"),variant="primary",visible=False)
812
- gr.Markdown(value=i18n("0b-语音切分工具"))
813
- with gr.Row():
814
- with gr.Column(scale=3):
815
- with gr.Row():
816
- slice_inp_path=gr.Textbox(label=i18n("音频自动切分输入路径,可文件可文件夹"),value="")
817
- slice_opt_root=gr.Textbox(label=i18n("切分后的子音频的输出根目录"),value="output/slicer_opt")
818
- with gr.Row():
819
- threshold=gr.Textbox(label=i18n("threshold:音量小于这个值视作静音的备选切割点"),value="-34")
820
- min_length=gr.Textbox(label=i18n("min_length:每段最小多长,如果第一段太短一直和后面段连起来直到超过这个值"),value="4000")
821
- min_interval=gr.Textbox(label=i18n("min_interval:最短切割间隔"),value="300")
822
- hop_size=gr.Textbox(label=i18n("hop_size:怎么算音量曲线,越小精度越大计算量越高(不是精度越大效果越好)"),value="10")
823
- max_sil_kept=gr.Textbox(label=i18n("max_sil_kept:切完后静音最多留多长"),value="500")
824
- with gr.Row():
825
- _max=gr.Slider(minimum=0,maximum=1,step=0.05,label=i18n("max:归一化后最大值多少"),value=0.9,interactive=True)
826
- alpha=gr.Slider(minimum=0,maximum=1,step=0.05,label=i18n("alpha_mix:混多少比例归一化后音频进来"),value=0.25,interactive=True)
827
- with gr.Row():
828
- n_process=gr.Slider(minimum=1,maximum=n_cpu,step=1,label=i18n("切割使用的进程数"),value=4,interactive=True)
829
- slicer_info = gr.Textbox(label=i18n("语音切割进程输出信息"))
830
- open_slicer_button=gr.Button(i18n("开启语音切割"), variant="primary",visible=True)
831
- close_slicer_button=gr.Button(i18n("终止语音切割"), variant="primary",visible=False)
832
- gr.Markdown(value=i18n("0bb-语音降噪工具"))
833
- with gr.Row():
834
- with gr.Column(scale=3):
835
- with gr.Row():
836
- denoise_input_dir=gr.Textbox(label=i18n("降噪音频文件输入文件夹"),value="")
837
- denoise_output_dir=gr.Textbox(label=i18n("降噪结果输出文件夹"),value="output/denoise_opt")
838
- with gr.Row():
839
- denoise_info = gr.Textbox(label=i18n("语音降噪进程输出信息"))
840
- open_denoise_button = gr.Button(i18n("开启语音降噪"), variant="primary",visible=True)
841
- close_denoise_button = gr.Button(i18n("终止语音降噪进程"), variant="primary",visible=False)
842
- gr.Markdown(value=i18n("0c-中文批量离线ASR工具"))
843
- with gr.Row():
844
- with gr.Column(scale=3):
845
- with gr.Row():
846
- asr_inp_dir = gr.Textbox(
847
- label=i18n("输入文件夹路径"),
848
- value="D:\\GPT-SoVITS\\raw\\xxx",
849
- interactive=True,
850
- )
851
- asr_opt_dir = gr.Textbox(
852
- label = i18n("输出文件夹路径"),
853
- value = "output/asr_opt",
854
- interactive = True,
855
- )
856
- with gr.Row():
857
- asr_model = gr.Dropdown(
858
- label = i18n("ASR 模型"),
859
- choices = list(asr_dict.keys()),
860
- interactive = True,
861
- value="达摩 ASR (中文)"
862
- )
863
- asr_size = gr.Dropdown(
864
- label = i18n("ASR 模型尺寸"),
865
- choices = ["large"],
866
- interactive = True,
867
- value="large"
868
- )
869
- asr_lang = gr.Dropdown(
870
- label = i18n("ASR 语言设置"),
871
- choices = ["zh","yue"],
872
- interactive = True,
873
- value="zh"
874
- )
875
- asr_precision = gr.Dropdown(
876
- label = i18n("数据类型精度"),
877
- choices = ["float32"],
878
- interactive = True,
879
- value="float32"
880
- )
881
- with gr.Row():
882
- asr_info = gr.Textbox(label=i18n("ASR进程输出信息"))
883
- open_asr_button = gr.Button(i18n("开启离线批量ASR"), variant="primary",visible=True)
884
- close_asr_button = gr.Button(i18n("终止ASR进程"), variant="primary",visible=False)
885
-
886
- def change_lang_choices(key): #根据选择的模型修改可选的语言
887
- # return gr.Dropdown(choices=asr_dict[key]['lang'])
888
- return {"__type__": "update", "choices": asr_dict[key]['lang'],"value":asr_dict[key]['lang'][0]}
889
- def change_size_choices(key): # 根据选择的模型修改可选的模型尺寸
890
- # return gr.Dropdown(choices=asr_dict[key]['size'])
891
- return {"__type__": "update", "choices": asr_dict[key]['size'],"value":asr_dict[key]['size'][-1]}
892
- def change_precision_choices(key): #根据选择的模型修改可选的语言
893
- if key =="Faster Whisper (多语种)":
894
- if default_batch_size <= 4:
895
- precision = 'int8'
896
- elif is_half:
897
- precision = 'float16'
898
- else:
899
- precision = 'float32'
900
- else:
901
- precision = 'float32'
902
- # return gr.Dropdown(choices=asr_dict[key]['precision'])
903
- return {"__type__": "update", "choices": asr_dict[key]['precision'],"value":precision}
904
- asr_model.change(change_lang_choices, [asr_model], [asr_lang])
905
- asr_model.change(change_size_choices, [asr_model], [asr_size])
906
- asr_model.change(change_precision_choices, [asr_model], [asr_precision])
907
-
908
-
909
- gr.Markdown(value=i18n("0d-语音文本校对标注工具"))
910
- with gr.Row():
911
- with gr.Column(scale=3):
912
- with gr.Row():
913
- path_list = gr.Textbox(
914
- label=i18n(".list标注文件的路径"),
915
- value="D:\\RVC1006\\GPT-SoVITS\\raw\\xxx.list",
916
- interactive=True,
917
- )
918
- label_info = gr.Textbox(label=i18n("打标工具进程输出信息"))
919
-
920
- open_label = gr.Button(value=i18n("开启打标WebUI"),variant="primary",visible=True)
921
- close_label = gr.Button(value=i18n("关闭打标WebUI"),variant="primary",visible=False)
922
- open_label.click(change_label, [path_list], [label_info,open_label,close_label])
923
- close_label.click(change_label, [path_list], [label_info,open_label,close_label])
924
- open_uvr5.click(change_uvr5, [], [uvr5_info,open_uvr5,close_uvr5])
925
- close_uvr5.click(change_uvr5, [], [uvr5_info,open_uvr5,close_uvr5])
926
-
927
- with gr.TabItem(i18n("1-GPT-SoVITS-TTS")):
928
- with gr.Row():
929
- with gr.Row():
930
- exp_name = gr.Textbox(label=i18n("*实验/模型名"), value="xxx", interactive=True)
931
- gpu_info = gr.Textbox(label=i18n("显卡信息"), value=gpu_info, visible=True, interactive=False)
932
- version_checkbox = gr.Radio(label=i18n("版本"),value=version,choices=['v1','v2','v3'])
933
- with gr.Row():
934
- pretrained_s2G = gr.Textbox(label=i18n("预训练的SoVITS-G模型路径"), value=pretrained_sovits_name[int(version[-1])-1], interactive=True, lines=2, max_lines=3,scale=9)
935
- pretrained_s2D = gr.Textbox(label=i18n("预训练的SoVITS-D模型路径"), value=pretrained_sovits_name[int(version[-1])-1].replace("s2G","s2D"), interactive=True, lines=2, max_lines=3,scale=9)
936
- pretrained_s1 = gr.Textbox(label=i18n("预训练的GPT模型路径"), value=pretrained_gpt_name[int(version[-1])-1], interactive=True, lines=2, max_lines=3,scale=10)
937
- with gr.TabItem(i18n("1A-训练集格式化工具")):
938
- gr.Markdown(value=i18n("输出logs/实验名目录下应有23456开头的文件和文件夹"))
939
- with gr.Row():
940
- with gr.Row():
941
- inp_text = gr.Textbox(label=i18n("*文本标注文件"),value=r"D:\RVC1006\GPT-SoVITS\raw\xxx.list",interactive=True,scale=10)
942
- with gr.Row():
943
- inp_wav_dir = gr.Textbox(
944
- label=i18n("*训练集音频文件目录"),
945
- # value=r"D:\RVC1006\GPT-SoVITS\raw\xxx",
946
- interactive=True,
947
- placeholder=i18n("填切割后音频所在目录!读取的音频文件完整路径=该目录-拼接-list文件里波形对应的文件名(不是全路径)。如果留空则使用.list文件里的绝对全路径。"), scale=10
948
- )
949
- gr.Markdown(value=i18n("1Aa-文本内容"))
950
- with gr.Row():
951
- with gr.Row():
952
- gpu_numbers1a = gr.Textbox(label=i18n("GPU卡号以-分割,每个卡号一个进程"),value="%s-%s"%(gpus,gpus),interactive=True)
953
- with gr.Row():
954
- bert_pretrained_dir = gr.Textbox(label=i18n("预训练的中文BERT模型路径"),value="GPT_SoVITS/pretrained_models/chinese-roberta-wwm-ext-large",interactive=False,lines=2)
955
- with gr.Row():
956
- button1a_open = gr.Button(i18n("开启文本获取"), variant="primary",visible=True)
957
- button1a_close = gr.Button(i18n("终止文本获取进程"), variant="primary",visible=False)
958
- with gr.Row():
959
- info1a=gr.Textbox(label=i18n("文本进程输出信息"))
960
- gr.Markdown(value=i18n("1Ab-SSL自监督特征提取"))
961
- with gr.Row():
962
- with gr.Row():
963
- gpu_numbers1Ba = gr.Textbox(label=i18n("GPU卡号以-分割,每个卡号一个进程"),value="%s-%s"%(gpus,gpus),interactive=True)
964
- with gr.Row():
965
- cnhubert_base_dir = gr.Textbox(label=i18n("预训练的SSL模型路径"),value="GPT_SoVITS/pretrained_models/chinese-hubert-base",interactive=False,lines=2)
966
- with gr.Row():
967
- button1b_open = gr.Button(i18n("开启SSL提取"), variant="primary",visible=True)
968
- button1b_close = gr.Button(i18n("终止SSL提取进程"), variant="primary",visible=False)
969
- with gr.Row():
970
- info1b=gr.Textbox(label=i18n("SSL进程输出信息"))
971
- gr.Markdown(value=i18n("1Ac-语义token提取"))
972
- with gr.Row():
973
- with gr.Row():
974
- gpu_numbers1c = gr.Textbox(label=i18n("GPU卡号以-分割,每个卡号一个进程"),value="%s-%s"%(gpus,gpus),interactive=True)
975
- with gr.Row():
976
- pretrained_s2G_ = gr.Textbox(label=i18n("预训练的SoVITS-G模型路径"), value=pretrained_sovits_name[int(version[-1])-1], interactive=False,lines=2)
977
- with gr.Row():
978
- button1c_open = gr.Button(i18n("开启语义token提取"), variant="primary",visible=True)
979
- button1c_close = gr.Button(i18n("终止语义token提取进程"), variant="primary",visible=False)
980
- with gr.Row():
981
- info1c=gr.Textbox(label=i18n("语义token提取进程输出信息"))
982
- gr.Markdown(value=i18n("1Aabc-训练集格式化一键三连"))
983
- with gr.Row():
984
- with gr.Row():
985
- button1abc_open = gr.Button(i18n("开启一键三连"), variant="primary",visible=True)
986
- button1abc_close = gr.Button(i18n("终止一键三连"), variant="primary",visible=False)
987
- with gr.Row():
988
- info1abc=gr.Textbox(label=i18n("一键三连进程输出信息"))
989
-
990
- pretrained_s2G.change(sync,[pretrained_s2G],[pretrained_s2G_])
991
- open_asr_button.click(open_asr, [asr_inp_dir, asr_opt_dir, asr_model, asr_size, asr_lang, asr_precision], [asr_info,open_asr_button,close_asr_button,path_list,inp_text,inp_wav_dir])
992
- close_asr_button.click(close_asr, [], [asr_info,open_asr_button,close_asr_button])
993
- 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,asr_inp_dir,denoise_input_dir,inp_wav_dir])
994
- close_slicer_button.click(close_slice, [], [slicer_info,open_slicer_button,close_slicer_button])
995
- open_denoise_button.click(open_denoise, [denoise_input_dir,denoise_output_dir], [denoise_info,open_denoise_button,close_denoise_button,asr_inp_dir,inp_wav_dir])
996
- close_denoise_button.click(close_denoise, [], [denoise_info,open_denoise_button,close_denoise_button])
997
-
998
- button1a_open.click(open1a, [inp_text,inp_wav_dir,exp_name,gpu_numbers1a,bert_pretrained_dir], [info1a,button1a_open,button1a_close])
999
- button1a_close.click(close1a, [], [info1a,button1a_open,button1a_close])
1000
- button1b_open.click(open1b, [inp_text,inp_wav_dir,exp_name,gpu_numbers1Ba,cnhubert_base_dir], [info1b,button1b_open,button1b_close])
1001
- button1b_close.click(close1b, [], [info1b,button1b_open,button1b_close])
1002
- button1c_open.click(open1c, [inp_text,exp_name,gpu_numbers1c,pretrained_s2G], [info1c,button1c_open,button1c_close])
1003
- button1c_close.click(close1c, [], [info1c,button1c_open,button1c_close])
1004
- 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])
1005
- button1abc_close.click(close1abc, [], [info1abc,button1abc_open,button1abc_close])
1006
- with gr.TabItem(i18n("1B-微调训练")):
1007
- gr.Markdown(value=i18n("1Ba-SoVITS训练。用于分享的模型文件输出在SoVITS_weights下。"))
1008
- with gr.Row():
1009
- with gr.Column():
1010
- with gr.Row():
1011
- batch_size = gr.Slider(minimum=1,maximum=default_max_batch_size,step=1,label=i18n("每张显卡的batch_size"),value=default_batch_size,interactive=True)
1012
- total_epoch = gr.Slider(minimum=1,maximum=max_sovits_epoch,step=1,label=i18n("总训练轮数total_epoch,不建议太高"),value=default_sovits_epoch,interactive=True)
1013
- with gr.Row():
1014
- text_low_lr_rate = gr.Slider(minimum=0.2,maximum=0.6,step=0.05,label=i18n("文本模块学习率权重"),value=0.4,interactive=True if version!="v3"else False)#v3 not need
1015
- save_every_epoch = gr.Slider(minimum=1,maximum=max_sovits_save_every_epoch,step=1,label=i18n("保存频率save_every_epoch"),value=default_sovits_save_every_epoch,interactive=True)
1016
- with gr.Column():
1017
- with gr.Column():
1018
- if_save_latest = gr.Checkbox(label=i18n("是否仅保存最新的ckpt文件以节省硬盘空间"), value=True, interactive=True, show_label=True)
1019
- if_save_every_weights = gr.Checkbox(label=i18n("是否在每次保存时间点将最终小模型保存至weights文件夹"), value=True, interactive=True, show_label=True)
1020
- if_grad_ckpt = gr.Checkbox(label="v3是否开启梯度检查点节省显存占用", value=False, interactive=True if version == "v3" else False, show_label=True) # 只有V3s2可以用
1021
- with gr.Row():
1022
- gpu_numbers1Ba = gr.Textbox(label=i18n("GPU卡号以-分割,每个卡号一个进程"), value="%s" % (gpus), interactive=True)
1023
- with gr.Row():
1024
- with gr.Row():
1025
- button1Ba_open = gr.Button(i18n("开启SoVITS训练"), variant="primary",visible=True)
1026
- button1Ba_close = gr.Button(i18n("终止SoVITS训练"), variant="primary",visible=False)
1027
- with gr.Row():
1028
- info1Ba=gr.Textbox(label=i18n("SoVITS训练进程输出信息"))
1029
- gr.Markdown(value=i18n("1Bb-GPT训练。用于分享的模型文件输出在GPT_weights下。"))
1030
- with gr.Row():
1031
- with gr.Column():
1032
- with gr.Row():
1033
- batch_size1Bb = gr.Slider(minimum=1,maximum=40,step=1,label=i18n("每张显卡的batch_size"),value=default_batch_size_s1,interactive=True)
1034
- total_epoch1Bb = gr.Slider(minimum=2,maximum=50,step=1,label=i18n("总训练轮数total_epoch"),value=15,interactive=True)
1035
- with gr.Row():
1036
- save_every_epoch1Bb = gr.Slider(minimum=1,maximum=50,step=1,label=i18n("保存频率save_every_epoch"),value=5,interactive=True)
1037
- if_dpo = gr.Checkbox(label=i18n("是否开启dpo训练选项(实验性)"), value=False, interactive=True, show_label=True)
1038
- with gr.Column():
1039
- with gr.Column():
1040
- if_save_latest1Bb = gr.Checkbox(label=i18n("是否仅保存最新的ckpt文件以节省硬盘空间"), value=True, interactive=True, show_label=True)
1041
- if_save_every_weights1Bb = gr.Checkbox(label=i18n("是否在每次保存时间点将最终小模型保存至weights文件夹"), value=True, interactive=True, show_label=True)
1042
- with gr.Row():
1043
- gpu_numbers1Bb = gr.Textbox(label=i18n("GPU卡号以-分割,每个卡号一个进程"), value="%s" % (gpus), interactive=True)
1044
- with gr.Row():
1045
- with gr.Row():
1046
- button1Bb_open = gr.Button(i18n("开启GPT训练"), variant="primary",visible=True)
1047
- button1Bb_close = gr.Button(i18n("终止GPT训练"), variant="primary",visible=False)
1048
- with gr.Row():
1049
- info1Bb=gr.Textbox(label=i18n("GPT训练进程输出信息"))
1050
- 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,if_grad_ckpt], [info1Ba,button1Ba_open,button1Ba_close])
1051
- button1Ba_close.click(close1Ba, [], [info1Ba,button1Ba_open,button1Ba_close])
1052
- button1Bb_open.click(open1Bb, [batch_size1Bb,total_epoch1Bb,exp_name,if_dpo,if_save_latest1Bb,if_save_every_weights1Bb,save_every_epoch1Bb,gpu_numbers1Bb,pretrained_s1], [info1Bb,button1Bb_open,button1Bb_close])
1053
- button1Bb_close.click(close1Bb, [], [info1Bb,button1Bb_open,button1Bb_close])
1054
- with gr.TabItem(i18n("1C-推理")):
1055
- gr.Markdown(value=i18n("选择训练完存放在SoVITS_weights和GPT_weights下的模型。默认的一个是底模,体验5秒Zero Shot TTS用。"))
1056
- with gr.Row():
1057
- with gr.Row():
1058
- GPT_dropdown = gr.Dropdown(label=i18n("*GPT模型列表"), choices=sorted(GPT_names,key=custom_sort_key),value=pretrained_gpt_name[0],interactive=True)
1059
- SoVITS_dropdown = gr.Dropdown(label=i18n("*SoVITS模型列表"), choices=sorted(SoVITS_names,key=custom_sort_key),value=pretrained_sovits_name[0],interactive=True)
1060
- with gr.Row():
1061
- gpu_number_1C=gr.Textbox(label=i18n("GPU卡号,只能填1个整数"), value=gpus, interactive=True)
1062
- refresh_button = gr.Button(i18n("刷新模型路径"), variant="primary")
1063
- refresh_button.click(fn=change_choices,inputs=[],outputs=[SoVITS_dropdown,GPT_dropdown])
1064
- with gr.Row():
1065
- with gr.Row():
1066
- batched_infer_enabled = gr.Checkbox(label=i18n("启用并行推理版本"), value=False, interactive=True, show_label=True)
1067
- with gr.Row():
1068
- open_tts = gr.Button(value=i18n("开启TTS推理WebUI"),variant='primary',visible=True)
1069
- close_tts = gr.Button(value=i18n("关闭TTS推理WebUI"),variant='primary',visible=False)
1070
- with gr.Row():
1071
- tts_info = gr.Textbox(label=i18n("TTS推理WebUI进程输出信息"))
1072
- open_tts.click(change_tts_inference, [bert_pretrained_dir,cnhubert_base_dir,gpu_number_1C,GPT_dropdown,SoVITS_dropdown, batched_infer_enabled], [tts_info,open_tts,close_tts])
1073
- close_tts.click(change_tts_inference, [bert_pretrained_dir,cnhubert_base_dir,gpu_number_1C,GPT_dropdown,SoVITS_dropdown, batched_infer_enabled], [tts_info,open_tts,close_tts])
1074
- version_checkbox.change(switch_version,[version_checkbox],[pretrained_s2G,pretrained_s2D,pretrained_s1,GPT_dropdown,SoVITS_dropdown,batch_size,total_epoch,save_every_epoch,text_low_lr_rate, if_grad_ckpt, batched_infer_enabled])
1075
- with gr.TabItem(i18n("2-GPT-SoVITS-变声")):gr.Markdown(value=i18n("施工中,请静候佳音"))
1076
- app.queue().launch(#concurrency_count=511, max_size=1022
1077
- inbrowser=True,
1078
- share=True,
1079
- quiet=True,
1080
- )