Spark808 commited on
Commit
db48aff
·
1 Parent(s): 4505994

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -15
app.py CHANGED
@@ -15,7 +15,6 @@ from config import is_half, device
15
 
16
  logging.getLogger("numba").setLevel(logging.WARNING)
17
 
18
-
19
  def create_vc_fn(tgt_sr, net_g, vc, if_f0, file_index, file_big_npy):
20
  def vc_fn(input_audio, f0_up_key, f0_method, index_rate):
21
  try:
@@ -59,7 +58,6 @@ def create_vc_fn(tgt_sr, net_g, vc, if_f0, file_index, file_big_npy):
59
 
60
  return vc_fn
61
 
62
-
63
  def load_hubert():
64
  global hubert_model
65
  models, _, _ = checkpoint_utils.load_model_ensemble_and_task(
@@ -74,17 +72,19 @@ def load_hubert():
74
  hubert_model = hubert_model.float()
75
  hubert_model.eval()
76
 
77
-
78
  if __name__ == '__main__':
79
  parser = argparse.ArgumentParser()
80
  parser.add_argument('--api', action="store_true", default=False)
81
  parser.add_argument("--share", action="store_true", default=False, help="share gradio app")
82
  parser.add_argument("--files", action="store_true", default=False, help="load audio from path")
83
  args, unknown = parser.parse_known_args()
 
84
  load_hubert()
85
  models = []
 
86
  with open("weights/model_info.json", "r", encoding="utf-8") as f:
87
  models_info = json.load(f)
 
88
  for name, info in models_info.items():
89
  if not info['enable']:
90
  continue
@@ -95,6 +95,7 @@ if __name__ == '__main__':
95
  cpt = torch.load(f"weights/{name}/{name}.pth", map_location="cpu")
96
  tgt_sr = cpt["config"][-1]
97
  if_f0 = cpt.get("f0", 1)
 
98
  if if_f0 == 1:
99
  net_g = SynthesizerTrnMs256NSFsid(*cpt["config"], is_half=is_half)
100
  else:
@@ -102,10 +103,12 @@ if __name__ == '__main__':
102
  del net_g.enc_q
103
  print(net_g.load_state_dict(cpt["weight"], strict=False))
104
  net_g.eval().to(device)
 
105
  if is_half:
106
  net_g = net_g.half()
107
  else:
108
  net_g = net_g.float()
 
109
  vc = VC(tgt_sr, device, is_half)
110
  models.append((name, title, cover, create_vc_fn(tgt_sr, net_g, vc, if_f0, index, npy)))
111
 
@@ -152,16 +155,16 @@ if __name__ == '__main__':
152
  vc_submit.click(vc_fn, [vc_input, vc_transpose, vc_f0method, vc_index_ratio], [vc_output1, vc_output2])
153
  app.queue(concurrency_count=1, max_size=20, api_open=args.api).launch(share=args.share)
154
 
155
- # Note: The following code is outside the `__main__` block, as it was causing indentation issues in the provided code.
156
- iface = gr.Interface(
157
- fn=create_vc_fn(tgt_sr, net_g, vc, if_f0, file_index, file_big_npy),
158
- inputs=[
159
- gr.inputs.Audio(source="microphone", type="numpy", sample_rate=16000),
160
- gr.inputs.Slider(minimum=-12, maximum=12, step=1, default=0),
161
- gr.inputs.Radio(["world", "dio"], label="F0 method"),
162
- gr.inputs.Slider(minimum=0, maximum=1, step=0.01, default=0.5)
163
- ],
164
- outputs="text",
165
- )
166
 
167
- iface.launch()
 
15
 
16
  logging.getLogger("numba").setLevel(logging.WARNING)
17
 
 
18
  def create_vc_fn(tgt_sr, net_g, vc, if_f0, file_index, file_big_npy):
19
  def vc_fn(input_audio, f0_up_key, f0_method, index_rate):
20
  try:
 
58
 
59
  return vc_fn
60
 
 
61
  def load_hubert():
62
  global hubert_model
63
  models, _, _ = checkpoint_utils.load_model_ensemble_and_task(
 
72
  hubert_model = hubert_model.float()
73
  hubert_model.eval()
74
 
 
75
  if __name__ == '__main__':
76
  parser = argparse.ArgumentParser()
77
  parser.add_argument('--api', action="store_true", default=False)
78
  parser.add_argument("--share", action="store_true", default=False, help="share gradio app")
79
  parser.add_argument("--files", action="store_true", default=False, help="load audio from path")
80
  args, unknown = parser.parse_known_args()
81
+
82
  load_hubert()
83
  models = []
84
+
85
  with open("weights/model_info.json", "r", encoding="utf-8") as f:
86
  models_info = json.load(f)
87
+
88
  for name, info in models_info.items():
89
  if not info['enable']:
90
  continue
 
95
  cpt = torch.load(f"weights/{name}/{name}.pth", map_location="cpu")
96
  tgt_sr = cpt["config"][-1]
97
  if_f0 = cpt.get("f0", 1)
98
+
99
  if if_f0 == 1:
100
  net_g = SynthesizerTrnMs256NSFsid(*cpt["config"], is_half=is_half)
101
  else:
 
103
  del net_g.enc_q
104
  print(net_g.load_state_dict(cpt["weight"], strict=False))
105
  net_g.eval().to(device)
106
+
107
  if is_half:
108
  net_g = net_g.half()
109
  else:
110
  net_g = net_g.float()
111
+
112
  vc = VC(tgt_sr, device, is_half)
113
  models.append((name, title, cover, create_vc_fn(tgt_sr, net_g, vc, if_f0, index, npy)))
114
 
 
155
  vc_submit.click(vc_fn, [vc_input, vc_transpose, vc_f0method, vc_index_ratio], [vc_output1, vc_output2])
156
  app.queue(concurrency_count=1, max_size=20, api_open=args.api).launch(share=args.share)
157
 
158
+ # Note: The following code is outside the `__main__` block, as it was causing indentation issues in the provided code.
159
+ iface = gr.Interface(
160
+ fn=create_vc_fn(tgt_sr, net_g, vc, if_f0, file_index, file_big_npy),
161
+ inputs=[
162
+ gr.inputs.Audio(source="microphone", type="numpy", sample_rate=16000),
163
+ gr.inputs.Slider(minimum=-12, maximum=12, step=1, default=0),
164
+ gr.inputs.Radio(["world", "dio"], label="F0 method"),
165
+ gr.inputs.Slider(minimum=0, maximum=1, step=0.01, default=0.5)
166
+ ],
167
+ outputs="text",
168
+ )
169
 
170
+ iface.launch()