tanbw commited on
Commit
11f92b1
1 Parent(s): c1bc199

no message

Browse files
Files changed (1) hide show
  1. webui.py +20 -3
webui.py CHANGED
@@ -155,8 +155,23 @@ parser.add_argument('--model_dir',
155
  default='pretrained_models/CosyVoice-300M',
156
  help='local path or modelscope repo id')
157
  args = parser.parse_args()
158
- cosyvoice = CosyVoice(args.model_dir)
159
- sft_spk = cosyvoice.list_avaliable_spks()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
160
  prompt_sr, target_sr = 16000, 22050
161
  default_data = np.zeros(target_sr)
162
 
@@ -171,7 +186,9 @@ with gr.Blocks() as demo:
171
  with gr.Row():
172
  mode_checkbox_group = gr.Radio(choices=inference_mode_list, label='选择推理模式', value=inference_mode_list[0])
173
  instruction_text = gr.Text(label="操作步骤", value=instruct_dict[inference_mode_list[0]], scale=0.5)
174
- sft_dropdown = gr.Dropdown(choices=sft_spk, label='选择预训练音色', value=sft_spk[0], scale=0.25)
 
 
175
  stream = gr.Radio(choices=stream_mode_list, label='是否流式推理', value=stream_mode_list[0][1])
176
  speed = gr.Number(value=1, label="速度调节(仅支持非流式推理)", minimum=0.5, maximum=2.0, step=0.1)
177
  with gr.Column(scale=0.25):
 
155
  default='pretrained_models/CosyVoice-300M',
156
  help='local path or modelscope repo id')
157
  args = parser.parse_args()
158
+
159
+ cosyvoice_instance = None
160
+
161
+ @spaces.GPU
162
+ def create_cosyvoice(model_dir):
163
+ # 在这里加入你需要的处理逻辑
164
+ if cosyvoice_instance is not None:
165
+ return cosyvoice_instance
166
+
167
+ return CosyVoice(model_dir)
168
+
169
+ @spaces.GPU
170
+ def load_sft_options():
171
+ return cosyvoice.list_avaliable_spks()
172
+ # 将原来的初始化修改为函数调用
173
+ cosyvoice = create_cosyvoice(args.model_dir)
174
+
175
  prompt_sr, target_sr = 16000, 22050
176
  default_data = np.zeros(target_sr)
177
 
 
186
  with gr.Row():
187
  mode_checkbox_group = gr.Radio(choices=inference_mode_list, label='选择推理模式', value=inference_mode_list[0])
188
  instruction_text = gr.Text(label="操作步骤", value=instruct_dict[inference_mode_list[0]], scale=0.5)
189
+ sft_dropdown = gr.Dropdown(choices=[], label='选择预训练音色', scale=0.25)
190
+ load_sft_button = gr.Button("加载预训练音色")
191
+ load_sft_button.click(load_sft_options, outputs=sft_dropdown)
192
  stream = gr.Radio(choices=stream_mode_list, label='是否流式推理', value=stream_mode_list[0][1])
193
  speed = gr.Number(value=1, label="速度调节(仅支持非流式推理)", minimum=0.5, maximum=2.0, step=0.1)
194
  with gr.Column(scale=0.25):