File size: 11,656 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
{
  "cells": [
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "ymhGfgFSR17k"
      },
      "source": [
        "## **Applio**\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",
      "source": [
        "### **Install Applio**\n",
        "If the runtime restarts, re-run the installation steps."
      ],
      "metadata": {
        "id": "NXXzfHi7Db-y"
      }
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "cellView": "form",
        "id": "19LNv6iYqF6_"
      },
      "outputs": [],
      "source": [
        "# @title Mount 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\")"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "cellView": "form",
        "id": "vtON700qokuQ"
      },
      "outputs": [],
      "source": [
        "# @title Setup runtime environment\n",
        "from IPython.display import clear_output\n",
        "import codecs\n",
        "\n",
        "encoded_url = \"uggcf://tvguho.pbz/VNUvfcnab/Nccyvb/\"\n",
        "decoded_url = codecs.decode(encoded_url, \"rot_13\")\n",
        "\n",
        "repo_name_encoded = \"Nccyvb\"\n",
        "repo_name = codecs.decode(repo_name_encoded, \"rot_13\")\n",
        "\n",
        "LOGS_PATH = f\"/content/{repo_name}/logs\"\n",
        "BACKUPS_PATH = f\"/content/drive/MyDrive/{repo_name}Backup\"\n",
        "\n",
        "%cd /content\n",
        "!git config --global advice.detachedHead false\n",
        "!git clone {decoded_url} --single-branch\n",
        "%cd {repo_name}\n",
        "!git checkout 8e161d2baffd145782241c8b1779f77d1bf7a06d\n",
        "clear_output()\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 ngrok jupyter-ui-poll\n",
        "!npm install -g -q localtunnel &> /dev/null\n",
        "\n",
        "!python core.py \"prerequisites\" --models \"True\" --pretraineds_hifigan \"True\"\n",
        "print(\"βœ… Finished installing requirements!\")\n"
      ]
    },
    {
      "cell_type": "markdown",
      "source": [
        "### **Start Applio**"
      ],
      "metadata": {
        "id": "IlM6ll0WDuOG"
      }
    },
    {
      "cell_type": "code",
      "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\")"
      ],
      "metadata": {
        "cellView": "form",
        "id": "2miFQtlfiWy_"
      },
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "cellView": "form",
        "id": "nAlXiNYnFH9F"
      },
      "outputs": [],
      "source": [
        "# @title **Start server**\n",
        "# @markdown  ### Choose a sharing method:\n",
        "from IPython.display import clear_output\n",
        "\n",
        "method = \"gradio\"  # @param [\"gradio\", \"localtunnel\", \"ngrok\"]\n",
        "ngrok_token = \"If you selected the 'ngrok' method, obtain your auth token here: https://dashboard.ngrok.com/get-started/your-authtoken\" # @param {type:\"string\"}\n",
        "tensorboard = True #@param {type: \"boolean\"}\n",
        "\n",
        "%cd /content/{repo_name}\n",
        "clear_output()\n",
        "\n",
        "if tensorboard:\n",
        "  %load_ext tensorboard\n",
        "  %tensorboard --logdir logs --bind_all\n",
        "\n",
        "match method:\n",
        "  case 'gradio':\n",
        "    !python app.py --listen --share\n",
        "  case 'localtunnel':\n",
        "    !echo Password IP: $(curl --silent https://ipv4.icanhazip.com)\n",
        "    !lt --port 6969 & python app.py --listen & echo\n",
        "  case 'ngrok':\n",
        "    import ngrok\n",
        "    ngrok.kill()\n",
        "    listener = await ngrok.forward(6969, authtoken=ngrok_token)\n",
        "    print(f\"Ngrok URL: {listener.url()}\")\n",
        "    !python app.py --listen"
      ]
    }
  ],
  "metadata": {
    "accelerator": "GPU",
    "colab": {
      "collapsed_sections": [
        "NXXzfHi7Db-y"
      ],
      "provenance": [],
      "private_outputs": true
    },
    "kernelspec": {
      "display_name": "Python 3",
      "name": "python3"
    },
    "language_info": {
      "name": "python"
    }
  },
  "nbformat": 4,
  "nbformat_minor": 0
}