webui.py 45 KB

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