Spaces:
Sleeping
Sleeping
Update ngrok regex match and add ngrok auth
Browse files- notebooks/AudioPalette.ipynb +50 -37
- utils/audio_palette.py +1 -1
notebooks/AudioPalette.ipynb
CHANGED
|
@@ -2,12 +2,12 @@
|
|
| 2 |
"cells": [
|
| 3 |
{
|
| 4 |
"cell_type": "markdown",
|
| 5 |
-
"metadata": {
|
| 6 |
-
"id": "w4LtdMb23tZ4"
|
| 7 |
-
},
|
| 8 |
"source": [
|
| 9 |
"## Prerequisites"
|
| 10 |
-
]
|
|
|
|
|
|
|
|
|
|
| 11 |
},
|
| 12 |
{
|
| 13 |
"cell_type": "markdown",
|
|
@@ -43,11 +43,6 @@
|
|
| 43 |
},
|
| 44 |
{
|
| 45 |
"cell_type": "code",
|
| 46 |
-
"execution_count": null,
|
| 47 |
-
"metadata": {
|
| 48 |
-
"id": "Nl0CQxwHCrFd"
|
| 49 |
-
},
|
| 50 |
-
"outputs": [],
|
| 51 |
"source": [
|
| 52 |
"!pip install typing-extensions==4.5.0\n",
|
| 53 |
"!pip install python-multipart\n",
|
|
@@ -57,7 +52,12 @@
|
|
| 57 |
"!pip install fastapi\n",
|
| 58 |
"!pip install \"uvicorn[standard]\"\n",
|
| 59 |
"!pip install pyngrok"
|
| 60 |
-
]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 61 |
},
|
| 62 |
{
|
| 63 |
"cell_type": "markdown",
|
|
@@ -110,20 +110,15 @@
|
|
| 110 |
},
|
| 111 |
{
|
| 112 |
"cell_type": "markdown",
|
| 113 |
-
"metadata": {
|
| 114 |
-
"id": "8nydshMdxKab"
|
| 115 |
-
},
|
| 116 |
"source": [
|
| 117 |
"#### Model Class"
|
| 118 |
-
]
|
|
|
|
|
|
|
|
|
|
| 119 |
},
|
| 120 |
{
|
| 121 |
"cell_type": "code",
|
| 122 |
-
"execution_count": null,
|
| 123 |
-
"metadata": {
|
| 124 |
-
"id": "4V49E7xpxNPu"
|
| 125 |
-
},
|
| 126 |
-
"outputs": [],
|
| 127 |
"source": [
|
| 128 |
"import numpy as np\n",
|
| 129 |
"import typing\n",
|
|
@@ -137,7 +132,7 @@
|
|
| 137 |
"\n",
|
| 138 |
" def generate(self):\n",
|
| 139 |
" if isinstance(self.caption, str):\n",
|
| 140 |
-
" return self.generate_single()\n",
|
| 141 |
" else:\n",
|
| 142 |
" return self.generate_multiple()\n",
|
| 143 |
"\n",
|
|
@@ -174,18 +169,23 @@
|
|
| 174 |
" else:\n",
|
| 175 |
" audio = self.generate_audio_with_melody_conditioning(prompt, audio)\n",
|
| 176 |
" return audio"
|
| 177 |
-
]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 178 |
},
|
| 179 |
{
|
| 180 |
"cell_type": "code",
|
| 181 |
-
"
|
|
|
|
|
|
|
| 182 |
"metadata": {
|
| 183 |
"id": "qW65Q68o-R7f"
|
| 184 |
},
|
| 185 |
-
"
|
| 186 |
-
"
|
| 187 |
-
"audiopalette = AudioPalette()"
|
| 188 |
-
]
|
| 189 |
},
|
| 190 |
{
|
| 191 |
"cell_type": "markdown",
|
|
@@ -221,11 +221,6 @@
|
|
| 221 |
},
|
| 222 |
{
|
| 223 |
"cell_type": "code",
|
| 224 |
-
"execution_count": null,
|
| 225 |
-
"metadata": {
|
| 226 |
-
"id": "iYUH3-GpfbN8"
|
| 227 |
-
},
|
| 228 |
-
"outputs": [],
|
| 229 |
"source": [
|
| 230 |
"import typing\n",
|
| 231 |
"import numpy as np\n",
|
|
@@ -241,7 +236,12 @@
|
|
| 241 |
"\n",
|
| 242 |
"# class Config:\n",
|
| 243 |
"# arbitrary_types_allowed = True"
|
| 244 |
-
]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 245 |
},
|
| 246 |
{
|
| 247 |
"cell_type": "code",
|
|
@@ -297,11 +297,25 @@
|
|
| 297 |
},
|
| 298 |
"outputs": [],
|
| 299 |
"source": [
|
|
|
|
|
|
|
| 300 |
"import nest_asyncio\n",
|
| 301 |
-
"
|
| 302 |
-
"import
|
| 303 |
]
|
| 304 |
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 305 |
{
|
| 306 |
"cell_type": "code",
|
| 307 |
"execution_count": null,
|
|
@@ -341,8 +355,7 @@
|
|
| 341 |
"accelerator": "GPU",
|
| 342 |
"colab": {
|
| 343 |
"collapsed_sections": [
|
| 344 |
-
"w4LtdMb23tZ4"
|
| 345 |
-
"46yDPBYqpYYN"
|
| 346 |
],
|
| 347 |
"gpuType": "T4",
|
| 348 |
"provenance": []
|
|
@@ -366,4 +379,4 @@
|
|
| 366 |
},
|
| 367 |
"nbformat": 4,
|
| 368 |
"nbformat_minor": 0
|
| 369 |
-
}
|
|
|
|
| 2 |
"cells": [
|
| 3 |
{
|
| 4 |
"cell_type": "markdown",
|
|
|
|
|
|
|
|
|
|
| 5 |
"source": [
|
| 6 |
"## Prerequisites"
|
| 7 |
+
],
|
| 8 |
+
"metadata": {
|
| 9 |
+
"id": "w4LtdMb23tZ4"
|
| 10 |
+
}
|
| 11 |
},
|
| 12 |
{
|
| 13 |
"cell_type": "markdown",
|
|
|
|
| 43 |
},
|
| 44 |
{
|
| 45 |
"cell_type": "code",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 46 |
"source": [
|
| 47 |
"!pip install typing-extensions==4.5.0\n",
|
| 48 |
"!pip install python-multipart\n",
|
|
|
|
| 52 |
"!pip install fastapi\n",
|
| 53 |
"!pip install \"uvicorn[standard]\"\n",
|
| 54 |
"!pip install pyngrok"
|
| 55 |
+
],
|
| 56 |
+
"metadata": {
|
| 57 |
+
"id": "Nl0CQxwHCrFd"
|
| 58 |
+
},
|
| 59 |
+
"execution_count": null,
|
| 60 |
+
"outputs": []
|
| 61 |
},
|
| 62 |
{
|
| 63 |
"cell_type": "markdown",
|
|
|
|
| 110 |
},
|
| 111 |
{
|
| 112 |
"cell_type": "markdown",
|
|
|
|
|
|
|
|
|
|
| 113 |
"source": [
|
| 114 |
"#### Model Class"
|
| 115 |
+
],
|
| 116 |
+
"metadata": {
|
| 117 |
+
"id": "8nydshMdxKab"
|
| 118 |
+
}
|
| 119 |
},
|
| 120 |
{
|
| 121 |
"cell_type": "code",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 122 |
"source": [
|
| 123 |
"import numpy as np\n",
|
| 124 |
"import typing\n",
|
|
|
|
| 132 |
"\n",
|
| 133 |
" def generate(self):\n",
|
| 134 |
" if isinstance(self.caption, str):\n",
|
| 135 |
+
" return self.generate_single(max_new_tokens=1024)\n",
|
| 136 |
" else:\n",
|
| 137 |
" return self.generate_multiple()\n",
|
| 138 |
"\n",
|
|
|
|
| 169 |
" else:\n",
|
| 170 |
" audio = self.generate_audio_with_melody_conditioning(prompt, audio)\n",
|
| 171 |
" return audio"
|
| 172 |
+
],
|
| 173 |
+
"metadata": {
|
| 174 |
+
"id": "4V49E7xpxNPu"
|
| 175 |
+
},
|
| 176 |
+
"execution_count": null,
|
| 177 |
+
"outputs": []
|
| 178 |
},
|
| 179 |
{
|
| 180 |
"cell_type": "code",
|
| 181 |
+
"source": [
|
| 182 |
+
"audiopalette = AudioPalette()"
|
| 183 |
+
],
|
| 184 |
"metadata": {
|
| 185 |
"id": "qW65Q68o-R7f"
|
| 186 |
},
|
| 187 |
+
"execution_count": null,
|
| 188 |
+
"outputs": []
|
|
|
|
|
|
|
| 189 |
},
|
| 190 |
{
|
| 191 |
"cell_type": "markdown",
|
|
|
|
| 221 |
},
|
| 222 |
{
|
| 223 |
"cell_type": "code",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 224 |
"source": [
|
| 225 |
"import typing\n",
|
| 226 |
"import numpy as np\n",
|
|
|
|
| 236 |
"\n",
|
| 237 |
"# class Config:\n",
|
| 238 |
"# arbitrary_types_allowed = True"
|
| 239 |
+
],
|
| 240 |
+
"metadata": {
|
| 241 |
+
"id": "iYUH3-GpfbN8"
|
| 242 |
+
},
|
| 243 |
+
"execution_count": null,
|
| 244 |
+
"outputs": []
|
| 245 |
},
|
| 246 |
{
|
| 247 |
"cell_type": "code",
|
|
|
|
| 297 |
},
|
| 298 |
"outputs": [],
|
| 299 |
"source": [
|
| 300 |
+
"from getpass import getpass\n",
|
| 301 |
+
"\n",
|
| 302 |
"import nest_asyncio\n",
|
| 303 |
+
"import uvicorn\n",
|
| 304 |
+
"from pyngrok import ngrok"
|
| 305 |
]
|
| 306 |
},
|
| 307 |
+
{
|
| 308 |
+
"cell_type": "code",
|
| 309 |
+
"source": [
|
| 310 |
+
"ngrok_auth_token = getpass(prompt=\"Enter ngrok auth token: \")\n",
|
| 311 |
+
"ngrok.set_auth_token(ngrok_auth_token)"
|
| 312 |
+
],
|
| 313 |
+
"metadata": {
|
| 314 |
+
"id": "QFDDncCJEs4f"
|
| 315 |
+
},
|
| 316 |
+
"execution_count": null,
|
| 317 |
+
"outputs": []
|
| 318 |
+
},
|
| 319 |
{
|
| 320 |
"cell_type": "code",
|
| 321 |
"execution_count": null,
|
|
|
|
| 355 |
"accelerator": "GPU",
|
| 356 |
"colab": {
|
| 357 |
"collapsed_sections": [
|
| 358 |
+
"w4LtdMb23tZ4"
|
|
|
|
| 359 |
],
|
| 360 |
"gpuType": "T4",
|
| 361 |
"provenance": []
|
|
|
|
| 379 |
},
|
| 380 |
"nbformat": 4,
|
| 381 |
"nbformat_minor": 0
|
| 382 |
+
}
|
utils/audio_palette.py
CHANGED
|
@@ -27,7 +27,7 @@ class AudioPalette:
|
|
| 27 |
"Medium": "medium",
|
| 28 |
"Slow": "low"
|
| 29 |
}
|
| 30 |
-
self.ngrok_url_pattern = re.compile("https:\/\/[a-z0-9\-]+\.ngrok\.io\/")
|
| 31 |
|
| 32 |
def prompt_construction(self, caption: str, pace: str, sentiment: typing.Union[str, None], instrument: typing.Union[str, None], first: bool = True):
|
| 33 |
instrument = instrument if instrument is not None else ""
|
|
|
|
| 27 |
"Medium": "medium",
|
| 28 |
"Slow": "low"
|
| 29 |
}
|
| 30 |
+
self.ngrok_url_pattern = re.compile("(https:\/\/[a-z0-9\-]+\.ngrok\.io\/)|(https:\/\/[a-z0-9\-]+\.ngrok-free.app\/)")
|
| 31 |
|
| 32 |
def prompt_construction(self, caption: str, pace: str, sentiment: typing.Union[str, None], instrument: typing.Union[str, None], first: bool = True):
|
| 33 |
instrument = instrument if instrument is not None else ""
|