yl12053 commited on
Commit
ec9b22d
1 Parent(s): ae80945
__pycache__/utils.cpython-39.pyc ADDED
Binary file (19.7 kB). View file
 
app.py CHANGED
@@ -39,6 +39,8 @@ debug = False
39
  sovits_params = {}
40
  diff_params = {}
41
 
 
 
42
  def debug_change():
43
  global debug
44
  debug = debug_button.value
@@ -140,6 +142,43 @@ def load_model_func(ckpt_name,cluster_name,config_name,enhance,diff_model_name,d
140
  output_msg = f"模型被成功加载到了{device_name}上\n{index_or_kmeans}:{clu_load}\n扩散模型:{diff_load}"
141
  return output_msg, gr.Dropdown.update(choices=spk_list, value=spk_choice), clip
142
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
143
  def get_file_options(directory, extension):
144
  return [file for file in os.listdir(directory) if file.endswith(extension)]
145
 
@@ -662,6 +701,21 @@ gpus="-".join([i[0]for i in gpu_infos])
662
  sovits_params, diff_params = get_default_settings()
663
 
664
  app = gr.Blocks()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
665
  with app:
666
  gr.Markdown(value="""
667
  ### So-VITS-SVC 4.1-Stable
@@ -677,30 +731,39 @@ with app:
677
  """)
678
  with gr.Tabs():
679
  with gr.TabItem("推理"):
 
 
 
 
 
 
 
 
 
 
 
 
 
 
680
  with gr.Row():
681
- choice_ckpt = gr.Dropdown(label="模型选择", choices=ckpt_list, value="no_model")
682
- model_branch = gr.Textbox(label="模型编码器", placeholder="请先选择模型", interactive=False)
683
- with gr.Row():
684
- config_choice = gr.Dropdown(label="配置文件", choices=config_list, value="no_config")
685
- config_info = gr.Textbox(label="配置文件编码器", placeholder="请选择配置文件")
686
- gr.Markdown(value="""**请检查模型和配置文件的编码器是否匹配**""")
687
- with gr.Row():
688
- diff_choice = gr.Dropdown(label="(可选)选择扩散模型", choices=diff_list, value="no_diff", interactive=True)
689
- diff_config_choice = gr.Dropdown(label="扩散模型配置文件", choices=diff_config_list, value="no_diff_config", interactive=True)
690
- cluster_choice = gr.Dropdown(label="(可选)选择聚类模型/特征检索模型", choices=cluster_list, value="no_clu")
691
  with gr.Row():
692
  enhance = gr.Checkbox(label="是否使用NSF_HIFIGAN增强,该选项对部分训练集少的模型有一定的音质增强效果,但是对训练好的模型有反面效果,默认关闭", value=False)
693
- only_diffusion = gr.Checkbox(label="是否使用全扩散推理,开启后将不使用So-VITS模型,仅使用扩散模型进行完整扩散推理,默认关闭", value=False)
694
- using_device = gr.Dropdown(label="推理设备,默认为自动选择", choices=["Auto","cuda","cpu"], value="Auto")
695
- refresh = gr.Button("刷新选项")
696
- loadckpt = gr.Button("加载模型", variant="primary")
697
- with gr.Row():
698
- model_message = gr.Textbox(label="Output Message")
699
- sid = gr.Dropdown(label="So-VITS说话人", value="speaker0")
 
 
 
700
 
701
- choice_ckpt.change(get_model_info, [choice_ckpt], [model_branch])
702
- config_choice.change(load_json_encoder, [config_choice], [config_info])
703
- refresh.click(refresh_options,[],[choice_ckpt,config_choice,cluster_choice,diff_choice,diff_config_choice])
 
704
 
705
  gr.Markdown(value="""
706
  请稍等片刻,模型加载大约需要10秒。后续操作不需要重新加载模型
@@ -756,7 +819,8 @@ with app:
756
  vc_output1 = gr.Textbox(label="Output Message")
757
  vc_output2 = gr.Audio(label="Output Audio")
758
 
759
- loadckpt.click(load_model_func,[choice_ckpt,cluster_choice,config_choice,enhance,diff_choice,diff_config_choice,only_diffusion,model_branch,using_device],[model_message, sid, cl_num])
 
760
  vc_submit.click(vc_fn, [sid, vc_input3, vc_transform,auto_f0,cluster_ratio, slice_db, noise_scale,pad_seconds,cl_num,lg_num,lgr_num,f0_predictor,enhancer_adaptive_key,cr_threshold,k_step,use_spk_mix,second_encoding,loudness_envelope_adjustment], [vc_output1, vc_output2])
761
  vc_batch_submit.click(vc_batch_fn, [sid, vc_batch_files, vc_transform,auto_f0,cluster_ratio, slice_db, noise_scale,pad_seconds,cl_num,lg_num,lgr_num,f0_predictor,enhancer_adaptive_key,cr_threshold,k_step,use_spk_mix,second_encoding,loudness_envelope_adjustment], [vc_output1])
762
  vc_tts_submit.click(tts_fn, [text_input, tts_spk, sid, vc_transform,auto_f0,cluster_ratio, slice_db, noise_scale,pad_seconds,cl_num,lg_num,lgr_num,f0_predictor,enhancer_adaptive_key,cr_threshold,k_step,use_spk_mix,second_encoding,loudness_envelope_adjustment], [vc_output1, vc_output2])
 
39
  sovits_params = {}
40
  diff_params = {}
41
 
42
+ loaded = None
43
+
44
  def debug_change():
45
  global debug
46
  debug = debug_button.value
 
142
  output_msg = f"模型被成功加载到了{device_name}上\n{index_or_kmeans}:{clu_load}\n扩散模型:{diff_load}"
143
  return output_msg, gr.Dropdown.update(choices=spk_list, value=spk_choice), clip
144
 
145
+ def Newload_model_func(ckpt_name,cluster_name,config_name,enhance,diff_model_name,diff_config_name,only_diffusion,encoder,using_device):
146
+ global model
147
+ config_path = os.path.join(config_dir, config_name)
148
+ diff_config_path = os.path.join(config_dir, diff_config_name) if diff_config_name != "no_diff_config" else "configs/diffusion.yaml"
149
+ with open(config_path, 'r') as f:
150
+ config = json.load(f)
151
+ spk_dict = config["spk"]
152
+ spk_name = config.get('spk', None)
153
+ spk_choice = next(iter(spk_name)) if spk_name else "未检测到音色"
154
+ ckpt_path = os.path.join(workdir, ckpt_name)
155
+ _, _suffix = os.path.splitext(cluster_name)
156
+ fr = True if _suffix == ".pkl" else False #如果是pkl后缀就启用特征检索
157
+ cluster_path = os.path.join(workdir, cluster_name)
158
+ diff_model_path = os.path.join(diff_workdir, diff_model_name)
159
+ shallow_diffusion = True if diff_model_name != "no_diff" else False
160
+ use_spk_mix = False
161
+ device = None if using_device == "Auto" else using_device
162
+ model = Svc(ckpt_path,
163
+ config_path,
164
+ device,
165
+ cluster_path,
166
+ enhance,
167
+ diff_model_path,
168
+ diff_config_path,
169
+ shallow_diffusion,
170
+ only_diffusion,
171
+ use_spk_mix,
172
+ fr)
173
+ spk_list = list(spk_dict.keys())
174
+ clip = 25 if encoder == "Whisper-PPG" else 0 #Whisper必须强制切片25秒
175
+ device_name = torch.cuda.get_device_properties(model.dev).name if "cuda" in str(model.dev) else str(model.dev)
176
+ index_or_kmeans = "特征索引" if fr is True else "聚类模型"
177
+ clu_load = "未加载" if cluster_name == "no_clu" else cluster_name
178
+ diff_load = "未加载" if diff_model_name == "no_diff" else diff_model_name
179
+ #output_msg = f"模型被成功加载到了{device_name}上\n{index_or_kmeans}:{clu_load}\n扩散模型:{diff_load}"
180
+ #return output_msg, gr.Dropdown.update(choices=spk_list, value=spk_choice), clip
181
+
182
  def get_file_options(directory, extension):
183
  return [file for file in os.listdir(directory) if file.endswith(extension)]
184
 
 
701
  sovits_params, diff_params = get_default_settings()
702
 
703
  app = gr.Blocks()
704
+
705
+ def Newget_model_info(choice_ckpt):
706
+ pthfile = os.path.join(workdir, choice_ckpt)
707
+ net = torch.load(pthfile, map_location=torch.device('cpu')) #cpu load
708
+ spk_emb = net["model"].get("emb_g.weight")
709
+ if spk_emb is None:
710
+ return "所选模型缺少emb_g.weight,你可能选择了一个底模"
711
+ _dim, _layer = spk_emb.size()
712
+ model_type = {
713
+ 768: "Vec768-Layer12",
714
+ 256: "Vec256-Layer9 / HubertSoft",
715
+ 1024: "Whisper-PPG"
716
+ }
717
+ return gr.Textbox(visible=False, value=model_type.get(_layer, "不受支持的模型"))
718
+
719
  with app:
720
  gr.Markdown(value="""
721
  ### So-VITS-SVC 4.1-Stable
 
731
  """)
732
  with gr.Tabs():
733
  with gr.TabItem("推理"):
734
+ #with gr.Row():
735
+ # choice_ckpt = gr.Dropdown(label="模型选择", choices=ckpt_list, value="no_model")
736
+ # model_branch = gr.Textbox(label="模型编码器", placeholder="请先选择模型", interactive=False)
737
+ choice_ckpt = gr.Dropdown(value="G_82400.pth", visible=False)
738
+ #with gr.Row():
739
+ # config_choice = gr.Dropdown(label="配置文件", choices=config_list, value="no_config")
740
+ # config_info = gr.Textbox(label="配置文件编码器", placeholder="请选择配置文件")
741
+ config_choice = gr.Dropdown(value="config.json", visible=False)
742
+ #gr.Markdown(value="""**请检查模型和配置文件的编码器是否匹配**""")
743
+ #with gr.Row():
744
+ # diff_choice = gr.Dropdown(label="(可选)选择扩散模型", choices=diff_list, value="no_diff", interactive=True)
745
+ # diff_config_choice = gr.Dropdown(label="扩散模型配置文件", choices=diff_config_list, value="no_diff_config", interactive=True)
746
+ diff_choice = gr.Dropdown(value="no_diff", visible=False)
747
+ diff_config_choice = gr.Dropdown(value="no_diff_config", visible=False)
748
  with gr.Row():
749
+ cluster_choice = gr.Dropdown(label="(可选)选择聚类模型/特征检索模型", choices=cluster_list, value="no_clu")
 
 
 
 
 
 
 
 
 
750
  with gr.Row():
751
  enhance = gr.Checkbox(label="是否使用NSF_HIFIGAN增强,该选项对部分训练集少的模型有一定的音质增强效果,但是对训练好的模型有反面效果,默认关闭", value=False)
752
+ #only_diffusion = gr.Checkbox(label="是否使用全扩散推理,开启后将不使用So-VITS模型,仅使用扩散模型进行完整扩散推理,默认关闭", value=False)
753
+ only_diffusion = gr.Checkbox(value=False, visible=False)
754
+ #using_device = gr.Dropdown(label="推理设备,默认为自动选择", choices=["Auto","cuda","cpu"], value="Auto")
755
+ using_device = gr.Dropdown(value='Auto', visible=False)
756
+ #refresh = gr.Button("刷新选项")
757
+ #loadckpt = gr.Button("加载模型", variant="primary")
758
+ #with gr.Row():
759
+ # model_message = gr.Textbox(label="Output Message")
760
+ # sid = gr.Dropdown(label="So-VITS说话人", value="speaker0")
761
+ sid = gr.Dropdown(value="1001", visible=False)
762
 
763
+ #choice_ckpt.change(get_model_info, [choice_ckpt], [model_branch])
764
+ model_branch = Newget_model_info(choice_ckpt)
765
+ #config_choice.change(load_json_encoder, [config_choice], [config_info])
766
+ #refresh.click(refresh_options,[],[choice_ckpt,config_choice,cluster_choice,diff_choice,diff_config_choice])
767
 
768
  gr.Markdown(value="""
769
  请稍等片刻,模型加载大约需要10秒。后续操作不需要重新加载模型
 
819
  vc_output1 = gr.Textbox(label="Output Message")
820
  vc_output2 = gr.Audio(label="Output Audio")
821
 
822
+ #loadckpt.click(load_model_func,[choice_ckpt,cluster_choice,config_choice,enhance,diff_choice,diff_config_choice,only_diffusion,model_branch,using_device],[model_message, sid, cl_num])
823
+ Newload_model_func(choice_ckpt,cluster_choice,config_choice,enhance,diff_choice,diff_config_choice,only_diffusion,model_branch,using_device)
824
  vc_submit.click(vc_fn, [sid, vc_input3, vc_transform,auto_f0,cluster_ratio, slice_db, noise_scale,pad_seconds,cl_num,lg_num,lgr_num,f0_predictor,enhancer_adaptive_key,cr_threshold,k_step,use_spk_mix,second_encoding,loudness_envelope_adjustment], [vc_output1, vc_output2])
825
  vc_batch_submit.click(vc_batch_fn, [sid, vc_batch_files, vc_transform,auto_f0,cluster_ratio, slice_db, noise_scale,pad_seconds,cl_num,lg_num,lgr_num,f0_predictor,enhancer_adaptive_key,cr_threshold,k_step,use_spk_mix,second_encoding,loudness_envelope_adjustment], [vc_output1])
826
  vc_tts_submit.click(tts_fn, [text_input, tts_spk, sid, vc_transform,auto_f0,cluster_ratio, slice_db, noise_scale,pad_seconds,cl_num,lg_num,lgr_num,f0_predictor,enhancer_adaptive_key,cr_threshold,k_step,use_spk_mix,second_encoding,loudness_envelope_adjustment], [vc_output1, vc_output2])
cluster/__pycache__/__init__.cpython-39.pyc ADDED
Binary file (1.09 kB). View file
 
inference/__pycache__/__init__.cpython-39.pyc ADDED
Binary file (140 Bytes). View file
 
inference/__pycache__/infer_tool.cpython-39.pyc ADDED
Binary file (14.9 kB). View file
 
inference/__pycache__/slicer.cpython-39.pyc ADDED
Binary file (3.84 kB). View file
 
modules/__pycache__/__init__.cpython-39.pyc ADDED
Binary file (138 Bytes). View file
 
modules/__pycache__/commons.cpython-39.pyc ADDED
Binary file (6.61 kB). View file