LaynzID12 commited on
Commit
6d5ef78
1 Parent(s): b37aea2

Upload app (3).py

Browse files
Files changed (1) hide show
  1. app (3).py +553 -0
app (3).py ADDED
@@ -0,0 +1,553 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import glob
3
+ import json
4
+ import traceback
5
+ import logging
6
+ import gradio as gr
7
+ import numpy as np
8
+ import librosa
9
+ import torch
10
+ import asyncio
11
+ import edge_tts
12
+ import sys
13
+ import io
14
+
15
+ from datetime import datetime
16
+ from lib.config.config import Config
17
+ from lib.vc.vc_infer_pipeline import VC
18
+ from lib.vc.settings import change_audio_mode
19
+ from lib.vc.audio import load_audio
20
+ from lib.infer_pack.models import (
21
+ SynthesizerTrnMs256NSFsid,
22
+ SynthesizerTrnMs256NSFsid_nono,
23
+ SynthesizerTrnMs768NSFsid,
24
+ SynthesizerTrnMs768NSFsid_nono,
25
+ )
26
+ from lib.vc.utils import (
27
+ combine_vocal_and_inst,
28
+ cut_vocal_and_inst,
29
+ download_audio,
30
+ load_hubert
31
+ )
32
+
33
+ config = Config()
34
+ logging.getLogger("numba").setLevel(logging.WARNING)
35
+ logger = logging.getLogger(__name__)
36
+ spaces = os.getenv("SYSTEM") == "spaces"
37
+ force_support = None
38
+ if config.unsupported is False:
39
+ if config.device == "mps" or config.device == "cpu":
40
+ force_support = False
41
+ else:
42
+ force_support = True
43
+
44
+ audio_mode = []
45
+ f0method_mode = []
46
+ f0method_info = ""
47
+ hubert_model = load_hubert(config)
48
+
49
+ if force_support is False or spaces is True:
50
+ if spaces is True:
51
+ audio_mode = ["Upload audio", "TTS Audio"]
52
+ else:
53
+ audio_mode = ["Input path", "Upload audio", "TTS Audio"]
54
+ f0method_mode = ["pm", "harvest"]
55
+ f0method_info = "PM is fast, Harvest is good but extremely slow, Rvmpe is alternative to harvest (might be better). (Default: PM)"
56
+ else:
57
+ audio_mode = ["Input path", "Upload audio", "Youtube", "TTS Audio"]
58
+ f0method_mode = ["pm", "harvest", "crepe"]
59
+ f0method_info = "PM is fast, Harvest is good but extremely slow, Rvmpe is alternative to harvest (might be better), and Crepe effect is good but requires GPU (Default: PM)"
60
+
61
+ if os.path.isfile("rmvpe.pt"):
62
+ f0method_mode.insert(2, "rmvpe")
63
+
64
+ def create_vc_fn(model_name, tgt_sr, net_g, vc, if_f0, version, file_index):
65
+ def vc_fn(
66
+ vc_audio_mode,
67
+ vc_input,
68
+ vc_upload,
69
+ tts_text,
70
+ tts_voice,
71
+ f0_up_key,
72
+ f0_method,
73
+ index_rate,
74
+ filter_radius,
75
+ resample_sr,
76
+ rms_mix_rate,
77
+ protect,
78
+ ):
79
+ try:
80
+ logs = []
81
+ logger.info(f"Converting using {model_name}...")
82
+ logs.append(f"Converting using {model_name}...")
83
+ yield "\n".join(logs), None
84
+ if vc_audio_mode == "Input path" or "Youtube" and vc_input != "":
85
+ audio = load_audio(vc_input, 16000)
86
+ audio_max = np.abs(audio).max() / 0.95
87
+ if audio_max > 1:
88
+ audio /= audio_max
89
+ elif vc_audio_mode == "Upload audio":
90
+ if vc_upload is None:
91
+ return "You need to upload an audio", None
92
+ sampling_rate, audio = vc_upload
93
+ duration = audio.shape[0] / sampling_rate
94
+ if duration > 20 and spaces:
95
+ return "Please upload an audio file that is less than 20 seconds. If you need to generate a longer audio file, please use Colab.", None
96
+ audio = (audio / np.iinfo(audio.dtype).max).astype(np.float32)
97
+ if len(audio.shape) > 1:
98
+ audio = librosa.to_mono(audio.transpose(1, 0))
99
+ if sampling_rate != 16000:
100
+ audio = librosa.resample(audio, orig_sr=sampling_rate, target_sr=16000)
101
+ elif vc_audio_mode == "TTS Audio":
102
+ if len(tts_text) > 100 and spaces:
103
+ return "Text is too long", None
104
+ if tts_text is None or tts_voice is None:
105
+ return "You need to enter text and select a voice", None
106
+ os.makedirs("output", exist_ok=True)
107
+ os.makedirs(os.path.join("output", "tts"), exist_ok=True)
108
+ asyncio.run(edge_tts.Communicate(tts_text, "-".join(tts_voice.split('-')[:-1])).save(os.path.join("output", "tts", "tts.mp3")))
109
+ audio, sr = librosa.load(os.path.join("output", "tts", "tts.mp3"), sr=16000, mono=True)
110
+ vc_input = os.path.join("output", "tts", "tts.mp3")
111
+ times = [0, 0, 0]
112
+ f0_up_key = int(f0_up_key)
113
+ audio_opt = vc.pipeline(
114
+ hubert_model,
115
+ net_g,
116
+ 0,
117
+ audio,
118
+ vc_input,
119
+ times,
120
+ f0_up_key,
121
+ f0_method,
122
+ file_index,
123
+ # file_big_npy,
124
+ index_rate,
125
+ if_f0,
126
+ filter_radius,
127
+ tgt_sr,
128
+ resample_sr,
129
+ rms_mix_rate,
130
+ version,
131
+ protect,
132
+ f0_file=None,
133
+ )
134
+ info = f"[{datetime.now().strftime('%Y-%m-%d %H:%M')}]: npy: {times[0]}, f0: {times[1]}s, infer: {times[2]}s"
135
+ logger.info(f"{model_name} | {info}")
136
+ logs.append(f"Successfully Convert {model_name}\n{info}")
137
+ yield "\n".join(logs), (tgt_sr, audio_opt)
138
+ except Exception as err:
139
+ info = traceback.format_exc()
140
+ logger.error(info)
141
+ logger.error(f"Error when using {model_name}.\n{str(err)}")
142
+ yield info, None
143
+ return vc_fn
144
+
145
+ def load_model():
146
+ categories = []
147
+ category_count = 0
148
+ if os.path.isfile("weights/folder_info.json"):
149
+ with open("weights/folder_info.json", "r", encoding="utf-8") as f:
150
+ folder_info = json.load(f)
151
+ for category_name, category_info in folder_info.items():
152
+ if not category_info['enable']:
153
+ continue
154
+ category_title = category_info['title']
155
+ category_folder = category_info['folder_path']
156
+ description = category_info['description']
157
+ models = []
158
+ with open(f"weights/{category_folder}/model_info.json", "r", encoding="utf-8") as f:
159
+ models_info = json.load(f)
160
+ for character_name, info in models_info.items():
161
+ if not info['enable']:
162
+ continue
163
+ model_title = info['title']
164
+ model_name = info['model_path']
165
+ model_author = info.get("author", None)
166
+ model_cover = f"weights/{category_folder}/{character_name}/{info['cover']}"
167
+ model_index = f"weights/{category_folder}/{character_name}/{info['feature_retrieval_library']}"
168
+ cpt = torch.load(f"weights/{category_folder}/{character_name}/{model_name}", map_location="cpu")
169
+ tgt_sr = cpt["config"][-1]
170
+ cpt["config"][-3] = cpt["weight"]["emb_g.weight"].shape[0] # n_spk
171
+ if_f0 = cpt.get("f0", 1)
172
+ version = cpt.get("version", "v1")
173
+ if version == "v1":
174
+ if if_f0 == 1:
175
+ net_g = SynthesizerTrnMs256NSFsid(*cpt["config"], is_half=config.is_half)
176
+ else:
177
+ net_g = SynthesizerTrnMs256NSFsid_nono(*cpt["config"])
178
+ model_version = "V1"
179
+ elif version == "v2":
180
+ if if_f0 == 1:
181
+ net_g = SynthesizerTrnMs768NSFsid(*cpt["config"], is_half=config.is_half)
182
+ else:
183
+ net_g = SynthesizerTrnMs768NSFsid_nono(*cpt["config"])
184
+ model_version = "V2"
185
+ del net_g.enc_q
186
+ logger.info(net_g.load_state_dict(cpt["weight"], strict=False))
187
+ net_g.eval().to(config.device)
188
+ if config.is_half:
189
+ net_g = net_g.half()
190
+ else:
191
+ net_g = net_g.float()
192
+ vc = VC(tgt_sr, config)
193
+ logger.info(f"Model loaded: {character_name} / {info['feature_retrieval_library']} | ({model_version})")
194
+ models.append((character_name, model_title, model_author, model_cover, model_version, create_vc_fn(model_name, tgt_sr, net_g, vc, if_f0, version, model_index)))
195
+ category_count += 1
196
+ categories.append([category_title, description, models])
197
+ elif os.path.exists("weights"):
198
+ models = []
199
+ for w_root, w_dirs, _ in os.walk("weights"):
200
+ model_count = 1
201
+ for sub_dir in w_dirs:
202
+ pth_files = glob.glob(f"weights/{sub_dir}/*.pth")
203
+ index_files = glob.glob(f"weights/{sub_dir}/*.index")
204
+ if pth_files == []:
205
+ logger.debug(f"Model [{model_count}/{len(w_dirs)}]: No Model file detected, skipping...")
206
+ continue
207
+ cpt = torch.load(pth_files[0])
208
+ tgt_sr = cpt["config"][-1]
209
+ cpt["config"][-3] = cpt["weight"]["emb_g.weight"].shape[0] # n_spk
210
+ if_f0 = cpt.get("f0", 1)
211
+ version = cpt.get("version", "v1")
212
+ if version == "v1":
213
+ if if_f0 == 1:
214
+ net_g = SynthesizerTrnMs256NSFsid(*cpt["config"], is_half=config.is_half)
215
+ else:
216
+ net_g = SynthesizerTrnMs256NSFsid_nono(*cpt["config"])
217
+ model_version = "V1"
218
+ elif version == "v2":
219
+ if if_f0 == 1:
220
+ net_g = SynthesizerTrnMs768NSFsid(*cpt["config"], is_half=config.is_half)
221
+ else:
222
+ net_g = SynthesizerTrnMs768NSFsid_nono(*cpt["config"])
223
+ model_version = "V2"
224
+ del net_g.enc_q
225
+ logger.info(net_g.load_state_dict(cpt["weight"], strict=False))
226
+ net_g.eval().to(config.device)
227
+ if config.is_half:
228
+ net_g = net_g.half()
229
+ else:
230
+ net_g = net_g.float()
231
+ vc = VC(tgt_sr, config)
232
+ if index_files == []:
233
+ logger.warning("No Index file detected!")
234
+ index_info = "None"
235
+ model_index = ""
236
+ else:
237
+ index_info = index_files[0]
238
+ model_index = index_files[0]
239
+ logger.info(f"Model loaded [{model_count}/{len(w_dirs)}]: {index_files[0]} / {index_info} | ({model_version})")
240
+ model_count += 1
241
+ models.append((index_files[0][:-4], index_files[0][:-4], "", "", model_version, create_vc_fn(index_files[0], tgt_sr, net_g, vc, if_f0, version, model_index)))
242
+ categories.append(["Models", "", models])
243
+ else:
244
+ categories = []
245
+ return categories
246
+
247
+ if __name__ == '__main__':
248
+ categories = load_model()
249
+ tts_voice_list = asyncio.new_event_loop().run_until_complete(edge_tts.list_voices())
250
+ voices = [f"{v['ShortName']}-{v['Gender']}" for v in tts_voice_list]
251
+ with gr.Blocks() as app:
252
+ gr.Markdown(
253
+ "<div align='center'>\n\n"+
254
+ "# Multi Model RVC Inference\n\n"+
255
+ "[![Repository](https://img.shields.io/badge/Github-Multi%20Model%20RVC%20Inference-blue?style=for-the-badge&logo=github)](https://github.com/ArkanDash/Multi-Model-RVC-Inference)\n\n"+
256
+ "</div>"
257
+ )
258
+ if categories == []:
259
+ gr.Markdown(
260
+ "<div align='center'>\n\n"+
261
+ "## No model found, please add the model into weights folder\n\n"+
262
+ "</div>"
263
+ )
264
+ for (folder_title, description, models) in categories:
265
+ with gr.TabItem(folder_title):
266
+ if description:
267
+ gr.Markdown(f"### <center> {description}")
268
+ with gr.Tabs():
269
+ if not models:
270
+ gr.Markdown("# <center> No Model Loaded.")
271
+ gr.Markdown("## <center> Please add the model or fix your model path.")
272
+ continue
273
+ for (name, title, author, cover, model_version, vc_fn) in models:
274
+ with gr.TabItem(name):
275
+ with gr.Row():
276
+ gr.Markdown(
277
+ '<div align="center">'
278
+ f'<div>{title}</div>\n'+
279
+ f'<div>RVC {model_version} Model</div>\n'+
280
+ (f'<div>Model author: {author}</div>' if author else "")+
281
+ (f'<img style="width:auto;height:300px;" src="file/{cover}">' if cover else "")+
282
+ '</div>'
283
+ )
284
+ with gr.Row():
285
+ if spaces is False:
286
+ with gr.TabItem("Input"):
287
+ with gr.Row():
288
+ with gr.Column():
289
+ vc_audio_mode = gr.Dropdown(label="Input voice", choices=audio_mode, allow_custom_value=False, value="Upload audio")
290
+ # Input
291
+ vc_input = gr.Textbox(label="Input audio path", visible=False)
292
+ # Upload
293
+ vc_upload = gr.Audio(label="Upload audio file", sources=["upload", "microphone"], visible=True, interactive=True)
294
+ # Youtube
295
+ vc_download_audio = gr.Dropdown(label="Provider", choices=["Youtube"], allow_custom_value=False, visible=False, value="Youtube", info="Select provider (Default: Youtube)")
296
+ vc_link = gr.Textbox(label="Youtube URL", visible=False, info="Example: https://www.youtube.com/watch?v=Nc0sB1Bmf-A", placeholder="https://www.youtube.com/watch?v=...")
297
+ vc_log_yt = gr.Textbox(label="Output Information", visible=False, interactive=False)
298
+ vc_download_button = gr.Button("Download Audio", variant="primary", visible=False)
299
+ vc_audio_preview = gr.Audio(label="Audio Preview", visible=False)
300
+ # TTS
301
+ tts_text = gr.Textbox(label="TTS text", info="Text to speech input", visible=False)
302
+ tts_voice = gr.Dropdown(label="Edge-tts speaker", choices=voices, visible=False, allow_custom_value=False, value="en-US-AnaNeural-Female")
303
+ with gr.Column():
304
+ vc_split_model = gr.Dropdown(label="Splitter Model", choices=["hdemucs_mmi", "htdemucs", "htdemucs_ft", "mdx", "mdx_q", "mdx_extra_q"], allow_custom_value=False, visible=False, value="htdemucs", info="Select the splitter model (Default: htdemucs)")
305
+ vc_split_log = gr.Textbox(label="Output Information", visible=False, interactive=False)
306
+ vc_split = gr.Button("Split Audio", variant="primary", visible=False)
307
+ vc_vocal_preview = gr.Audio(label="Vocal Preview", visible=False)
308
+ vc_inst_preview = gr.Audio(label="Instrumental Preview", visible=False)
309
+ with gr.TabItem("Convert"):
310
+ with gr.Row():
311
+ with gr.Column():
312
+ vc_transform0 = gr.Number(label="Transpose", value=0, info='Type "12" to change from male to female voice. Type "-12" to change female to male voice')
313
+ f0method0 = gr.Radio(
314
+ label="Pitch extraction algorithm",
315
+ info=f0method_info,
316
+ choices=f0method_mode,
317
+ value="pm",
318
+ interactive=True
319
+ )
320
+ index_rate1 = gr.Slider(
321
+ minimum=0,
322
+ maximum=1,
323
+ label="Retrieval feature ratio",
324
+ info="(Default: 0.7)",
325
+ value=0.7,
326
+ interactive=True,
327
+ )
328
+ filter_radius0 = gr.Slider(
329
+ minimum=0,
330
+ maximum=7,
331
+ label="Apply Median Filtering",
332
+ info="The value represents the filter radius and can reduce breathiness.",
333
+ value=3,
334
+ step=1,
335
+ interactive=True,
336
+ )
337
+ resample_sr0 = gr.Slider(
338
+ minimum=0,
339
+ maximum=48000,
340
+ label="Resample the output audio",
341
+ info="Resample the output audio in post-processing to the final sample rate. Set to 0 for no resampling",
342
+ value=0,
343
+ step=1,
344
+ interactive=True,
345
+ )
346
+ rms_mix_rate0 = gr.Slider(
347
+ minimum=0,
348
+ maximum=1,
349
+ label="Volume Envelope",
350
+ info="Use the volume envelope of the input to replace or mix with the volume envelope of the output. The closer the ratio is to 1, the more the output envelope is used",
351
+ value=1,
352
+ interactive=True,
353
+ )
354
+ protect0 = gr.Slider(
355
+ minimum=0,
356
+ maximum=0.5,
357
+ label="Voice Protection",
358
+ info="Protect voiceless consonants and breath sounds to prevent artifacts such as tearing in electronic music. Set to 0.5 to disable. Decrease the value to increase protection, but it may reduce indexing accuracy",
359
+ value=0.5,
360
+ step=0.01,
361
+ interactive=True,
362
+ )
363
+ with gr.Column():
364
+ vc_log = gr.Textbox(label="Output Information", interactive=False)
365
+ vc_output = gr.Audio(label="Output Audio", interactive=False)
366
+ vc_convert = gr.Button("Convert", variant="primary")
367
+ vc_vocal_volume = gr.Slider(
368
+ minimum=0,
369
+ maximum=10,
370
+ label="Vocal volume",
371
+ value=1,
372
+ interactive=True,
373
+ step=1,
374
+ info="Adjust vocal volume (Default: 1}",
375
+ visible=False
376
+ )
377
+ vc_inst_volume = gr.Slider(
378
+ minimum=0,
379
+ maximum=10,
380
+ label="Instrument volume",
381
+ value=1,
382
+ interactive=True,
383
+ step=1,
384
+ info="Adjust instrument volume (Default: 1}",
385
+ visible=False
386
+ )
387
+ vc_combined_output = gr.Audio(label="Output Combined Audio", visible=False)
388
+ vc_combine = gr.Button("Combine",variant="primary", visible=False)
389
+ else:
390
+ with gr.Column():
391
+ vc_audio_mode = gr.Dropdown(label="Input voice", choices=audio_mode, allow_custom_value=False, value="Upload audio")
392
+ # Input
393
+ vc_input = gr.Textbox(label="Input audio path", visible=False)
394
+ # Upload
395
+ vc_upload = gr.Audio(label="Upload audio file", sources=["upload", "microphone"], visible=True, interactive=True)
396
+ # Youtube
397
+ vc_download_audio = gr.Dropdown(label="Provider", choices=["Youtube"], allow_custom_value=False, visible=False, value="Youtube", info="Select provider (Default: Youtube)")
398
+ vc_link = gr.Textbox(label="Youtube URL", visible=False, info="Example: https://www.youtube.com/watch?v=Nc0sB1Bmf-A", placeholder="https://www.youtube.com/watch?v=...")
399
+ vc_log_yt = gr.Textbox(label="Output Information", visible=False, interactive=False)
400
+ vc_download_button = gr.Button("Download Audio", variant="primary", visible=False)
401
+ vc_audio_preview = gr.Audio(label="Audio Preview", visible=False)
402
+ # Splitter
403
+ vc_split_model = gr.Dropdown(label="Splitter Model", choices=["hdemucs_mmi", "htdemucs", "htdemucs_ft", "mdx", "mdx_q", "mdx_extra_q"], allow_custom_value=False, visible=False, value="htdemucs", info="Select the splitter model (Default: htdemucs)")
404
+ vc_split_log = gr.Textbox(label="Output Information", visible=False, interactive=False)
405
+ vc_split = gr.Button("Split Audio", variant="primary", visible=False)
406
+ vc_vocal_preview = gr.Audio(label="Vocal Preview", visible=False)
407
+ vc_inst_preview = gr.Audio(label="Instrumental Preview", visible=False)
408
+ # TTS
409
+ tts_text = gr.Textbox(label="TTS text", info="Text to speech input", visible=False)
410
+ tts_voice = gr.Dropdown(label="Edge-tts speaker", choices=voices, visible=False, allow_custom_value=False, value="en-US-AnaNeural-Female")
411
+ with gr.Column():
412
+ vc_transform0 = gr.Number(label="Transpose", value=0, info='Type "12" to change from male to female voice. Type "-12" to change female to male voice')
413
+ f0method0 = gr.Radio(
414
+ label="Pitch extraction algorithm",
415
+ info=f0method_info,
416
+ choices=f0method_mode,
417
+ value="pm",
418
+ interactive=True
419
+ )
420
+ index_rate1 = gr.Slider(
421
+ minimum=0,
422
+ maximum=1,
423
+ label="Retrieval feature ratio",
424
+ info="(Default: 0.7)",
425
+ value=0.7,
426
+ interactive=True,
427
+ )
428
+ filter_radius0 = gr.Slider(
429
+ minimum=0,
430
+ maximum=7,
431
+ label="Apply Median Filtering",
432
+ info="The value represents the filter radius and can reduce breathiness.",
433
+ value=3,
434
+ step=1,
435
+ interactive=True,
436
+ )
437
+ resample_sr0 = gr.Slider(
438
+ minimum=0,
439
+ maximum=48000,
440
+ label="Resample the output audio",
441
+ info="Resample the output audio in post-processing to the final sample rate. Set to 0 for no resampling",
442
+ value=0,
443
+ step=1,
444
+ interactive=True,
445
+ )
446
+ rms_mix_rate0 = gr.Slider(
447
+ minimum=0,
448
+ maximum=1,
449
+ label="Volume Envelope",
450
+ info="Use the volume envelope of the input to replace or mix with the volume envelope of the output. The closer the ratio is to 1, the more the output envelope is used",
451
+ value=1,
452
+ interactive=True,
453
+ )
454
+ protect0 = gr.Slider(
455
+ minimum=0,
456
+ maximum=0.5,
457
+ label="Voice Protection",
458
+ info="Protect voiceless consonants and breath sounds to prevent artifacts such as tearing in electronic music. Set to 0.5 to disable. Decrease the value to increase protection, but it may reduce indexing accuracy",
459
+ value=0.5,
460
+ step=0.01,
461
+ interactive=True,
462
+ )
463
+ with gr.Column():
464
+ vc_log = gr.Textbox(label="Output Information", interactive=False)
465
+ vc_output = gr.Audio(label="Output Audio", interactive=False)
466
+ vc_convert = gr.Button("Convert", variant="primary")
467
+ vc_vocal_volume = gr.Slider(
468
+ minimum=0,
469
+ maximum=10,
470
+ label="Vocal volume",
471
+ value=1,
472
+ interactive=True,
473
+ step=1,
474
+ info="Adjust vocal volume (Default: 1}",
475
+ visible=False
476
+ )
477
+ vc_inst_volume = gr.Slider(
478
+ minimum=0,
479
+ maximum=10,
480
+ label="Instrument volume",
481
+ value=1,
482
+ interactive=True,
483
+ step=1,
484
+ info="Adjust instrument volume (Default: 1}",
485
+ visible=False
486
+ )
487
+ vc_combined_output = gr.Audio(label="Output Combined Audio", visible=False)
488
+ vc_combine = gr.Button("Combine",variant="primary", visible=False)
489
+ vc_convert.click(
490
+ fn=vc_fn,
491
+ inputs=[
492
+ vc_audio_mode,
493
+ vc_input,
494
+ vc_upload,
495
+ tts_text,
496
+ tts_voice,
497
+ vc_transform0,
498
+ f0method0,
499
+ index_rate1,
500
+ filter_radius0,
501
+ resample_sr0,
502
+ rms_mix_rate0,
503
+ protect0,
504
+ ],
505
+ outputs=[vc_log ,vc_output]
506
+ )
507
+ vc_download_button.click(
508
+ fn=download_audio,
509
+ inputs=[vc_link, vc_download_audio],
510
+ outputs=[vc_audio_preview, vc_log_yt]
511
+ )
512
+ vc_split.click(
513
+ fn=cut_vocal_and_inst,
514
+ inputs=[vc_split_model],
515
+ outputs=[vc_split_log, vc_vocal_preview, vc_inst_preview, vc_input]
516
+ )
517
+ vc_combine.click(
518
+ fn=combine_vocal_and_inst,
519
+ inputs=[vc_output, vc_vocal_volume, vc_inst_volume, vc_split_model],
520
+ outputs=[vc_combined_output]
521
+ )
522
+ vc_audio_mode.change(
523
+ fn=change_audio_mode,
524
+ inputs=[vc_audio_mode],
525
+ outputs=[
526
+ vc_input,
527
+ vc_upload,
528
+ vc_download_audio,
529
+ vc_link,
530
+ vc_log_yt,
531
+ vc_download_button,
532
+ vc_split_model,
533
+ vc_split_log,
534
+ vc_split,
535
+ vc_audio_preview,
536
+ vc_vocal_preview,
537
+ vc_inst_preview,
538
+ vc_vocal_volume,
539
+ vc_inst_volume,
540
+ vc_combined_output,
541
+ vc_combine,
542
+ tts_text,
543
+ tts_voice
544
+ ]
545
+ )
546
+ app.queue(
547
+ max_size=20,
548
+ api_open=config.api,
549
+ ).launch(
550
+ share=config.share,
551
+ max_threads=1,
552
+ allowed_paths=["weights"]
553
+ )