File size: 28,979 Bytes
8ef89ca
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
{
  "cells": [
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "0pKllbPyK_BC"
      },
      "source": [
        "## **Applio NoUI**\n",
        "A simple, high-quality voice conversion tool focused on ease of use and performance.\n",
        "\n",
        "[Support](https://discord.gg/urxFjYmYYh) — [GitHub](https://github.com/IAHispano/Applio) — [Terms of Use](https://github.com/IAHispano/Applio/blob/main/TERMS_OF_USE.md)\n",
        "\n",
        "<br>\n",
        "\n",
        "---\n",
        "\n",
        "<br>\n",
        "\n",
        "#### **Acknowledgments**\n",
        "\n",
        "To all external collaborators for their special help in the following areas:\n",
        "* Hina (Encryption method)\n",
        "* Poopmaster (Extra section)\n",
        "* Shirou (UV installer)\n",
        "* Bruno5430 (AutoBackup code and general notebook maintenance)\n",
        "\n",
        "#### **Disclaimer**\n",
        "By using Applio, you agree to comply with ethical and legal standards, respect intellectual property and privacy rights, avoid harmful or prohibited uses, and accept full responsibility for any outcomes, while Applio disclaims liability and reserves the right to amend these terms."
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "ymMCTSD6m8qV"
      },
      "source": [
        "### **Install Applio**\n",
        "If the runtime restarts, re-run the installation steps."
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "cellView": "form",
        "id": "yFhAeKGOp9aa"
      },
      "outputs": [],
      "source": [
        "# @title Mount Google Drive\n",
        "from google.colab import drive\n",
        "from google.colab._message import MessageError\n",
        "\n",
        "try:\n",
        "  drive.mount(\"/content/drive\")\n",
        "except MessageError:\n",
        "  print(\"❌ Failed to mount drive\")\n",
        "\n",
        "# Migrate folders to match documentation\n",
        "from pathlib import Path\n",
        "if Path(\"/content/drive\").is_mount():\n",
        "  %cd \"/content/drive/MyDrive/\"\n",
        "  if not Path(\"ApplioBackup/\").exists() and Path(\"RVC_Backup/\").exists():\n",
        "    !mv \"RVC_Backup/\" \"ApplioBackup/\"\n",
        "  %cd /content"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "cellView": "form",
        "id": "CAXW55BQm0PP"
      },
      "outputs": [],
      "source": [
        "# @title Setup runtime environment\n",
        "from multiprocessing import cpu_count\n",
        "cpu_cores = cpu_count()\n",
        "post_process = False\n",
        "LOGS_PATH = \"/content/Applio/logs\"\n",
        "BACKUPS_PATH = \"/content/drive/MyDrive/ApplioBackup\"\n",
        "\n",
        "%cd /content\n",
        "!git config --global advice.detachedHead false\n",
        "!git clone https://github.com/IAHispano/Applio --single-branch\n",
        "%cd /content/Applio\n",
        "!git checkout 8e161d2baffd145782241c8b1779f77d1bf7a06d\n",
        "\n",
        "# Install older python\n",
        "!apt install python3.11 python3.11-distutils\n",
        "!update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.11 2\n",
        "!update-alternatives --set python3 /usr/bin/python3.11\n",
        "\n",
        "print(\"Installing requirements...\")\n",
        "!curl -LsSf https://astral.sh/uv/install.sh | sh\n",
        "!uv pip install -q torch==2.7.1 torchvision torchaudio==2.7.1 --upgrade --index-url https://download.pytorch.org/whl/cu128\n",
        "!uv pip install -q -r requirements.txt\n",
        "!uv pip install -q jupyter-ui-poll\n",
        "!python core.py \"prerequisites\" --models \"True\" --pretraineds_hifigan \"True\"\n",
        "print(\"Finished installing requirements!\")\n"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "YzaeMYsUE97Y"
      },
      "source": [
        "### **Infer**\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "cellView": "form",
        "id": "2miFQtlfiWy_"
      },
      "outputs": [],
      "source": [
        "# @title Sync with Google Drive\n",
        "# @markdown 💾 Run this cell to automatically Save/Load models from your mounted drive\n",
        "# @title\n",
        "# @markdown This will merge and link your `ApplioBackup` folder from gdrive to this notebook\n",
        "from IPython.display import display, clear_output\n",
        "from pathlib import Path\n",
        "\n",
        "non_bak_folders = [\"mute\", \"reference\", \"zips\", \"mute_spin\"]\n",
        "non_bak_path = \"/tmp/rvc_logs\"\n",
        "\n",
        "\n",
        "def press_button(button):\n",
        "  button.disabled = True\n",
        "\n",
        "\n",
        "def get_date(path: Path):\n",
        "  from datetime import datetime\n",
        "  return datetime.fromtimestamp(int(path.stat().st_mtime))\n",
        "\n",
        "\n",
        "def get_size(path: Path):\n",
        "  !du -shx --apparent-size \"{path}\" > /tmp/size.txt\n",
        "  return open(\"/tmp/size.txt\").readlines().pop(0).split(\"\t\")[0] + \"B\"\n",
        "\n",
        "\n",
        "def sync_folders(folder: Path, backup: Path):\n",
        "  from ipywidgets import widgets\n",
        "  from jupyter_ui_poll import ui_events\n",
        "  from time import sleep\n",
        "\n",
        "  local = widgets.VBox([\n",
        "      widgets.Label(f\"Local: {LOGS_PATH.removeprefix('/content/')}/{folder.name}/\"),\n",
        "      widgets.Label(f\"Size: {get_size(folder)}\"),\n",
        "      widgets.Label(f\"Last modified: {get_date(folder)}\")\n",
        "  ])\n",
        "  remote = widgets.VBox([\n",
        "      widgets.Label(f\"Remote: {BACKUPS_PATH.removeprefix('/content/')}/{backup.name}/\"),\n",
        "      widgets.Label(f\"Size: {get_size(backup)}\"),\n",
        "      widgets.Label(f\"Last modified: {get_date(backup)}\")\n",
        "  ])\n",
        "  separator = widgets.VBox([\n",
        "      widgets.Label(\"|||\"),\n",
        "      widgets.Label(\"|||\"),\n",
        "      widgets.Label(\"|||\")\n",
        "  ])\n",
        "  radio = widgets.RadioButtons(\n",
        "      options=[\n",
        "          \"Save local model to drive\",\n",
        "          \"Keep remote model\"\n",
        "      ]\n",
        "  )\n",
        "  button = widgets.Button(\n",
        "      description=\"Sync\",\n",
        "      icon=\"upload\",\n",
        "      tooltip=\"Sync model\"\n",
        "  )\n",
        "  button.on_click(press_button)\n",
        "\n",
        "  clear_output()\n",
        "  print(f\"Your local model '{folder.name}' is in conflict with it's copy in Google Drive.\")\n",
        "  print(\"Please select which one you want to keep:\")\n",
        "  display(widgets.Box([local, separator, remote]))\n",
        "  display(radio)\n",
        "  display(button)\n",
        "\n",
        "  with ui_events() as poll:\n",
        "    while not button.disabled:\n",
        "      poll(10)\n",
        "      sleep(0.1)\n",
        "\n",
        "  match radio.value:\n",
        "    case \"Save local model to drive\":\n",
        "      !rm -r \"{backup}\"\n",
        "      !mv \"{folder}\" \"{backup}\"\n",
        "    case \"Keep remote model\":\n",
        "      !rm -r \"{folder}\"\n",
        "\n",
        "\n",
        "if Path(\"/content/drive\").is_mount():\n",
        "  !mkdir -p \"{BACKUPS_PATH}\"\n",
        "  !mkdir -p \"{non_bak_path}\"\n",
        "\n",
        "  if not Path(LOGS_PATH).is_symlink():\n",
        "    for folder in non_bak_folders:\n",
        "      folder = Path(f\"{LOGS_PATH}/{folder}\")\n",
        "      backup = Path(f\"{BACKUPS_PATH}/{folder.name}\")\n",
        "\n",
        "      !mkdir -p \"{folder}\"\n",
        "      !mv \"{folder}\" \"{non_bak_path}\" &> /dev/null\n",
        "      !rm -rf \"{folder}\"\n",
        "      folder = Path(f\"{non_bak_path}/{folder.name}\")\n",
        "      if backup.exists() and backup.resolve() != folder.resolve():\n",
        "        !rm -r \"{backup}\"\n",
        "      !ln -s \"{folder}\" \"{backup}\" &> /dev/null\n",
        "\n",
        "    for model in Path(LOGS_PATH).iterdir():\n",
        "      if model.is_dir() and not model.is_symlink():\n",
        "        backup = Path(f\"{BACKUPS_PATH}/{model.name}\")\n",
        "\n",
        "        if model.name == \".ipynb_checkpoints\":\n",
        "          continue\n",
        "\n",
        "        if backup.exists() and backup.is_dir():\n",
        "          sync_folders(model, backup)\n",
        "        else:\n",
        "          !rm \"{backup}\"\n",
        "          !mv \"{model}\" \"{backup}\"\n",
        "\n",
        "    !rm -r \"{LOGS_PATH}\"\n",
        "    !ln -s \"{BACKUPS_PATH}\" \"{LOGS_PATH}\"\n",
        "\n",
        "    clear_output()\n",
        "    print(\"✅ Models are synced!\")\n",
        "\n",
        "  else:\n",
        "    !rm \"{LOGS_PATH}\"\n",
        "    !ln -s \"{BACKUPS_PATH}\" \"{LOGS_PATH}\"\n",
        "    clear_output()\n",
        "    print(\"✅ Models already synced!\")\n",
        "\n",
        "else:\n",
        "  print(\"❌ Drive is not mounted, skipping model syncing\")\n",
        "  print(\"To sync your models, first mount your Google Drive and re-run this cell\")"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "cellView": "form",
        "id": "v0EgikgjFCjE"
      },
      "outputs": [],
      "source": [
        "# @title Download model\n",
        "# @markdown Hugging Face or Google Drive\n",
        "model_link = \"https://huggingface.co/Darwin/Darwin/resolve/main/Darwin.zip\"  # @param {type:\"string\"}\n",
        "\n",
        "%cd /content/Applio\n",
        "!python core.py download --model_link \"{model_link}\""
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "cellView": "form",
        "id": "lrCKEOzvDPRu"
      },
      "outputs": [],
      "source": [
        "# @title Run Inference\n",
        "# @markdown Please upload the audio file to your Google Drive path `/content/drive/MyDrive` and specify its name here. For the model name, use the zip file name without the extension. Alternatively, you can check the path `/content/Applio/logs` for the model name (name of the folder).\n",
        "%cd /content/Applio\n",
        "from pathlib import Path\n",
        "\n",
        "model_name = \"Darwin\"  # @param {type:\"string\"}\n",
        "model_path = Path(f\"{LOGS_PATH}/{model_name}\")\n",
        "if not (model_path.exists() and model_path.is_dir()):\n",
        "    raise FileNotFoundError(f\"Model directory not found: {model_path.resolve()}\")\n",
        "\n",
        "# Select either the last checkpoint or the final weight\n",
        "!ls -t \"{model_path}\"/\"{model_name}\"_*e_*s.pth \"{model_path}\"/\"{model_name}\".pth 2> /dev/null | head -n 1 > /tmp/pth.txt\n",
        "pth_file = open(\"/tmp/pth.txt\", \"r\").read().strip()\n",
        "if pth_file == \"\":\n",
        "  raise FileNotFoundError(f\"No model weight found in directory: {model_path.resolve()}\\nMake sure that the file is properly named (e.g. \\\"{model_name}.pth)\\\"\")\n",
        "\n",
        "!ls -t \"{model_path}\"/*.index | head -n 1 > /tmp/index.txt\n",
        "index_file = open(\"/tmp/index.txt\", \"r\").read().strip()\n",
        "\n",
        "input_path = \"/content/example.wav\"  # @param {type:\"string\"}\n",
        "output_path = \"/content/output.wav\"\n",
        "export_format = \"WAV\"  # @param ['WAV', 'MP3', 'FLAC', 'OGG', 'M4A'] {allow-input: false}\n",
        "f0_method = \"rmvpe\"  # @param [\"crepe\", \"crepe-tiny\", \"rmvpe\", \"fcpe\", \"hybrid[rmvpe+fcpe]\"] {allow-input: false}\n",
        "f0_up_key = 0  # @param {type:\"slider\", min:-24, max:24, step:0}\n",
        "rms_mix_rate = 0.8  # @param {type:\"slider\", min:0.0, max:1.0, step:0.1}\n",
        "protect = 0.5  # @param {type:\"slider\", min:0.0, max:0.5, step:0.1}\n",
        "index_rate = 0.7  # @param {type:\"slider\", min:0.0, max:1.0, step:0.1}\n",
        "clean_strength = 0.7  # @param {type:\"slider\", min:0.0, max:1.0, step:0.1}\n",
        "split_audio = False  # @param{type:\"boolean\"}\n",
        "clean_audio = False  # @param{type:\"boolean\"}\n",
        "f0_autotune = False  # @param{type:\"boolean\"}\n",
        "formant_shift = False # @param{type:\"boolean\"}\n",
        "formant_qfrency = 1.0 # @param {type:\"slider\", min:1.0, max:16.0, step:0.1}\n",
        "formant_timbre = 1.0 # @param {type:\"slider\", min:1.0, max:16.0, step:0.1}\n",
        "embedder_model = \"contentvec\" # @param [\"contentvec\", \"chinese-hubert-base\", \"japanese-hubert-base\", \"korean-hubert-base\", \"custom\"] {allow-input: false}\n",
        "embedder_model_custom = \"\" # @param {type:\"string\"}\n",
        "\n",
        "!rm -f \"{output_path}\"\n",
        "if post_process:\n",
        "  !python core.py infer --pitch \"{f0_up_key}\" --volume_envelope \"{rms_mix_rate}\" --index_rate \"{index_rate}\" --protect \"{protect}\" --f0_autotune \"{f0_autotune}\" --f0_method \"{f0_method}\" --input_path \"{input_path}\" --output_path \"{output_path}\" --pth_path \"{pth_file}\" --index_path \"{index_file}\" --split_audio \"{split_audio}\" --clean_audio \"{clean_audio}\" --clean_strength \"{clean_strength}\" --export_format \"{export_format}\" --embedder_model \"{embedder_model}\" --embedder_model_custom \"{embedder_model_custom}\" --formant_shifting \"{formant_shift}\" --formant_qfrency \"{formant_qfrency}\" --formant_timbre \"{formant_timbre}\" --post_process \"{post_process}\" --reverb \"{reverb}\" --pitch_shift \"{pitch_shift}\" --limiter \"{limiter}\" --gain \"{gain}\" --distortion \"{distortion}\" --chorus \"{chorus}\" --bitcrush \"{bitcrush}\" --clipping \"{clipping}\" --compressor \"{compressor}\" --delay \"{delay}\" --reverb_room_size \"{reverb_room_size}\" --reverb_damping \"{reverb_damping}\" --reverb_wet_gain \"{reverb_wet_gain}\" --reverb_dry_gain \"{reverb_dry_gain}\" --reverb_width \"{reverb_width}\" --reverb_freeze_mode \"{reverb_freeze_mode}\" --pitch_shift_semitones \"{pitch_shift_semitones}\" --limiter_threshold \"{limiter_threshold}\" --limiter_release_time \"{limiter_release_time}\" --gain_db \"{gain_db}\" --distortion_gain \"{distortion_gain}\" --chorus_rate \"{chorus_rate}\" --chorus_depth \"{chorus_depth}\" --chorus_center_delay \"{chorus_center_delay}\" --chorus_feedback \"{chorus_feedback}\" --chorus_mix \"{chorus_mix}\" --bitcrush_bit_depth \"{bitcrush_bit_depth}\" --clipping_threshold \"{clipping_threshold}\" --compressor_threshold \"{compressor_threshold}\" --compressor_ratio \"{compressor_ratio}\" --compressor_attack \"{compressor_attack}\" --compressor_release \"{compressor_release}\" --delay_seconds \"{delay_seconds}\" --delay_feedback \"{delay_feedback}\" --delay_mix \"{delay_mix}\"\n",
        "else:\n",
        "  !python core.py infer --pitch \"{f0_up_key}\" --volume_envelope \"{rms_mix_rate}\" --index_rate \"{index_rate}\" --protect \"{protect}\" --f0_autotune \"{f0_autotune}\" --f0_method \"{f0_method}\" --input_path \"{input_path}\" --output_path \"{output_path}\" --pth_path \"{pth_file}\" --index_path \"{index_file}\" --split_audio \"{split_audio}\" --clean_audio \"{clean_audio}\" --clean_strength \"{clean_strength}\" --export_format \"{export_format}\" --embedder_model \"{embedder_model}\" --embedder_model_custom \"{embedder_model_custom}\" --formant_shifting \"{formant_shift}\" --formant_qfrency \"{formant_qfrency}\" --formant_timbre \"{formant_timbre}\" --post_process \"{post_process}\"\n",
        "\n",
        "if Path(output_path).exists():\n",
        "  from IPython.display import Audio, display\n",
        "  output_path = output_path.replace(\".wav\", f\".{export_format.lower()}\")\n",
        "  display(Audio(output_path, autoplay=True))"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "cellView": "form",
        "id": "J43qejJ-2Tpp"
      },
      "outputs": [],
      "source": [
        "# @title Enable post-processing effects for inference\n",
        "post_process = False # @param{type:\"boolean\"}\n",
        "reverb = False # @param{type:\"boolean\"}\n",
        "pitch_shift = False # @param{type:\"boolean\"}\n",
        "limiter = False # @param{type:\"boolean\"}\n",
        "gain = False # @param{type:\"boolean\"}\n",
        "distortion = False # @param{type:\"boolean\"}\n",
        "chorus = False # @param{type:\"boolean\"}\n",
        "bitcrush = False # @param{type:\"boolean\"}\n",
        "clipping = False # @param{type:\"boolean\"}\n",
        "compressor = False # @param{type:\"boolean\"}\n",
        "delay = False # @param{type:\"boolean\"}\n",
        "\n",
        "reverb_room_size = 0.5 # @param {type:\"slider\", min:0.0, max:1.0, step:0.1}\n",
        "reverb_damping = 0.5 # @param {type:\"slider\", min:0.0, max:1.0, step:0.1}\n",
        "reverb_wet_gain = 0.0 # @param {type:\"slider\", min:-20.0, max:20.0, step:0.1}\n",
        "reverb_dry_gain = 0.0 # @param {type:\"slider\", min:-20.0, max:20.0, step:0.1}\n",
        "reverb_width = 1.0 # @param {type:\"slider\", min:0.0, max:1.0, step:0.1}\n",
        "reverb_freeze_mode = 0.0 # @param {type:\"slider\", min:0.0, max:1.0, step:0.1}\n",
        "\n",
        "pitch_shift_semitones = 0.0 # @param {type:\"slider\", min:-12.0, max:12.0, step:0.1}\n",
        "\n",
        "limiter_threshold = -1.0 # @param {type:\"slider\", min:-20.0, max:0.0, step:0.1}\n",
        "limiter_release_time = 0.05 # @param {type:\"slider\", min:0.0, max:1.0, step:0.01}\n",
        "\n",
        "gain_db = 0.0 # @param {type:\"slider\", min:-20.0, max:20.0, step:0.1}\n",
        "\n",
        "distortion_gain = 0.0 # @param {type:\"slider\", min:0.0, max:1.0, step:0.1}\n",
        "\n",
        "chorus_rate = 1.5 # @param {type:\"slider\", min:0.1, max:10.0, step:0.1}\n",
        "chorus_depth = 0.1 # @param {type:\"slider\", min:0.0, max:1.0, step:0.1}\n",
        "chorus_center_delay = 15.0 # @param {type:\"slider\", min:0.0, max:50.0, step:0.1}\n",
        "chorus_feedback = 0.25 # @param {type:\"slider\", min:0.0, max:1.0, step:0.1}\n",
        "chorus_mix = 0.5 # @param {type:\"slider\", min:0.0, max:1.0, step:0.1}\n",
        "\n",
        "bitcrush_bit_depth = 4 # @param {type:\"slider\", min:1, max:16, step:1}\n",
        "\n",
        "clipping_threshold = 0.5 # @param {type:\"slider\", min:0.0, max:1.0, step:0.1}\n",
        "\n",
        "compressor_threshold = -20.0 # @param {type:\"slider\", min:-60.0, max:0.0, step:0.1}\n",
        "compressor_ratio = 4.0 # @param {type:\"slider\", min:1.0, max:20.0, step:0.1}\n",
        "compressor_attack = 0.001 # @param {type:\"slider\", min:0.0, max:0.1, step:0.001}\n",
        "compressor_release = 0.1 # @param {type:\"slider\", min:0.0, max:1.0, step:0.01}\n",
        "\n",
        "delay_seconds = 0.1 # @param {type:\"slider\", min:0.0, max:1.0, step:0.01}\n",
        "delay_feedback = 0.5 # @param {type:\"slider\", min:0.0, max:1.0, step:0.1}\n",
        "delay_mix = 0.5 # @param {type:\"slider\", min:0.0, max:1.0, step:0.1}\n"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "1QkabnLlF2KB"
      },
      "source": [
        "### **Train**"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "cellView": "form",
        "id": "64V5TWxp05cn"
      },
      "outputs": [],
      "source": [
        "# @title Setup model parameters\n",
        "\n",
        "model_name = \"Darwin\" # @param {type:\"string\"}\n",
        "sample_rate = \"40k\"  # @param [\"32k\", \"40k\", \"48k\"] {allow-input: false}\n",
        "sr = int(sample_rate.rstrip(\"k\")) * 1000\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "cellView": "form",
        "id": "oBzqm4JkGGa0"
      },
      "outputs": [],
      "source": [
        "# @title Preprocess Dataset\n",
        "\n",
        "dataset_path = \"/content/drive/MyDrive/Darwin_Dataset\"  # @param {type:\"string\"}\n",
        "\n",
        "cut_preprocess = \"Automatic\" # @param [\"Skip\",\"Simple\",\"Automatic\"]\n",
        "chunk_len = 3 # @param {type:\"slider\", min:0.5, max:5.0, step:0.5}\n",
        "overlap_len = 0.3 # @param {type:\"slider\", min:0, max:0.5, step:0.1}\n",
        "process_effects = False # @param{type:\"boolean\"}\n",
        "noise_reduction = False # @param{type:\"boolean\"}\n",
        "noise_reduction_strength = 0.7 # @param {type:\"slider\", min:0.0, max:1.0, step:0.1}\n",
		"normalization_mode = \"none\" # @param [\"none\",\"pre\",\"post\"]\n",
        "\n",
        "%cd /content/Applio\n",
        "!python core.py preprocess --model_name \"{model_name}\" --dataset_path \"{dataset_path}\" --sample_rate \"{sr}\" --cpu_cores \"{cpu_cores}\" --cut_preprocess \"{cut_preprocess}\" --process_effects \"{process_effects}\" --noise_reduction \"{noise_reduction}\" --noise_reduction_strength \"{noise_reduction_strength}\" --chunk_len \"{chunk_len}\" --overlap_len \"{overlap_len}\" --normalization_mode \"{normalization_mode}\""
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "cellView": "form",
        "id": "zWMiMYfRJTJv"
      },
      "outputs": [],
      "source": [
        "# @title Extract Features\n",
        "f0_method = \"rmvpe\"  # @param [\"crepe\", \"crepe-tiny\", \"rmvpe\"] {allow-input: false}\n",
        "\n",
        "sr = int(sample_rate.rstrip(\"k\")) * 1000\n",
        "include_mutes = 2 # @param {type:\"slider\", min:0, max:10, step:1}\n",
        "embedder_model = \"contentvec\" # @param [\"contentvec\", \"chinese-hubert-base\", \"japanese-hubert-base\", \"korean-hubert-base\", \"custom\"] {allow-input: false}\n",
        "embedder_model_custom = \"\" # @param {type:\"string\"}\n",
        "\n",
        "%cd /content/Applio\n",
        "!python core.py extract --model_name \"{model_name}\" --f0_method \"{f0_method}\" --sample_rate \"{sr}\" --cpu_cores \"{cpu_cores}\" --gpu \"0\" --embedder_model \"{embedder_model}\" --embedder_model_custom \"{embedder_model_custom}\"  --include_mutes \"{include_mutes}\""
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "cellView": "form",
        "id": "bHLs5AT4Q1ck"
      },
      "outputs": [],
      "source": [
        "# @title Generate index file\n",
        "index_algorithm = \"Auto\"  # @param [\"Auto\", \"Faiss\", \"KMeans\"] {allow-input: false}\n",
        "\n",
        "%cd /content/Applio\n",
        "!python core.py index --model_name \"{model_name}\" --index_algorithm \"{index_algorithm}\""
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "cellView": "form",
        "id": "TI6LLdIzKAIa"
      },
      "outputs": [],
      "source": [
        "# @title Start Training\n",
        "# @markdown ### ⚙️ Train Settings\n",
        "total_epoch = 800  # @param {type:\"integer\"}\n",
        "batch_size = 8  # @param {type:\"slider\", min:1, max:25, step:0}\n",
        "pretrained = True  # @param{type:\"boolean\"}\n",
        "cleanup = False  # @param{type:\"boolean\"}\n",
        "cache_data_in_gpu = False  # @param{type:\"boolean\"}\n",
        "vocoder = \"HiFi-GAN\" # @param [\"HiFi-GAN\"]\n",
        "checkpointing = False\n",
        "tensorboard = True  # @param{type:\"boolean\"}\n",
        "# @markdown ### ➡️ Choose how many epochs your model will be stored\n",
        "save_every_epoch = 10  # @param {type:\"slider\", min:1, max:100, step:0}\n",
        "save_only_latest = True  # @param{type:\"boolean\"}\n",
        "save_every_weights = False  # @param{type:\"boolean\"}\n",
        "overtraining_detector = False  # @param{type:\"boolean\"}\n",
        "overtraining_threshold = 50  # @param {type:\"slider\", min:1, max:100, step:0}\n",
        "# @markdown ### ❓ Optional\n",
        "# @markdown In case you select custom pretrained, you will have to download the pretraineds and enter the path of the pretraineds.\n",
        "custom_pretrained = False  # @param{type:\"boolean\"}\n",
        "g_pretrained_path = \"/content/Applio/rvc/models/pretraineds/pretraineds_custom/G48k.pth\"  # @param {type:\"string\"}\n",
        "d_pretrained_path = \"/content/Applio/rvc/models/pretraineds/pretraineds_custom/D48k.pth\"  # @param {type:\"string\"}\n",
        "\n",
        "\n",
        "%cd /content/Applio\n",
        "if tensorboard:\n",
        "  %load_ext tensorboard\n",
        "  %tensorboard --logdir logs --bind_all\n",
        "!python core.py train --model_name \"{model_name}\" --save_every_epoch \"{save_every_epoch}\" --save_only_latest \"{save_only_latest}\" --save_every_weights \"{save_every_weights}\" --total_epoch \"{total_epoch}\" --sample_rate \"{sr}\" --batch_size \"{batch_size}\" --gpu 0 --pretrained \"{pretrained}\" --custom_pretrained \"{custom_pretrained}\" --g_pretrained_path \"{g_pretrained_path}\" --d_pretrained_path \"{d_pretrained_path}\" --overtraining_detector \"{overtraining_detector}\" --overtraining_threshold \"{overtraining_threshold}\" --cleanup \"{cleanup}\" --cache_data_in_gpu \"{cache_data_in_gpu}\" --vocoder \"{vocoder}\" --checkpointing \"{checkpointing}\""
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "cellView": "form",
        "id": "X_eU_SoiHIQg"
      },
      "outputs": [],
      "source": [
        "# @title Export model\n",
        "# @markdown Export model to a zip file\n",
        "# @markdown * Training: Bigger file size, can continue training\n",
        "# @markdown * Inference: Smaller file size, only for model inference\n",
        "# @title\n",
        "# @markdown (Note) Exporting for training is only recommended for use outside of Applio, if you plan to resume training later, use [Sync with Google Drive](#scrollTo=2miFQtlfiWy_) cell instead.\n",
        "EXPORT_PATH = \"/content/drive/MyDrive/ApplioExported\"\n",
        "from pathlib import Path\n",
        "\n",
        "export_for = \"inference\" # @param [\"training\", \"inference\"] {allow-input: false}\n",
        "\n",
        "logs_folder = Path(f\"/content/Applio/logs/{model_name}/\")\n",
        "if not (logs_folder.exists() and logs_folder.is_dir()):\n",
        "    raise FileNotFoundError(f\"{model_name} model folder not found\")\n",
        "\n",
        "%cd {logs_folder}/..\n",
        "if export_for == \"training\":\n",
        "  !zip -r \"/content/{model_name}.zip\" \"{model_name}\"\n",
        "else:\n",
        "  # find latest trained weight file\n",
        "  !ls -t \"{model_name}/{model_name}\"_*e_*s.pth | head -n 1 > /tmp/weight.txt\n",
        "  weight_path = open(\"/tmp/weight.txt\", \"r\").read().strip()\n",
        "  if weight_path == \"\":\n",
        "    raise FileNotFoundError(\"Model has no weight file, please finish training first\")\n",
        "  weight_name = Path(weight_path).name\n",
        "  # command does not fail if index is missing, this is intended\n",
        "  !zip \"/content/{model_name}.zip\" \"{model_name}/{weight_name}\" \"{model_name}/{model_name}.index\"\n",
        "\n",
        "if Path(\"/content/drive\").is_mount():\n",
        "  !mkdir -p \"{EXPORT_PATH}\"\n",
        "  !mv \"/content/{model_name}.zip\" \"{EXPORT_PATH}\" && echo \"Exported model to {EXPORT_PATH}/{model_name}.zip\"\n",
        "else:\n",
        "  !echo \"Drive not mounted, exporting model to /content/{model_name}.zip\""
      ]
    }
  ],
  "metadata": {
    "accelerator": "GPU",
    "colab": {
      "collapsed_sections": [
        "ymMCTSD6m8qV"
      ],
      "private_outputs": true,
      "provenance": [],
      "toc_visible": true
    },
    "kernelspec": {
      "display_name": "Python 3",
      "name": "python3"
    },
    "language_info": {
      "name": "python"
    }
  },
  "nbformat": 4,
  "nbformat_minor": 0
}