webui.py 59 KB

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