Update demo.py
Browse files
demo.py
CHANGED
|
@@ -1,439 +1,439 @@
|
|
| 1 |
-
from original import *
|
| 2 |
-
import shutil, glob
|
| 3 |
-
from easyfuncs import download_from_url, CachedModels
|
| 4 |
-
os.makedirs("dataset",exist_ok=True)
|
| 5 |
-
model_library = CachedModels()
|
| 6 |
-
|
| 7 |
-
with gr.Blocks(title="
|
| 8 |
-
with gr.Row():
|
| 9 |
-
gr.
|
| 10 |
-
with gr.Tabs():
|
| 11 |
-
with gr.TabItem("Inference"):
|
| 12 |
-
with gr.Row():
|
| 13 |
-
voice_model = gr.Dropdown(label="Model Voice", choices=sorted(names), value=lambda:sorted(names)[0] if len(sorted(names)) > 0 else '', interactive=True)
|
| 14 |
-
refresh_button = gr.Button("Refresh", variant="primary")
|
| 15 |
-
spk_item = gr.Slider(
|
| 16 |
-
minimum=0,
|
| 17 |
-
maximum=2333,
|
| 18 |
-
step=1,
|
| 19 |
-
label="Speaker ID",
|
| 20 |
-
value=0,
|
| 21 |
-
visible=False,
|
| 22 |
-
interactive=True,
|
| 23 |
-
)
|
| 24 |
-
vc_transform0 = gr.Number(
|
| 25 |
-
label="Pitch",
|
| 26 |
-
value=0
|
| 27 |
-
)
|
| 28 |
-
but0 = gr.Button(value="Convert", variant="primary")
|
| 29 |
-
with gr.Row():
|
| 30 |
-
with gr.Column():
|
| 31 |
-
with gr.Row():
|
| 32 |
-
dropbox = gr.File(label="Drop your audio here & hit the Reload button.")
|
| 33 |
-
with gr.Row():
|
| 34 |
-
record_button=gr.Audio(source="microphone", label="OR Record audio.", type="filepath")
|
| 35 |
-
with gr.Row():
|
| 36 |
-
paths_for_files = lambda path:[os.path.abspath(os.path.join(path, f)) for f in os.listdir(path) if os.path.splitext(f)[1].lower() in ('.mp3', '.wav', '.flac', '.ogg')]
|
| 37 |
-
input_audio0 = gr.Dropdown(
|
| 38 |
-
label="Input Path",
|
| 39 |
-
value=paths_for_files('audios')[0] if len(paths_for_files('audios')) > 0 else '',
|
| 40 |
-
choices=paths_for_files('audios'), # Only show absolute paths for audio files ending in .mp3, .wav, .flac or .ogg
|
| 41 |
-
allow_custom_value=True
|
| 42 |
-
)
|
| 43 |
-
with gr.Row():
|
| 44 |
-
audio_player = gr.Audio()
|
| 45 |
-
input_audio0.change(
|
| 46 |
-
inputs=[input_audio0],
|
| 47 |
-
outputs=[audio_player],
|
| 48 |
-
fn=lambda path: {"value":path,"__type__":"update"} if os.path.exists(path) else None
|
| 49 |
-
)
|
| 50 |
-
record_button.stop_recording(
|
| 51 |
-
fn=lambda audio:audio, #TODO save wav lambda
|
| 52 |
-
inputs=[record_button],
|
| 53 |
-
outputs=[input_audio0])
|
| 54 |
-
dropbox.upload(
|
| 55 |
-
fn=lambda audio:audio.name,
|
| 56 |
-
inputs=[dropbox],
|
| 57 |
-
outputs=[input_audio0])
|
| 58 |
-
with gr.Column():
|
| 59 |
-
with gr.Accordion("Change Index", open=False):
|
| 60 |
-
file_index2 = gr.Dropdown(
|
| 61 |
-
label="Change Index",
|
| 62 |
-
choices=sorted(index_paths),
|
| 63 |
-
interactive=True,
|
| 64 |
-
value=sorted(index_paths)[0] if len(sorted(index_paths)) > 0 else ''
|
| 65 |
-
)
|
| 66 |
-
index_rate1 = gr.Slider(
|
| 67 |
-
minimum=0,
|
| 68 |
-
maximum=1,
|
| 69 |
-
label="Index Strength",
|
| 70 |
-
value=0.5,
|
| 71 |
-
interactive=True,
|
| 72 |
-
)
|
| 73 |
-
vc_output2 = gr.Audio(label="Output")
|
| 74 |
-
with gr.Accordion("General Settings", open=False):
|
| 75 |
-
f0method0 = gr.Radio(
|
| 76 |
-
label="Method",
|
| 77 |
-
choices=["pm", "harvest", "crepe", "rmvpe"]
|
| 78 |
-
if config.dml == False
|
| 79 |
-
else ["pm", "harvest", "rmvpe"],
|
| 80 |
-
value="rmvpe",
|
| 81 |
-
interactive=True,
|
| 82 |
-
)
|
| 83 |
-
filter_radius0 = gr.Slider(
|
| 84 |
-
minimum=0,
|
| 85 |
-
maximum=7,
|
| 86 |
-
label="Breathiness Reduction (Harvest only)",
|
| 87 |
-
value=3,
|
| 88 |
-
step=1,
|
| 89 |
-
interactive=True,
|
| 90 |
-
)
|
| 91 |
-
resample_sr0 = gr.Slider(
|
| 92 |
-
minimum=0,
|
| 93 |
-
maximum=48000,
|
| 94 |
-
label="Resample",
|
| 95 |
-
value=0,
|
| 96 |
-
step=1,
|
| 97 |
-
interactive=True,
|
| 98 |
-
visible=False
|
| 99 |
-
)
|
| 100 |
-
rms_mix_rate0 = gr.Slider(
|
| 101 |
-
minimum=0,
|
| 102 |
-
maximum=1,
|
| 103 |
-
label="Volume Normalization",
|
| 104 |
-
value=0,
|
| 105 |
-
interactive=True,
|
| 106 |
-
)
|
| 107 |
-
protect0 = gr.Slider(
|
| 108 |
-
minimum=0,
|
| 109 |
-
maximum=0.5,
|
| 110 |
-
label="Breathiness Protection (0 is enabled, 0.5 is disabled)",
|
| 111 |
-
value=0.33,
|
| 112 |
-
step=0.01,
|
| 113 |
-
interactive=True,
|
| 114 |
-
)
|
| 115 |
-
if voice_model != None: vc.get_vc(voice_model.value,protect0,protect0)
|
| 116 |
-
file_index1 = gr.Textbox(
|
| 117 |
-
label="Index Path",
|
| 118 |
-
interactive=True,
|
| 119 |
-
visible=False#Not used here
|
| 120 |
-
)
|
| 121 |
-
refresh_button.click(
|
| 122 |
-
fn=change_choices,
|
| 123 |
-
inputs=[],
|
| 124 |
-
outputs=[voice_model, file_index2],
|
| 125 |
-
api_name="infer_refresh",
|
| 126 |
-
)
|
| 127 |
-
refresh_button.click(
|
| 128 |
-
fn=lambda:{"choices":paths_for_files('audios'),"__type__":"update"}, #TODO check if properly returns a sorted list of audio files in the 'audios' folder that have the extensions '.wav', '.mp3', '.ogg', or '.flac'
|
| 129 |
-
inputs=[],
|
| 130 |
-
outputs = [input_audio0],
|
| 131 |
-
)
|
| 132 |
-
refresh_button.click(
|
| 133 |
-
fn=lambda:{"value":paths_for_files('audios')[0],"__type__":"update"} if len(paths_for_files('audios')) > 0 else {"value":"","__type__":"update"}, #TODO check if properly returns a sorted list of audio files in the 'audios' folder that have the extensions '.wav', '.mp3', '.ogg', or '.flac'
|
| 134 |
-
inputs=[],
|
| 135 |
-
outputs = [input_audio0],
|
| 136 |
-
)
|
| 137 |
-
with gr.Row():
|
| 138 |
-
f0_file = gr.File(label="F0 Path", visible=False)
|
| 139 |
-
with gr.Row():
|
| 140 |
-
vc_output1 = gr.Textbox(label="Information", placeholder="Welcome!",visible=False)
|
| 141 |
-
but0.click(
|
| 142 |
-
vc.vc_single,
|
| 143 |
-
[
|
| 144 |
-
spk_item,
|
| 145 |
-
input_audio0,
|
| 146 |
-
vc_transform0,
|
| 147 |
-
f0_file,
|
| 148 |
-
f0method0,
|
| 149 |
-
file_index1,
|
| 150 |
-
file_index2,
|
| 151 |
-
index_rate1,
|
| 152 |
-
filter_radius0,
|
| 153 |
-
resample_sr0,
|
| 154 |
-
rms_mix_rate0,
|
| 155 |
-
protect0,
|
| 156 |
-
],
|
| 157 |
-
[vc_output1, vc_output2],
|
| 158 |
-
api_name="infer_convert",
|
| 159 |
-
)
|
| 160 |
-
voice_model.change(
|
| 161 |
-
fn=vc.get_vc,
|
| 162 |
-
inputs=[voice_model, protect0, protect0],
|
| 163 |
-
outputs=[spk_item, protect0, protect0, file_index2, file_index2],
|
| 164 |
-
api_name="infer_change_voice",
|
| 165 |
-
)
|
| 166 |
-
with gr.TabItem("Download Models"):
|
| 167 |
-
with gr.Row():
|
| 168 |
-
url_input = gr.Textbox(label="URL to model", value="",placeholder="https://...", scale=6)
|
| 169 |
-
name_output = gr.Textbox(label="Save as", value="",placeholder="MyModel",scale=2)
|
| 170 |
-
url_download = gr.Button(value="Download Model",scale=2)
|
| 171 |
-
url_download.click(
|
| 172 |
-
inputs=[url_input,name_output],
|
| 173 |
-
outputs=[url_input],
|
| 174 |
-
fn=download_from_url,
|
| 175 |
-
)
|
| 176 |
-
with gr.Row():
|
| 177 |
-
model_browser = gr.Dropdown(choices=list(model_library.models.keys()),label="OR Search Models (Quality UNKNOWN)",scale=5)
|
| 178 |
-
download_from_browser = gr.Button(value="Get",scale=2)
|
| 179 |
-
download_from_browser.click(
|
| 180 |
-
inputs=[model_browser],
|
| 181 |
-
outputs=[model_browser],
|
| 182 |
-
fn=lambda model: download_from_url(model_library.models[model],model),
|
| 183 |
-
)
|
| 184 |
-
with gr.TabItem("Train"):
|
| 185 |
-
with gr.Row():
|
| 186 |
-
with gr.Column():
|
| 187 |
-
training_name = gr.Textbox(label="Name your model", value="My-Voice",placeholder="My-Voice")
|
| 188 |
-
np7 = gr.Slider(
|
| 189 |
-
minimum=0,
|
| 190 |
-
maximum=config.n_cpu,
|
| 191 |
-
step=1,
|
| 192 |
-
label="Number of CPU processes used to extract pitch features",
|
| 193 |
-
value=int(np.ceil(config.n_cpu / 1.5)),
|
| 194 |
-
interactive=True,
|
| 195 |
-
)
|
| 196 |
-
sr2 = gr.Radio(
|
| 197 |
-
label="Sampling Rate",
|
| 198 |
-
choices=["40k", "32k"],
|
| 199 |
-
value="32k",
|
| 200 |
-
interactive=True,
|
| 201 |
-
visible=False
|
| 202 |
-
)
|
| 203 |
-
if_f0_3 = gr.Radio(
|
| 204 |
-
label="Will your model be used for singing? If not, you can ignore this.",
|
| 205 |
-
choices=[True, False],
|
| 206 |
-
value=True,
|
| 207 |
-
interactive=True,
|
| 208 |
-
visible=False
|
| 209 |
-
)
|
| 210 |
-
version19 = gr.Radio(
|
| 211 |
-
label="Version",
|
| 212 |
-
choices=["v1", "v2"],
|
| 213 |
-
value="v2",
|
| 214 |
-
interactive=True,
|
| 215 |
-
visible=False,
|
| 216 |
-
)
|
| 217 |
-
dataset_folder = gr.Textbox(
|
| 218 |
-
label="dataset folder", value='dataset'
|
| 219 |
-
)
|
| 220 |
-
easy_uploader = gr.Files(label="Drop your audio files here",file_types=['audio'])
|
| 221 |
-
but1 = gr.Button("1. Process", variant="primary")
|
| 222 |
-
info1 = gr.Textbox(label="Information", value="",visible=True)
|
| 223 |
-
easy_uploader.upload(inputs=[dataset_folder],outputs=[],fn=lambda folder:os.makedirs(folder,exist_ok=True))
|
| 224 |
-
easy_uploader.upload(
|
| 225 |
-
fn=lambda files,folder: [shutil.copy2(f.name,os.path.join(folder,os.path.split(f.name)[1])) for f in files] if folder != "" else gr.Warning('Please enter a folder name for your dataset'),
|
| 226 |
-
inputs=[easy_uploader, dataset_folder],
|
| 227 |
-
outputs=[])
|
| 228 |
-
gpus6 = gr.Textbox(
|
| 229 |
-
label="Enter the GPU numbers to use separated by -, (e.g. 0-1-2)",
|
| 230 |
-
value=gpus,
|
| 231 |
-
interactive=True,
|
| 232 |
-
visible=F0GPUVisible,
|
| 233 |
-
)
|
| 234 |
-
gpu_info9 = gr.Textbox(
|
| 235 |
-
label="GPU Info", value=gpu_info, visible=F0GPUVisible
|
| 236 |
-
)
|
| 237 |
-
spk_id5 = gr.Slider(
|
| 238 |
-
minimum=0,
|
| 239 |
-
maximum=4,
|
| 240 |
-
step=1,
|
| 241 |
-
label="Speaker ID",
|
| 242 |
-
value=0,
|
| 243 |
-
interactive=True,
|
| 244 |
-
visible=False
|
| 245 |
-
)
|
| 246 |
-
but1.click(
|
| 247 |
-
preprocess_dataset,
|
| 248 |
-
[dataset_folder, training_name, sr2, np7],
|
| 249 |
-
[info1],
|
| 250 |
-
api_name="train_preprocess",
|
| 251 |
-
)
|
| 252 |
-
with gr.Column():
|
| 253 |
-
f0method8 = gr.Radio(
|
| 254 |
-
label="F0 extraction method",
|
| 255 |
-
choices=["pm", "harvest", "dio", "rmvpe", "rmvpe_gpu"],
|
| 256 |
-
value="rmvpe_gpu",
|
| 257 |
-
interactive=True,
|
| 258 |
-
)
|
| 259 |
-
gpus_rmvpe = gr.Textbox(
|
| 260 |
-
label="GPU numbers to use separated by -, (e.g. 0-1-2)",
|
| 261 |
-
value="%s-%s" % (gpus, gpus),
|
| 262 |
-
interactive=True,
|
| 263 |
-
visible=F0GPUVisible,
|
| 264 |
-
)
|
| 265 |
-
but2 = gr.Button("2. Extract Features", variant="primary")
|
| 266 |
-
info2 = gr.Textbox(label="Information", value="", max_lines=8)
|
| 267 |
-
f0method8.change(
|
| 268 |
-
fn=change_f0_method,
|
| 269 |
-
inputs=[f0method8],
|
| 270 |
-
outputs=[gpus_rmvpe],
|
| 271 |
-
)
|
| 272 |
-
but2.click(
|
| 273 |
-
extract_f0_feature,
|
| 274 |
-
[
|
| 275 |
-
gpus6,
|
| 276 |
-
np7,
|
| 277 |
-
f0method8,
|
| 278 |
-
if_f0_3,
|
| 279 |
-
training_name,
|
| 280 |
-
version19,
|
| 281 |
-
gpus_rmvpe,
|
| 282 |
-
],
|
| 283 |
-
[info2],
|
| 284 |
-
api_name="train_extract_f0_feature",
|
| 285 |
-
)
|
| 286 |
-
with gr.Column():
|
| 287 |
-
total_epoch11 = gr.Slider(
|
| 288 |
-
minimum=2,
|
| 289 |
-
maximum=1000,
|
| 290 |
-
step=1,
|
| 291 |
-
label="Epochs (more epochs may improve quality but takes longer)",
|
| 292 |
-
value=150,
|
| 293 |
-
interactive=True,
|
| 294 |
-
)
|
| 295 |
-
but4 = gr.Button("3. Train Index", variant="primary")
|
| 296 |
-
but3 = gr.Button("4. Train Model", variant="primary")
|
| 297 |
-
info3 = gr.Textbox(label="Information", value="", max_lines=10)
|
| 298 |
-
with gr.Accordion(label="General Settings", open=False):
|
| 299 |
-
gpus16 = gr.Textbox(
|
| 300 |
-
label="GPUs separated by -, (e.g. 0-1-2)",
|
| 301 |
-
value="0",
|
| 302 |
-
interactive=True,
|
| 303 |
-
visible=True
|
| 304 |
-
)
|
| 305 |
-
save_epoch10 = gr.Slider(
|
| 306 |
-
minimum=1,
|
| 307 |
-
maximum=50,
|
| 308 |
-
step=1,
|
| 309 |
-
label="Weight Saving Frequency",
|
| 310 |
-
value=25,
|
| 311 |
-
interactive=True,
|
| 312 |
-
)
|
| 313 |
-
batch_size12 = gr.Slider(
|
| 314 |
-
minimum=1,
|
| 315 |
-
maximum=40,
|
| 316 |
-
step=1,
|
| 317 |
-
label="Batch Size",
|
| 318 |
-
value=default_batch_size,
|
| 319 |
-
interactive=True,
|
| 320 |
-
)
|
| 321 |
-
if_save_latest13 = gr.Radio(
|
| 322 |
-
label="Only save the latest model",
|
| 323 |
-
choices=["yes", "no"],
|
| 324 |
-
value="yes",
|
| 325 |
-
interactive=True,
|
| 326 |
-
visible=False
|
| 327 |
-
)
|
| 328 |
-
if_cache_gpu17 = gr.Radio(
|
| 329 |
-
label="If your dataset is UNDER 10 minutes, cache it to train faster",
|
| 330 |
-
choices=["yes", "no"],
|
| 331 |
-
value="no",
|
| 332 |
-
interactive=True,
|
| 333 |
-
)
|
| 334 |
-
if_save_every_weights18 = gr.Radio(
|
| 335 |
-
label="Save small model at every save point",
|
| 336 |
-
choices=["yes", "no"],
|
| 337 |
-
value="yes",
|
| 338 |
-
interactive=True,
|
| 339 |
-
)
|
| 340 |
-
with gr.Accordion(label="Change pretrains", open=False):
|
| 341 |
-
pretrained = lambda sr, letter: [os.path.abspath(os.path.join('assets/pretrained_v2', file)) for file in os.listdir('assets/pretrained_v2') if file.endswith('.pth') and sr in file and letter in file]
|
| 342 |
-
pretrained_G14 = gr.Dropdown(
|
| 343 |
-
label="pretrained G",
|
| 344 |
-
# Get a list of all pretrained G model files in assets/pretrained_v2 that end with .pth
|
| 345 |
-
choices = pretrained(sr2.value, 'G'),
|
| 346 |
-
value=pretrained(sr2.value, 'G')[0] if len(pretrained(sr2.value, 'G')) > 0 else '',
|
| 347 |
-
interactive=True,
|
| 348 |
-
visible=True
|
| 349 |
-
)
|
| 350 |
-
pretrained_D15 = gr.Dropdown(
|
| 351 |
-
label="pretrained D",
|
| 352 |
-
choices = pretrained(sr2.value, 'D'),
|
| 353 |
-
value= pretrained(sr2.value, 'D')[0] if len(pretrained(sr2.value, 'G')) > 0 else '',
|
| 354 |
-
visible=True,
|
| 355 |
-
interactive=True
|
| 356 |
-
)
|
| 357 |
-
with gr.Row():
|
| 358 |
-
download_model = gr.Button('5.Download Model')
|
| 359 |
-
with gr.Row():
|
| 360 |
-
model_files = gr.Files(label='Your Model and Index file can be downloaded here:')
|
| 361 |
-
download_model.click(
|
| 362 |
-
fn=lambda name: os.listdir(f'assets/weights/{name}') + glob.glob(f'logs/{name.split(".")[0]}/added_*.index'),
|
| 363 |
-
inputs=[training_name],
|
| 364 |
-
outputs=[model_files, info3])
|
| 365 |
-
with gr.Row():
|
| 366 |
-
sr2.change(
|
| 367 |
-
change_sr2,
|
| 368 |
-
[sr2, if_f0_3, version19],
|
| 369 |
-
[pretrained_G14, pretrained_D15],
|
| 370 |
-
)
|
| 371 |
-
version19.change(
|
| 372 |
-
change_version19,
|
| 373 |
-
[sr2, if_f0_3, version19],
|
| 374 |
-
[pretrained_G14, pretrained_D15, sr2],
|
| 375 |
-
)
|
| 376 |
-
if_f0_3.change(
|
| 377 |
-
change_f0,
|
| 378 |
-
[if_f0_3, sr2, version19],
|
| 379 |
-
[f0method8, pretrained_G14, pretrained_D15],
|
| 380 |
-
)
|
| 381 |
-
with gr.Row():
|
| 382 |
-
but5 = gr.Button("1 Click Training", variant="primary", visible=False)
|
| 383 |
-
but3.click(
|
| 384 |
-
click_train,
|
| 385 |
-
[
|
| 386 |
-
training_name,
|
| 387 |
-
sr2,
|
| 388 |
-
if_f0_3,
|
| 389 |
-
spk_id5,
|
| 390 |
-
save_epoch10,
|
| 391 |
-
total_epoch11,
|
| 392 |
-
batch_size12,
|
| 393 |
-
if_save_latest13,
|
| 394 |
-
pretrained_G14,
|
| 395 |
-
pretrained_D15,
|
| 396 |
-
gpus16,
|
| 397 |
-
if_cache_gpu17,
|
| 398 |
-
if_save_every_weights18,
|
| 399 |
-
version19,
|
| 400 |
-
],
|
| 401 |
-
info3,
|
| 402 |
-
api_name="train_start",
|
| 403 |
-
)
|
| 404 |
-
but4.click(train_index, [training_name, version19], info3)
|
| 405 |
-
but5.click(
|
| 406 |
-
train1key,
|
| 407 |
-
[
|
| 408 |
-
training_name,
|
| 409 |
-
sr2,
|
| 410 |
-
if_f0_3,
|
| 411 |
-
dataset_folder,
|
| 412 |
-
spk_id5,
|
| 413 |
-
np7,
|
| 414 |
-
f0method8,
|
| 415 |
-
save_epoch10,
|
| 416 |
-
total_epoch11,
|
| 417 |
-
batch_size12,
|
| 418 |
-
if_save_latest13,
|
| 419 |
-
pretrained_G14,
|
| 420 |
-
pretrained_D15,
|
| 421 |
-
gpus16,
|
| 422 |
-
if_cache_gpu17,
|
| 423 |
-
if_save_every_weights18,
|
| 424 |
-
version19,
|
| 425 |
-
gpus_rmvpe,
|
| 426 |
-
],
|
| 427 |
-
info3,
|
| 428 |
-
api_name="train_start_all",
|
| 429 |
-
)
|
| 430 |
-
|
| 431 |
-
if config.iscolab:
|
| 432 |
-
app.queue(concurrency_count=511, max_size=1022).launch(share=True)
|
| 433 |
-
else:
|
| 434 |
-
app.queue(concurrency_count=511, max_size=1022).launch(
|
| 435 |
-
server_name="0.0.0.0",
|
| 436 |
-
inbrowser=not config.noautoopen,
|
| 437 |
-
server_port=config.listen_port,
|
| 438 |
-
quiet=True,
|
| 439 |
-
)
|
|
|
|
| 1 |
+
from original import *
|
| 2 |
+
import shutil, glob
|
| 3 |
+
from easyfuncs import download_from_url, CachedModels
|
| 4 |
+
os.makedirs("dataset",exist_ok=True)
|
| 5 |
+
model_library = CachedModels()
|
| 6 |
+
|
| 7 |
+
with gr.Blocks(title="easygui v2",theme=gr.themes.Base(primary_hue="rose",neutral_hue="zinc")) as app:
|
| 8 |
+
with gr.Row():
|
| 9 |
+
gr.Markdown("# EasyGUI V2")
|
| 10 |
+
with gr.Tabs():
|
| 11 |
+
with gr.TabItem("Inference"):
|
| 12 |
+
with gr.Row():
|
| 13 |
+
voice_model = gr.Dropdown(label="Model Voice", choices=sorted(names), value=lambda:sorted(names)[0] if len(sorted(names)) > 0 else '', interactive=True)
|
| 14 |
+
refresh_button = gr.Button("Refresh", variant="primary")
|
| 15 |
+
spk_item = gr.Slider(
|
| 16 |
+
minimum=0,
|
| 17 |
+
maximum=2333,
|
| 18 |
+
step=1,
|
| 19 |
+
label="Speaker ID",
|
| 20 |
+
value=0,
|
| 21 |
+
visible=False,
|
| 22 |
+
interactive=True,
|
| 23 |
+
)
|
| 24 |
+
vc_transform0 = gr.Number(
|
| 25 |
+
label="Pitch",
|
| 26 |
+
value=0
|
| 27 |
+
)
|
| 28 |
+
but0 = gr.Button(value="Convert", variant="primary")
|
| 29 |
+
with gr.Row():
|
| 30 |
+
with gr.Column():
|
| 31 |
+
with gr.Row():
|
| 32 |
+
dropbox = gr.File(label="Drop your audio here & hit the Reload button.")
|
| 33 |
+
with gr.Row():
|
| 34 |
+
record_button=gr.Audio(source="microphone", label="OR Record audio.", type="filepath")
|
| 35 |
+
with gr.Row():
|
| 36 |
+
paths_for_files = lambda path:[os.path.abspath(os.path.join(path, f)) for f in os.listdir(path) if os.path.splitext(f)[1].lower() in ('.mp3', '.wav', '.flac', '.ogg')]
|
| 37 |
+
input_audio0 = gr.Dropdown(
|
| 38 |
+
label="Input Path",
|
| 39 |
+
value=paths_for_files('audios')[0] if len(paths_for_files('audios')) > 0 else '',
|
| 40 |
+
choices=paths_for_files('audios'), # Only show absolute paths for audio files ending in .mp3, .wav, .flac or .ogg
|
| 41 |
+
allow_custom_value=True
|
| 42 |
+
)
|
| 43 |
+
with gr.Row():
|
| 44 |
+
audio_player = gr.Audio()
|
| 45 |
+
input_audio0.change(
|
| 46 |
+
inputs=[input_audio0],
|
| 47 |
+
outputs=[audio_player],
|
| 48 |
+
fn=lambda path: {"value":path,"__type__":"update"} if os.path.exists(path) else None
|
| 49 |
+
)
|
| 50 |
+
record_button.stop_recording(
|
| 51 |
+
fn=lambda audio:audio, #TODO save wav lambda
|
| 52 |
+
inputs=[record_button],
|
| 53 |
+
outputs=[input_audio0])
|
| 54 |
+
dropbox.upload(
|
| 55 |
+
fn=lambda audio:audio.name,
|
| 56 |
+
inputs=[dropbox],
|
| 57 |
+
outputs=[input_audio0])
|
| 58 |
+
with gr.Column():
|
| 59 |
+
with gr.Accordion("Change Index", open=False):
|
| 60 |
+
file_index2 = gr.Dropdown(
|
| 61 |
+
label="Change Index",
|
| 62 |
+
choices=sorted(index_paths),
|
| 63 |
+
interactive=True,
|
| 64 |
+
value=sorted(index_paths)[0] if len(sorted(index_paths)) > 0 else ''
|
| 65 |
+
)
|
| 66 |
+
index_rate1 = gr.Slider(
|
| 67 |
+
minimum=0,
|
| 68 |
+
maximum=1,
|
| 69 |
+
label="Index Strength",
|
| 70 |
+
value=0.5,
|
| 71 |
+
interactive=True,
|
| 72 |
+
)
|
| 73 |
+
vc_output2 = gr.Audio(label="Output")
|
| 74 |
+
with gr.Accordion("General Settings", open=False):
|
| 75 |
+
f0method0 = gr.Radio(
|
| 76 |
+
label="Method",
|
| 77 |
+
choices=["pm", "harvest", "crepe", "rmvpe", "dio", "fcpe"]
|
| 78 |
+
if config.dml == False
|
| 79 |
+
else ["pm", "harvest", "rmvpe", "dio", "fcpe"],
|
| 80 |
+
value="rmvpe",
|
| 81 |
+
interactive=True,
|
| 82 |
+
)
|
| 83 |
+
filter_radius0 = gr.Slider(
|
| 84 |
+
minimum=0,
|
| 85 |
+
maximum=7,
|
| 86 |
+
label="Breathiness Reduction (Harvest only)",
|
| 87 |
+
value=3,
|
| 88 |
+
step=1,
|
| 89 |
+
interactive=True,
|
| 90 |
+
)
|
| 91 |
+
resample_sr0 = gr.Slider(
|
| 92 |
+
minimum=0,
|
| 93 |
+
maximum=48000,
|
| 94 |
+
label="Resample",
|
| 95 |
+
value=0,
|
| 96 |
+
step=1,
|
| 97 |
+
interactive=True,
|
| 98 |
+
visible=False
|
| 99 |
+
)
|
| 100 |
+
rms_mix_rate0 = gr.Slider(
|
| 101 |
+
minimum=0,
|
| 102 |
+
maximum=1,
|
| 103 |
+
label="Volume Normalization",
|
| 104 |
+
value=0,
|
| 105 |
+
interactive=True,
|
| 106 |
+
)
|
| 107 |
+
protect0 = gr.Slider(
|
| 108 |
+
minimum=0,
|
| 109 |
+
maximum=0.5,
|
| 110 |
+
label="Breathiness Protection (0 is enabled, 0.5 is disabled)",
|
| 111 |
+
value=0.33,
|
| 112 |
+
step=0.01,
|
| 113 |
+
interactive=True,
|
| 114 |
+
)
|
| 115 |
+
if voice_model != None: vc.get_vc(voice_model.value,protect0,protect0)
|
| 116 |
+
file_index1 = gr.Textbox(
|
| 117 |
+
label="Index Path",
|
| 118 |
+
interactive=True,
|
| 119 |
+
visible=False#Not used here
|
| 120 |
+
)
|
| 121 |
+
refresh_button.click(
|
| 122 |
+
fn=change_choices,
|
| 123 |
+
inputs=[],
|
| 124 |
+
outputs=[voice_model, file_index2],
|
| 125 |
+
api_name="infer_refresh",
|
| 126 |
+
)
|
| 127 |
+
refresh_button.click(
|
| 128 |
+
fn=lambda:{"choices":paths_for_files('audios'),"__type__":"update"}, #TODO check if properly returns a sorted list of audio files in the 'audios' folder that have the extensions '.wav', '.mp3', '.ogg', or '.flac'
|
| 129 |
+
inputs=[],
|
| 130 |
+
outputs = [input_audio0],
|
| 131 |
+
)
|
| 132 |
+
refresh_button.click(
|
| 133 |
+
fn=lambda:{"value":paths_for_files('audios')[0],"__type__":"update"} if len(paths_for_files('audios')) > 0 else {"value":"","__type__":"update"}, #TODO check if properly returns a sorted list of audio files in the 'audios' folder that have the extensions '.wav', '.mp3', '.ogg', or '.flac'
|
| 134 |
+
inputs=[],
|
| 135 |
+
outputs = [input_audio0],
|
| 136 |
+
)
|
| 137 |
+
with gr.Row():
|
| 138 |
+
f0_file = gr.File(label="F0 Path", visible=False)
|
| 139 |
+
with gr.Row():
|
| 140 |
+
vc_output1 = gr.Textbox(label="Information", placeholder="Welcome!",visible=False)
|
| 141 |
+
but0.click(
|
| 142 |
+
vc.vc_single,
|
| 143 |
+
[
|
| 144 |
+
spk_item,
|
| 145 |
+
input_audio0,
|
| 146 |
+
vc_transform0,
|
| 147 |
+
f0_file,
|
| 148 |
+
f0method0,
|
| 149 |
+
file_index1,
|
| 150 |
+
file_index2,
|
| 151 |
+
index_rate1,
|
| 152 |
+
filter_radius0,
|
| 153 |
+
resample_sr0,
|
| 154 |
+
rms_mix_rate0,
|
| 155 |
+
protect0,
|
| 156 |
+
],
|
| 157 |
+
[vc_output1, vc_output2],
|
| 158 |
+
api_name="infer_convert",
|
| 159 |
+
)
|
| 160 |
+
voice_model.change(
|
| 161 |
+
fn=vc.get_vc,
|
| 162 |
+
inputs=[voice_model, protect0, protect0],
|
| 163 |
+
outputs=[spk_item, protect0, protect0, file_index2, file_index2],
|
| 164 |
+
api_name="infer_change_voice",
|
| 165 |
+
)
|
| 166 |
+
with gr.TabItem("Download Models"):
|
| 167 |
+
with gr.Row():
|
| 168 |
+
url_input = gr.Textbox(label="URL to model", value="",placeholder="https://...", scale=6)
|
| 169 |
+
name_output = gr.Textbox(label="Save as", value="",placeholder="MyModel",scale=2)
|
| 170 |
+
url_download = gr.Button(value="Download Model",scale=2)
|
| 171 |
+
url_download.click(
|
| 172 |
+
inputs=[url_input,name_output],
|
| 173 |
+
outputs=[url_input],
|
| 174 |
+
fn=download_from_url,
|
| 175 |
+
)
|
| 176 |
+
with gr.Row():
|
| 177 |
+
model_browser = gr.Dropdown(choices=list(model_library.models.keys()),label="OR Search Models (Quality UNKNOWN)",scale=5)
|
| 178 |
+
download_from_browser = gr.Button(value="Get",scale=2)
|
| 179 |
+
download_from_browser.click(
|
| 180 |
+
inputs=[model_browser],
|
| 181 |
+
outputs=[model_browser],
|
| 182 |
+
fn=lambda model: download_from_url(model_library.models[model],model),
|
| 183 |
+
)
|
| 184 |
+
with gr.TabItem("Train"):
|
| 185 |
+
with gr.Row():
|
| 186 |
+
with gr.Column():
|
| 187 |
+
training_name = gr.Textbox(label="Name your model", value="My-Voice",placeholder="My-Voice")
|
| 188 |
+
np7 = gr.Slider(
|
| 189 |
+
minimum=0,
|
| 190 |
+
maximum=config.n_cpu,
|
| 191 |
+
step=1,
|
| 192 |
+
label="Number of CPU processes used to extract pitch features",
|
| 193 |
+
value=int(np.ceil(config.n_cpu / 1.5)),
|
| 194 |
+
interactive=True,
|
| 195 |
+
)
|
| 196 |
+
sr2 = gr.Radio(
|
| 197 |
+
label="Sampling Rate",
|
| 198 |
+
choices=["40k", "32k"],
|
| 199 |
+
value="32k",
|
| 200 |
+
interactive=True,
|
| 201 |
+
visible=False
|
| 202 |
+
)
|
| 203 |
+
if_f0_3 = gr.Radio(
|
| 204 |
+
label="Will your model be used for singing? If not, you can ignore this.",
|
| 205 |
+
choices=[True, False],
|
| 206 |
+
value=True,
|
| 207 |
+
interactive=True,
|
| 208 |
+
visible=False
|
| 209 |
+
)
|
| 210 |
+
version19 = gr.Radio(
|
| 211 |
+
label="Version",
|
| 212 |
+
choices=["v1", "v2"],
|
| 213 |
+
value="v2",
|
| 214 |
+
interactive=True,
|
| 215 |
+
visible=False,
|
| 216 |
+
)
|
| 217 |
+
dataset_folder = gr.Textbox(
|
| 218 |
+
label="dataset folder", value='dataset'
|
| 219 |
+
)
|
| 220 |
+
easy_uploader = gr.Files(label="Drop your audio files here",file_types=['audio'])
|
| 221 |
+
but1 = gr.Button("1. Process", variant="primary")
|
| 222 |
+
info1 = gr.Textbox(label="Information", value="",visible=True)
|
| 223 |
+
easy_uploader.upload(inputs=[dataset_folder],outputs=[],fn=lambda folder:os.makedirs(folder,exist_ok=True))
|
| 224 |
+
easy_uploader.upload(
|
| 225 |
+
fn=lambda files,folder: [shutil.copy2(f.name,os.path.join(folder,os.path.split(f.name)[1])) for f in files] if folder != "" else gr.Warning('Please enter a folder name for your dataset'),
|
| 226 |
+
inputs=[easy_uploader, dataset_folder],
|
| 227 |
+
outputs=[])
|
| 228 |
+
gpus6 = gr.Textbox(
|
| 229 |
+
label="Enter the GPU numbers to use separated by -, (e.g. 0-1-2)",
|
| 230 |
+
value=gpus,
|
| 231 |
+
interactive=True,
|
| 232 |
+
visible=F0GPUVisible,
|
| 233 |
+
)
|
| 234 |
+
gpu_info9 = gr.Textbox(
|
| 235 |
+
label="GPU Info", value=gpu_info, visible=F0GPUVisible
|
| 236 |
+
)
|
| 237 |
+
spk_id5 = gr.Slider(
|
| 238 |
+
minimum=0,
|
| 239 |
+
maximum=4,
|
| 240 |
+
step=1,
|
| 241 |
+
label="Speaker ID",
|
| 242 |
+
value=0,
|
| 243 |
+
interactive=True,
|
| 244 |
+
visible=False
|
| 245 |
+
)
|
| 246 |
+
but1.click(
|
| 247 |
+
preprocess_dataset,
|
| 248 |
+
[dataset_folder, training_name, sr2, np7],
|
| 249 |
+
[info1],
|
| 250 |
+
api_name="train_preprocess",
|
| 251 |
+
)
|
| 252 |
+
with gr.Column():
|
| 253 |
+
f0method8 = gr.Radio(
|
| 254 |
+
label="F0 extraction method",
|
| 255 |
+
choices=["pm", "harvest", "dio", "rmvpe", "rmvpe_gpu"],
|
| 256 |
+
value="rmvpe_gpu",
|
| 257 |
+
interactive=True,
|
| 258 |
+
)
|
| 259 |
+
gpus_rmvpe = gr.Textbox(
|
| 260 |
+
label="GPU numbers to use separated by -, (e.g. 0-1-2)",
|
| 261 |
+
value="%s-%s" % (gpus, gpus),
|
| 262 |
+
interactive=True,
|
| 263 |
+
visible=F0GPUVisible,
|
| 264 |
+
)
|
| 265 |
+
but2 = gr.Button("2. Extract Features", variant="primary")
|
| 266 |
+
info2 = gr.Textbox(label="Information", value="", max_lines=8)
|
| 267 |
+
f0method8.change(
|
| 268 |
+
fn=change_f0_method,
|
| 269 |
+
inputs=[f0method8],
|
| 270 |
+
outputs=[gpus_rmvpe],
|
| 271 |
+
)
|
| 272 |
+
but2.click(
|
| 273 |
+
extract_f0_feature,
|
| 274 |
+
[
|
| 275 |
+
gpus6,
|
| 276 |
+
np7,
|
| 277 |
+
f0method8,
|
| 278 |
+
if_f0_3,
|
| 279 |
+
training_name,
|
| 280 |
+
version19,
|
| 281 |
+
gpus_rmvpe,
|
| 282 |
+
],
|
| 283 |
+
[info2],
|
| 284 |
+
api_name="train_extract_f0_feature",
|
| 285 |
+
)
|
| 286 |
+
with gr.Column():
|
| 287 |
+
total_epoch11 = gr.Slider(
|
| 288 |
+
minimum=2,
|
| 289 |
+
maximum=1000,
|
| 290 |
+
step=1,
|
| 291 |
+
label="Epochs (more epochs may improve quality but takes longer)",
|
| 292 |
+
value=150,
|
| 293 |
+
interactive=True,
|
| 294 |
+
)
|
| 295 |
+
but4 = gr.Button("3. Train Index", variant="primary")
|
| 296 |
+
but3 = gr.Button("4. Train Model", variant="primary")
|
| 297 |
+
info3 = gr.Textbox(label="Information", value="", max_lines=10)
|
| 298 |
+
with gr.Accordion(label="General Settings", open=False):
|
| 299 |
+
gpus16 = gr.Textbox(
|
| 300 |
+
label="GPUs separated by -, (e.g. 0-1-2)",
|
| 301 |
+
value="0",
|
| 302 |
+
interactive=True,
|
| 303 |
+
visible=True
|
| 304 |
+
)
|
| 305 |
+
save_epoch10 = gr.Slider(
|
| 306 |
+
minimum=1,
|
| 307 |
+
maximum=50,
|
| 308 |
+
step=1,
|
| 309 |
+
label="Weight Saving Frequency",
|
| 310 |
+
value=25,
|
| 311 |
+
interactive=True,
|
| 312 |
+
)
|
| 313 |
+
batch_size12 = gr.Slider(
|
| 314 |
+
minimum=1,
|
| 315 |
+
maximum=40,
|
| 316 |
+
step=1,
|
| 317 |
+
label="Batch Size",
|
| 318 |
+
value=default_batch_size,
|
| 319 |
+
interactive=True,
|
| 320 |
+
)
|
| 321 |
+
if_save_latest13 = gr.Radio(
|
| 322 |
+
label="Only save the latest model",
|
| 323 |
+
choices=["yes", "no"],
|
| 324 |
+
value="yes",
|
| 325 |
+
interactive=True,
|
| 326 |
+
visible=False
|
| 327 |
+
)
|
| 328 |
+
if_cache_gpu17 = gr.Radio(
|
| 329 |
+
label="If your dataset is UNDER 10 minutes, cache it to train faster",
|
| 330 |
+
choices=["yes", "no"],
|
| 331 |
+
value="no",
|
| 332 |
+
interactive=True,
|
| 333 |
+
)
|
| 334 |
+
if_save_every_weights18 = gr.Radio(
|
| 335 |
+
label="Save small model at every save point",
|
| 336 |
+
choices=["yes", "no"],
|
| 337 |
+
value="yes",
|
| 338 |
+
interactive=True,
|
| 339 |
+
)
|
| 340 |
+
with gr.Accordion(label="Change pretrains", open=False):
|
| 341 |
+
pretrained = lambda sr, letter: [os.path.abspath(os.path.join('assets/pretrained_v2', file)) for file in os.listdir('assets/pretrained_v2') if file.endswith('.pth') and sr in file and letter in file]
|
| 342 |
+
pretrained_G14 = gr.Dropdown(
|
| 343 |
+
label="pretrained G",
|
| 344 |
+
# Get a list of all pretrained G model files in assets/pretrained_v2 that end with .pth
|
| 345 |
+
choices = pretrained(sr2.value, 'G'),
|
| 346 |
+
value=pretrained(sr2.value, 'G')[0] if len(pretrained(sr2.value, 'G')) > 0 else '',
|
| 347 |
+
interactive=True,
|
| 348 |
+
visible=True
|
| 349 |
+
)
|
| 350 |
+
pretrained_D15 = gr.Dropdown(
|
| 351 |
+
label="pretrained D",
|
| 352 |
+
choices = pretrained(sr2.value, 'D'),
|
| 353 |
+
value= pretrained(sr2.value, 'D')[0] if len(pretrained(sr2.value, 'G')) > 0 else '',
|
| 354 |
+
visible=True,
|
| 355 |
+
interactive=True
|
| 356 |
+
)
|
| 357 |
+
with gr.Row():
|
| 358 |
+
download_model = gr.Button('5.Download Model')
|
| 359 |
+
with gr.Row():
|
| 360 |
+
model_files = gr.Files(label='Your Model and Index file can be downloaded here:')
|
| 361 |
+
download_model.click(
|
| 362 |
+
fn=lambda name: os.listdir(f'assets/weights/{name}') + glob.glob(f'logs/{name.split(".")[0]}/added_*.index'),
|
| 363 |
+
inputs=[training_name],
|
| 364 |
+
outputs=[model_files, info3])
|
| 365 |
+
with gr.Row():
|
| 366 |
+
sr2.change(
|
| 367 |
+
change_sr2,
|
| 368 |
+
[sr2, if_f0_3, version19],
|
| 369 |
+
[pretrained_G14, pretrained_D15],
|
| 370 |
+
)
|
| 371 |
+
version19.change(
|
| 372 |
+
change_version19,
|
| 373 |
+
[sr2, if_f0_3, version19],
|
| 374 |
+
[pretrained_G14, pretrained_D15, sr2],
|
| 375 |
+
)
|
| 376 |
+
if_f0_3.change(
|
| 377 |
+
change_f0,
|
| 378 |
+
[if_f0_3, sr2, version19],
|
| 379 |
+
[f0method8, pretrained_G14, pretrained_D15],
|
| 380 |
+
)
|
| 381 |
+
with gr.Row():
|
| 382 |
+
but5 = gr.Button("1 Click Training", variant="primary", visible=False)
|
| 383 |
+
but3.click(
|
| 384 |
+
click_train,
|
| 385 |
+
[
|
| 386 |
+
training_name,
|
| 387 |
+
sr2,
|
| 388 |
+
if_f0_3,
|
| 389 |
+
spk_id5,
|
| 390 |
+
save_epoch10,
|
| 391 |
+
total_epoch11,
|
| 392 |
+
batch_size12,
|
| 393 |
+
if_save_latest13,
|
| 394 |
+
pretrained_G14,
|
| 395 |
+
pretrained_D15,
|
| 396 |
+
gpus16,
|
| 397 |
+
if_cache_gpu17,
|
| 398 |
+
if_save_every_weights18,
|
| 399 |
+
version19,
|
| 400 |
+
],
|
| 401 |
+
info3,
|
| 402 |
+
api_name="train_start",
|
| 403 |
+
)
|
| 404 |
+
but4.click(train_index, [training_name, version19], info3)
|
| 405 |
+
but5.click(
|
| 406 |
+
train1key,
|
| 407 |
+
[
|
| 408 |
+
training_name,
|
| 409 |
+
sr2,
|
| 410 |
+
if_f0_3,
|
| 411 |
+
dataset_folder,
|
| 412 |
+
spk_id5,
|
| 413 |
+
np7,
|
| 414 |
+
f0method8,
|
| 415 |
+
save_epoch10,
|
| 416 |
+
total_epoch11,
|
| 417 |
+
batch_size12,
|
| 418 |
+
if_save_latest13,
|
| 419 |
+
pretrained_G14,
|
| 420 |
+
pretrained_D15,
|
| 421 |
+
gpus16,
|
| 422 |
+
if_cache_gpu17,
|
| 423 |
+
if_save_every_weights18,
|
| 424 |
+
version19,
|
| 425 |
+
gpus_rmvpe,
|
| 426 |
+
],
|
| 427 |
+
info3,
|
| 428 |
+
api_name="train_start_all",
|
| 429 |
+
)
|
| 430 |
+
|
| 431 |
+
if config.iscolab:
|
| 432 |
+
app.queue(concurrency_count=511, max_size=1022).launch(share=True)
|
| 433 |
+
else:
|
| 434 |
+
app.queue(concurrency_count=511, max_size=1022).launch(
|
| 435 |
+
server_name="0.0.0.0",
|
| 436 |
+
inbrowser=not config.noautoopen,
|
| 437 |
+
server_port=config.listen_port,
|
| 438 |
+
quiet=True,
|
| 439 |
+
)
|