File size: 45,901 Bytes
bd25455
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "cb5d0890-3f2d-4020-8270-f3a9bb9f63c6",
   "metadata": {},
   "outputs": [],
   "source": [
    "%%bash # install the vall-e and required libraries\n",
    "# PyTorch\n",
    "pip install torch==1.13.1 torchaudio==0.13.1 --extra-index-url https://download.pytorch.org/whl/cu116\n",
    "pip install torchmetrics==0.11.1\n",
    "# fbank\n",
    "pip install librosa==0.8.1\n",
    "\n",
    "# phonemizer pypinyin\n",
    "apt-get install espeak-ng\n",
    "## OSX: brew install espeak\n",
    "pip install phonemizer==3.2.1 pypinyin==0.48.0\n",
    "\n",
    "# lhotse update to newest version\n",
    "# https://github.com/lhotse-speech/lhotse/pull/956\n",
    "# https://github.com/lhotse-speech/lhotse/pull/960\n",
    "pip uninstall lhotse\n",
    "pip install lhotse\n",
    "\n",
    "# k2\n",
    "# find the right version in https://huggingface.co/csukuangfj/k2\n",
    "pip install https://huggingface.co/csukuangfj/k2/resolve/main/cuda/k2-1.23.4.dev20230224+cuda11.6.torch1.13.1-cp310-cp310-linux_x86_64.whl\n",
    "\n",
    "# icefall\n",
    "git clone https://github.com/k2-fsa/icefall\n",
    "cd icefall\n",
    "pip install -r requirements.txt\n",
    "export PYTHONPATH=`pwd`/../icefall:$PYTHONPATH\n",
    "echo \"export PYTHONPATH=`pwd`/../icefall:\\$PYTHONPATH\" >> ~/.zshrc\n",
    "echo \"export PYTHONPATH=`pwd`/../icefall:\\$PYTHONPATH\" >> ~/.bashrc\n",
    "cd -\n",
    "source ~/.zshrc\n",
    "\n",
    "# valle\n",
    "git clone https://github.com/lifeiteng/valle.git\n",
    "cd valle\n",
    "pip install -e ."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "1b8a4af2-5851-4c41-96bb-bda4b259f857",
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "/home/dongsun/.local/lib/python3.10/site-packages/torchvision/io/image.py:13: UserWarning: Failed to load image Python extension: '/home/dongsun/.local/lib/python3.10/site-packages/torchvision/image.so: undefined symbol: _ZN3c104cuda20CUDACachingAllocator9allocatorE'If you don't plan on using image functionality from `torchvision.io`, you can ignore this warning. Otherwise, there might be something wrong with your environment. Did you have `libjpeg` or `libpng` installed before building `torchvision` from source?\n",
      "  warn(\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[2023-09-21 14:36:33,978] [INFO] [real_accelerator.py:133:get_accelerator] Setting ds_accelerator to cuda (auto detect)\n",
      "Use 8 cpu cores for computing\n"
     ]
    }
   ],
   "source": [
    "import argparse\n",
    "import logging\n",
    "import os\n",
    "import pathlib\n",
    "import time\n",
    "import tempfile\n",
    "import platform\n",
    "import webbrowser\n",
    "import sys\n",
    "import torch, torchaudio\n",
    "import random\n",
    "\n",
    "import numpy as np\n",
    "\n",
    "from valle.data import (\n",
    "    AudioTokenizer,\n",
    "    TextTokenizer,\n",
    "    tokenize_audio,\n",
    "    tokenize_text,\n",
    ")\n",
    "from icefall.utils import AttributeDict\n",
    "from valle.data.collation import get_text_token_collater\n",
    "from valle.models import get_model\n",
    "\n",
    "from vocos import Vocos\n",
    "from encodec.utils import convert_audio\n",
    "import multiprocessing\n",
    "\n",
    "thread_count = multiprocessing.cpu_count()\n",
    "\n",
    "print(\"Use\",thread_count,\"cpu cores for computing\")\n",
    "\n",
    "torch.set_num_threads(thread_count)\n",
    "torch.set_num_interop_threads(thread_count)\n",
    "torch._C._jit_set_profiling_executor(False)\n",
    "torch._C._jit_set_profiling_mode(False)\n",
    "torch._C._set_graph_executor_optimize(False)\n",
    "\n",
    "text_tokenizer = TextTokenizer(language='ko')\n",
    "\n",
    "device = torch.device(\"cpu\")\n",
    "if torch.cuda.is_available():\n",
    "    device = torch.device(\"cuda\", 0)\n",
    "\n",
    "checkpoint = torch.load(\"./vall-e_ko_v0.pt\", map_location='cpu')\n",
    "model = get_model(AttributeDict(checkpoint))\n",
    "missing_keys, unexpected_keys = model.load_state_dict(\n",
    "    checkpoint[\"model\"], strict=True\n",
    ")\n",
    "assert not missing_keys\n",
    "model.eval()\n",
    "model.to(device)\n",
    "text_collater = get_text_token_collater('./unique_text_tokens.k2symbols')\n",
    "\n",
    "# Encodec model\n",
    "audio_tokenizer = AudioTokenizer(device)\n",
    "\n",
    "# Vocos decoder\n",
    "vocos = Vocos.from_pretrained('charactr/vocos-encodec-24khz').to(device)\n",
    "\n",
    "model.to(device)\n",
    "@torch.no_grad()\n",
    "def infer_from_prompt(text_prompt, audio_prompt, text):\n",
    "    ## text to token\n",
    "    text_tokens, text_tokens_lens = text_collater(\n",
    "        [\n",
    "            tokenize_text(\n",
    "                text_tokenizer, text=f\"{text_prompt} {text}\".strip()\n",
    "            )\n",
    "        ]\n",
    "    )\n",
    "    _, enroll_x_lens = text_collater(\n",
    "        [\n",
    "            tokenize_text(\n",
    "                text_tokenizer, text=f\"{text_prompt}\".strip()\n",
    "            )\n",
    "        ]\n",
    "    )\n",
    "    print('text_loaded')\n",
    "\n",
    "    # text to synthesize\n",
    "    wav_pr, sr = torchaudio.load(audio_prompt)\n",
    "    wav_pr = convert_audio(wav_pr, sr, audio_tokenizer.sample_rate, audio_tokenizer.channels)\n",
    "    audio_prompts = audio_tokenizer.encode(wav_pr.unsqueeze(0))[0][0].transpose(2, 1).to(device)\n",
    "    print('Audio encoded')\n",
    "\n",
    "    encoded_frames = model.inference(\n",
    "        text_tokens.to(device), text_tokens_lens.to(device),\n",
    "        audio_prompts, enroll_x_lens=enroll_x_lens,\n",
    "        top_k=-100, temperature=1)\n",
    "    vocos_features = vocos.codes_to_features(encoded_frames.permute(2, 0, 1))\n",
    "    samples = vocos.decode(vocos_features, bandwidth_id=torch.tensor([2], device=device))\n",
    "    message = f\"sythesized text: {text}\"\n",
    "    return message, (24000, samples.squeeze(0).cpu().numpy())\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "fa6e2e1d-7522-43f0-985c-e731047acd9c",
   "metadata": {},
   "source": [
    "# Example"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "41e40fe5-595e-4f9a-8dd7-dfda52944529",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"><span style=\"color: #800000; text-decoration-color: #800000\">โ•ญโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ </span><span style=\"color: #800000; text-decoration-color: #800000; font-weight: bold\">Traceback </span><span style=\"color: #bf7f7f; text-decoration-color: #bf7f7f; font-weight: bold\">(most recent call last)</span><span style=\"color: #800000; text-decoration-color: #800000\"> โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฎ</span>\n",
       "<span style=\"color: #800000; text-decoration-color: #800000\">โ”‚</span> in <span style=\"color: #00ff00; text-decoration-color: #00ff00\">&lt;module&gt;</span>                                                                                      <span style=\"color: #800000; text-decoration-color: #800000\">โ”‚</span>\n",
       "<span style=\"color: #800000; text-decoration-color: #800000\">โ”‚</span>                                                                                                  <span style=\"color: #800000; text-decoration-color: #800000\">โ”‚</span>\n",
       "<span style=\"color: #800000; text-decoration-color: #800000\">โ”‚</span>   <span style=\"color: #7f7f7f; text-decoration-color: #7f7f7f\">1 </span>text_prompt = <span style=\"color: #808000; text-decoration-color: #808000\">''</span> <span style=\"color: #7f7f7f; text-decoration-color: #7f7f7f\"># text of the audio </span>                                                        <span style=\"color: #800000; text-decoration-color: #800000\">โ”‚</span>\n",
       "<span style=\"color: #800000; text-decoration-color: #800000\">โ”‚</span>   <span style=\"color: #7f7f7f; text-decoration-color: #7f7f7f\">2 </span>audio_prompt = <span style=\"color: #808000; text-decoration-color: #808000\">''</span> <span style=\"color: #7f7f7f; text-decoration-color: #7f7f7f\"># path to the audio file</span>                                                   <span style=\"color: #800000; text-decoration-color: #800000\">โ”‚</span>\n",
       "<span style=\"color: #800000; text-decoration-color: #800000\">โ”‚</span>   <span style=\"color: #7f7f7f; text-decoration-color: #7f7f7f\">3 </span>text = <span style=\"color: #808000; text-decoration-color: #808000\">''</span> <span style=\"color: #7f7f7f; text-decoration-color: #7f7f7f\"># </span>                                                                                 <span style=\"color: #800000; text-decoration-color: #800000\">โ”‚</span>\n",
       "<span style=\"color: #800000; text-decoration-color: #800000\">โ”‚</span> <span style=\"color: #800000; text-decoration-color: #800000\">โฑ </span>4 message, (sr, data) = infer_from_prompt(text_prompt, audio_prompt, text)                     <span style=\"color: #800000; text-decoration-color: #800000\">โ”‚</span>\n",
       "<span style=\"color: #800000; text-decoration-color: #800000\">โ”‚</span>   <span style=\"color: #7f7f7f; text-decoration-color: #7f7f7f\">5 </span>                                                                                             <span style=\"color: #800000; text-decoration-color: #800000\">โ”‚</span>\n",
       "<span style=\"color: #800000; text-decoration-color: #800000\">โ”‚</span>                                                                                                  <span style=\"color: #800000; text-decoration-color: #800000\">โ”‚</span>\n",
       "<span style=\"color: #800000; text-decoration-color: #800000\">โ”‚</span> <span style=\"color: #bfbf7f; text-decoration-color: #bfbf7f\">/home/dongsun/.local/lib/python3.10/site-packages/torch/autograd/</span><span style=\"color: #808000; text-decoration-color: #808000; font-weight: bold\">grad_mode.py</span>:<span style=\"color: #0000ff; text-decoration-color: #0000ff\">27</span> in              <span style=\"color: #800000; text-decoration-color: #800000\">โ”‚</span>\n",
       "<span style=\"color: #800000; text-decoration-color: #800000\">โ”‚</span> <span style=\"color: #00ff00; text-decoration-color: #00ff00\">decorate_context</span>                                                                                 <span style=\"color: #800000; text-decoration-color: #800000\">โ”‚</span>\n",
       "<span style=\"color: #800000; text-decoration-color: #800000\">โ”‚</span>                                                                                                  <span style=\"color: #800000; text-decoration-color: #800000\">โ”‚</span>\n",
       "<span style=\"color: #800000; text-decoration-color: #800000\">โ”‚</span>   <span style=\"color: #7f7f7f; text-decoration-color: #7f7f7f\"> 24 โ”‚   โ”‚   </span><span style=\"color: #ff00ff; text-decoration-color: #ff00ff; font-weight: bold\">@functools</span>.wraps(func)                                                             <span style=\"color: #800000; text-decoration-color: #800000\">โ”‚</span>\n",
       "<span style=\"color: #800000; text-decoration-color: #800000\">โ”‚</span>   <span style=\"color: #7f7f7f; text-decoration-color: #7f7f7f\"> 25 โ”‚   โ”‚   </span><span style=\"color: #0000ff; text-decoration-color: #0000ff\">def</span> <span style=\"color: #00ff00; text-decoration-color: #00ff00\">decorate_context</span>(*args, **kwargs):                                             <span style=\"color: #800000; text-decoration-color: #800000\">โ”‚</span>\n",
       "<span style=\"color: #800000; text-decoration-color: #800000\">โ”‚</span>   <span style=\"color: #7f7f7f; text-decoration-color: #7f7f7f\"> 26 โ”‚   โ”‚   โ”‚   </span><span style=\"color: #0000ff; text-decoration-color: #0000ff\">with</span> <span style=\"color: #00ffff; text-decoration-color: #00ffff\">self</span>.clone():                                                             <span style=\"color: #800000; text-decoration-color: #800000\">โ”‚</span>\n",
       "<span style=\"color: #800000; text-decoration-color: #800000\">โ”‚</span> <span style=\"color: #800000; text-decoration-color: #800000\">โฑ </span> 27 <span style=\"color: #7f7f7f; text-decoration-color: #7f7f7f\">โ”‚   โ”‚   โ”‚   โ”‚   </span><span style=\"color: #0000ff; text-decoration-color: #0000ff\">return</span> func(*args, **kwargs)                                               <span style=\"color: #800000; text-decoration-color: #800000\">โ”‚</span>\n",
       "<span style=\"color: #800000; text-decoration-color: #800000\">โ”‚</span>   <span style=\"color: #7f7f7f; text-decoration-color: #7f7f7f\"> 28 โ”‚   โ”‚   </span><span style=\"color: #0000ff; text-decoration-color: #0000ff\">return</span> cast(F, decorate_context)                                                   <span style=\"color: #800000; text-decoration-color: #800000\">โ”‚</span>\n",
       "<span style=\"color: #800000; text-decoration-color: #800000\">โ”‚</span>   <span style=\"color: #7f7f7f; text-decoration-color: #7f7f7f\"> 29 โ”‚   </span>                                                                                       <span style=\"color: #800000; text-decoration-color: #800000\">โ”‚</span>\n",
       "<span style=\"color: #800000; text-decoration-color: #800000\">โ”‚</span>   <span style=\"color: #7f7f7f; text-decoration-color: #7f7f7f\"> 30 โ”‚   </span><span style=\"color: #0000ff; text-decoration-color: #0000ff\">def</span> <span style=\"color: #00ff00; text-decoration-color: #00ff00\">_wrap_generator</span>(<span style=\"color: #00ffff; text-decoration-color: #00ffff\">self</span>, func):                                                       <span style=\"color: #800000; text-decoration-color: #800000\">โ”‚</span>\n",
       "<span style=\"color: #800000; text-decoration-color: #800000\">โ”‚</span>                                                                                                  <span style=\"color: #800000; text-decoration-color: #800000\">โ”‚</span>\n",
       "<span style=\"color: #800000; text-decoration-color: #800000\">โ”‚</span> in <span style=\"color: #00ff00; text-decoration-color: #00ff00\">infer_from_prompt</span>                                                                             <span style=\"color: #800000; text-decoration-color: #800000\">โ”‚</span>\n",
       "<span style=\"color: #800000; text-decoration-color: #800000\">โ”‚</span>                                                                                                  <span style=\"color: #800000; text-decoration-color: #800000\">โ”‚</span>\n",
       "<span style=\"color: #800000; text-decoration-color: #800000\">โ”‚</span>   <span style=\"color: #7f7f7f; text-decoration-color: #7f7f7f\">64 โ”‚   ## text to token</span>                                                                        <span style=\"color: #800000; text-decoration-color: #800000\">โ”‚</span>\n",
       "<span style=\"color: #800000; text-decoration-color: #800000\">โ”‚</span>   <span style=\"color: #7f7f7f; text-decoration-color: #7f7f7f\">65 โ”‚   </span>text_tokens, text_tokens_lens = text_collater(                                          <span style=\"color: #800000; text-decoration-color: #800000\">โ”‚</span>\n",
       "<span style=\"color: #800000; text-decoration-color: #800000\">โ”‚</span>   <span style=\"color: #7f7f7f; text-decoration-color: #7f7f7f\">66 โ”‚   โ”‚   </span>[                                                                                   <span style=\"color: #800000; text-decoration-color: #800000\">โ”‚</span>\n",
       "<span style=\"color: #800000; text-decoration-color: #800000\">โ”‚</span> <span style=\"color: #800000; text-decoration-color: #800000\">โฑ </span>67 <span style=\"color: #7f7f7f; text-decoration-color: #7f7f7f\">โ”‚   โ”‚   โ”‚   </span>tokenize_text(                                                                  <span style=\"color: #800000; text-decoration-color: #800000\">โ”‚</span>\n",
       "<span style=\"color: #800000; text-decoration-color: #800000\">โ”‚</span>   <span style=\"color: #7f7f7f; text-decoration-color: #7f7f7f\">68 โ”‚   โ”‚   โ”‚   โ”‚   </span>text_tokenizer, text=<span style=\"color: #808000; text-decoration-color: #808000\">f\"{</span>text_prompt<span style=\"color: #808000; text-decoration-color: #808000\">} {</span>text<span style=\"color: #808000; text-decoration-color: #808000\">}\"</span>.strip()                        <span style=\"color: #800000; text-decoration-color: #800000\">โ”‚</span>\n",
       "<span style=\"color: #800000; text-decoration-color: #800000\">โ”‚</span>   <span style=\"color: #7f7f7f; text-decoration-color: #7f7f7f\">69 โ”‚   โ”‚   โ”‚   </span>)                                                                               <span style=\"color: #800000; text-decoration-color: #800000\">โ”‚</span>\n",
       "<span style=\"color: #800000; text-decoration-color: #800000\">โ”‚</span>   <span style=\"color: #7f7f7f; text-decoration-color: #7f7f7f\">70 โ”‚   โ”‚   </span>]                                                                                   <span style=\"color: #800000; text-decoration-color: #800000\">โ”‚</span>\n",
       "<span style=\"color: #800000; text-decoration-color: #800000\">โ”‚</span>                                                                                                  <span style=\"color: #800000; text-decoration-color: #800000\">โ”‚</span>\n",
       "<span style=\"color: #800000; text-decoration-color: #800000\">โ”‚</span> <span style=\"color: #bfbf7f; text-decoration-color: #bfbf7f\">/home/dongsun/vall-e/valle/data/</span><span style=\"color: #808000; text-decoration-color: #808000; font-weight: bold\">tokenizer.py</span>:<span style=\"color: #0000ff; text-decoration-color: #0000ff\">178</span> in <span style=\"color: #00ff00; text-decoration-color: #00ff00\">tokenize_text</span>                                <span style=\"color: #800000; text-decoration-color: #800000\">โ”‚</span>\n",
       "<span style=\"color: #800000; text-decoration-color: #800000\">โ”‚</span>                                                                                                  <span style=\"color: #800000; text-decoration-color: #800000\">โ”‚</span>\n",
       "<span style=\"color: #800000; text-decoration-color: #800000\">โ”‚</span>   <span style=\"color: #7f7f7f; text-decoration-color: #7f7f7f\">175 </span>                                                                                           <span style=\"color: #800000; text-decoration-color: #800000\">โ”‚</span>\n",
       "<span style=\"color: #800000; text-decoration-color: #800000\">โ”‚</span>   <span style=\"color: #7f7f7f; text-decoration-color: #7f7f7f\">176 </span><span style=\"color: #0000ff; text-decoration-color: #0000ff\">def</span> <span style=\"color: #00ff00; text-decoration-color: #00ff00\">tokenize_text</span>(tokenizer: TextTokenizer, text: <span style=\"color: #00ffff; text-decoration-color: #00ffff\">str</span>) -&gt; List[<span style=\"color: #00ffff; text-decoration-color: #00ffff\">str</span>]:                       <span style=\"color: #800000; text-decoration-color: #800000\">โ”‚</span>\n",
       "<span style=\"color: #800000; text-decoration-color: #800000\">โ”‚</span>   <span style=\"color: #7f7f7f; text-decoration-color: #7f7f7f\">177 โ”‚   </span>phonemes = tokenizer([text.strip()])                                                   <span style=\"color: #800000; text-decoration-color: #800000\">โ”‚</span>\n",
       "<span style=\"color: #800000; text-decoration-color: #800000\">โ”‚</span> <span style=\"color: #800000; text-decoration-color: #800000\">โฑ </span>178 <span style=\"color: #7f7f7f; text-decoration-color: #7f7f7f\">โ”‚   </span><span style=\"color: #0000ff; text-decoration-color: #0000ff\">return</span> phonemes[<span style=\"color: #0000ff; text-decoration-color: #0000ff\">0</span>]  <span style=\"color: #7f7f7f; text-decoration-color: #7f7f7f\"># k2symbols</span>                                                        <span style=\"color: #800000; text-decoration-color: #800000\">โ”‚</span>\n",
       "<span style=\"color: #800000; text-decoration-color: #800000\">โ”‚</span>   <span style=\"color: #7f7f7f; text-decoration-color: #7f7f7f\">179 </span>                                                                                           <span style=\"color: #800000; text-decoration-color: #800000\">โ”‚</span>\n",
       "<span style=\"color: #800000; text-decoration-color: #800000\">โ”‚</span>   <span style=\"color: #7f7f7f; text-decoration-color: #7f7f7f\">180 </span>                                                                                           <span style=\"color: #800000; text-decoration-color: #800000\">โ”‚</span>\n",
       "<span style=\"color: #800000; text-decoration-color: #800000\">โ”‚</span>   <span style=\"color: #7f7f7f; text-decoration-color: #7f7f7f\">181 </span><span style=\"color: #0000ff; text-decoration-color: #0000ff\">def</span> <span style=\"color: #00ff00; text-decoration-color: #00ff00\">remove_encodec_weight_norm</span>(model):                                                     <span style=\"color: #800000; text-decoration-color: #800000\">โ”‚</span>\n",
       "<span style=\"color: #800000; text-decoration-color: #800000\">โ•ฐโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฏ</span>\n",
       "<span style=\"color: #ff0000; text-decoration-color: #ff0000; font-weight: bold\">IndexError: </span>list index out of range\n",
       "</pre>\n"
      ],
      "text/plain": [
       "\u001b[31mโ•ญโ”€\u001b[0m\u001b[31mโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€\u001b[0m\u001b[31m \u001b[0m\u001b[1;31mTraceback \u001b[0m\u001b[1;2;31m(most recent call last)\u001b[0m\u001b[31m \u001b[0m\u001b[31mโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€\u001b[0m\u001b[31mโ”€โ•ฎ\u001b[0m\n",
       "\u001b[31mโ”‚\u001b[0m in \u001b[92m<module>\u001b[0m                                                                                      \u001b[31mโ”‚\u001b[0m\n",
       "\u001b[31mโ”‚\u001b[0m                                                                                                  \u001b[31mโ”‚\u001b[0m\n",
       "\u001b[31mโ”‚\u001b[0m   \u001b[2m1 \u001b[0mtext_prompt = \u001b[33m'\u001b[0m\u001b[33m'\u001b[0m \u001b[2m# text of the audio \u001b[0m                                                        \u001b[31mโ”‚\u001b[0m\n",
       "\u001b[31mโ”‚\u001b[0m   \u001b[2m2 \u001b[0maudio_prompt = \u001b[33m'\u001b[0m\u001b[33m'\u001b[0m \u001b[2m# path to the audio file\u001b[0m                                                   \u001b[31mโ”‚\u001b[0m\n",
       "\u001b[31mโ”‚\u001b[0m   \u001b[2m3 \u001b[0mtext = \u001b[33m'\u001b[0m\u001b[33m'\u001b[0m \u001b[2m# \u001b[0m                                                                                 \u001b[31mโ”‚\u001b[0m\n",
       "\u001b[31mโ”‚\u001b[0m \u001b[31mโฑ \u001b[0m4 message, (sr, data) = infer_from_prompt(text_prompt, audio_prompt, text)                     \u001b[31mโ”‚\u001b[0m\n",
       "\u001b[31mโ”‚\u001b[0m   \u001b[2m5 \u001b[0m                                                                                             \u001b[31mโ”‚\u001b[0m\n",
       "\u001b[31mโ”‚\u001b[0m                                                                                                  \u001b[31mโ”‚\u001b[0m\n",
       "\u001b[31mโ”‚\u001b[0m \u001b[2;33m/home/dongsun/.local/lib/python3.10/site-packages/torch/autograd/\u001b[0m\u001b[1;33mgrad_mode.py\u001b[0m:\u001b[94m27\u001b[0m in              \u001b[31mโ”‚\u001b[0m\n",
       "\u001b[31mโ”‚\u001b[0m \u001b[92mdecorate_context\u001b[0m                                                                                 \u001b[31mโ”‚\u001b[0m\n",
       "\u001b[31mโ”‚\u001b[0m                                                                                                  \u001b[31mโ”‚\u001b[0m\n",
       "\u001b[31mโ”‚\u001b[0m   \u001b[2m 24 \u001b[0m\u001b[2mโ”‚   โ”‚   \u001b[0m\u001b[1;95m@functools\u001b[0m.wraps(func)                                                             \u001b[31mโ”‚\u001b[0m\n",
       "\u001b[31mโ”‚\u001b[0m   \u001b[2m 25 \u001b[0m\u001b[2mโ”‚   โ”‚   \u001b[0m\u001b[94mdef\u001b[0m \u001b[92mdecorate_context\u001b[0m(*args, **kwargs):                                             \u001b[31mโ”‚\u001b[0m\n",
       "\u001b[31mโ”‚\u001b[0m   \u001b[2m 26 \u001b[0m\u001b[2mโ”‚   โ”‚   โ”‚   \u001b[0m\u001b[94mwith\u001b[0m \u001b[96mself\u001b[0m.clone():                                                             \u001b[31mโ”‚\u001b[0m\n",
       "\u001b[31mโ”‚\u001b[0m \u001b[31mโฑ \u001b[0m 27 \u001b[2mโ”‚   โ”‚   โ”‚   โ”‚   \u001b[0m\u001b[94mreturn\u001b[0m func(*args, **kwargs)                                               \u001b[31mโ”‚\u001b[0m\n",
       "\u001b[31mโ”‚\u001b[0m   \u001b[2m 28 \u001b[0m\u001b[2mโ”‚   โ”‚   \u001b[0m\u001b[94mreturn\u001b[0m cast(F, decorate_context)                                                   \u001b[31mโ”‚\u001b[0m\n",
       "\u001b[31mโ”‚\u001b[0m   \u001b[2m 29 \u001b[0m\u001b[2mโ”‚   \u001b[0m                                                                                       \u001b[31mโ”‚\u001b[0m\n",
       "\u001b[31mโ”‚\u001b[0m   \u001b[2m 30 \u001b[0m\u001b[2mโ”‚   \u001b[0m\u001b[94mdef\u001b[0m \u001b[92m_wrap_generator\u001b[0m(\u001b[96mself\u001b[0m, func):                                                       \u001b[31mโ”‚\u001b[0m\n",
       "\u001b[31mโ”‚\u001b[0m                                                                                                  \u001b[31mโ”‚\u001b[0m\n",
       "\u001b[31mโ”‚\u001b[0m in \u001b[92minfer_from_prompt\u001b[0m                                                                             \u001b[31mโ”‚\u001b[0m\n",
       "\u001b[31mโ”‚\u001b[0m                                                                                                  \u001b[31mโ”‚\u001b[0m\n",
       "\u001b[31mโ”‚\u001b[0m   \u001b[2m64 \u001b[0m\u001b[2mโ”‚   \u001b[0m\u001b[2m## text to token\u001b[0m                                                                        \u001b[31mโ”‚\u001b[0m\n",
       "\u001b[31mโ”‚\u001b[0m   \u001b[2m65 \u001b[0m\u001b[2mโ”‚   \u001b[0mtext_tokens, text_tokens_lens = text_collater(                                          \u001b[31mโ”‚\u001b[0m\n",
       "\u001b[31mโ”‚\u001b[0m   \u001b[2m66 \u001b[0m\u001b[2mโ”‚   โ”‚   \u001b[0m[                                                                                   \u001b[31mโ”‚\u001b[0m\n",
       "\u001b[31mโ”‚\u001b[0m \u001b[31mโฑ \u001b[0m67 \u001b[2mโ”‚   โ”‚   โ”‚   \u001b[0mtokenize_text(                                                                  \u001b[31mโ”‚\u001b[0m\n",
       "\u001b[31mโ”‚\u001b[0m   \u001b[2m68 \u001b[0m\u001b[2mโ”‚   โ”‚   โ”‚   โ”‚   \u001b[0mtext_tokenizer, text=\u001b[33mf\u001b[0m\u001b[33m\"\u001b[0m\u001b[33m{\u001b[0mtext_prompt\u001b[33m}\u001b[0m\u001b[33m \u001b[0m\u001b[33m{\u001b[0mtext\u001b[33m}\u001b[0m\u001b[33m\"\u001b[0m.strip()                        \u001b[31mโ”‚\u001b[0m\n",
       "\u001b[31mโ”‚\u001b[0m   \u001b[2m69 \u001b[0m\u001b[2mโ”‚   โ”‚   โ”‚   \u001b[0m)                                                                               \u001b[31mโ”‚\u001b[0m\n",
       "\u001b[31mโ”‚\u001b[0m   \u001b[2m70 \u001b[0m\u001b[2mโ”‚   โ”‚   \u001b[0m]                                                                                   \u001b[31mโ”‚\u001b[0m\n",
       "\u001b[31mโ”‚\u001b[0m                                                                                                  \u001b[31mโ”‚\u001b[0m\n",
       "\u001b[31mโ”‚\u001b[0m \u001b[2;33m/home/dongsun/vall-e/valle/data/\u001b[0m\u001b[1;33mtokenizer.py\u001b[0m:\u001b[94m178\u001b[0m in \u001b[92mtokenize_text\u001b[0m                                \u001b[31mโ”‚\u001b[0m\n",
       "\u001b[31mโ”‚\u001b[0m                                                                                                  \u001b[31mโ”‚\u001b[0m\n",
       "\u001b[31mโ”‚\u001b[0m   \u001b[2m175 \u001b[0m                                                                                           \u001b[31mโ”‚\u001b[0m\n",
       "\u001b[31mโ”‚\u001b[0m   \u001b[2m176 \u001b[0m\u001b[94mdef\u001b[0m \u001b[92mtokenize_text\u001b[0m(tokenizer: TextTokenizer, text: \u001b[96mstr\u001b[0m) -> List[\u001b[96mstr\u001b[0m]:                       \u001b[31mโ”‚\u001b[0m\n",
       "\u001b[31mโ”‚\u001b[0m   \u001b[2m177 \u001b[0m\u001b[2mโ”‚   \u001b[0mphonemes = tokenizer([text.strip()])                                                   \u001b[31mโ”‚\u001b[0m\n",
       "\u001b[31mโ”‚\u001b[0m \u001b[31mโฑ \u001b[0m178 \u001b[2mโ”‚   \u001b[0m\u001b[94mreturn\u001b[0m phonemes[\u001b[94m0\u001b[0m]  \u001b[2m# k2symbols\u001b[0m                                                        \u001b[31mโ”‚\u001b[0m\n",
       "\u001b[31mโ”‚\u001b[0m   \u001b[2m179 \u001b[0m                                                                                           \u001b[31mโ”‚\u001b[0m\n",
       "\u001b[31mโ”‚\u001b[0m   \u001b[2m180 \u001b[0m                                                                                           \u001b[31mโ”‚\u001b[0m\n",
       "\u001b[31mโ”‚\u001b[0m   \u001b[2m181 \u001b[0m\u001b[94mdef\u001b[0m \u001b[92mremove_encodec_weight_norm\u001b[0m(model):                                                     \u001b[31mโ”‚\u001b[0m\n",
       "\u001b[31mโ•ฐโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฏ\u001b[0m\n",
       "\u001b[1;91mIndexError: \u001b[0mlist index out of range\n"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "text_prompt = '' # text of the audio \n",
    "audio_prompt = '' # path to the audio file\n",
    "text = '' # \n",
    "message, (sr, data) = infer_from_prompt(text_prompt, audio_prompt, text)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "1f97f088-74a4-4cbb-a18b-d884adf81546",
   "metadata": {},
   "outputs": [],
   "source": [
    "print(message)\n",
    "from IPython.display import Audio\n",
    "Audio(data, rate=sr)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "1cedb3cc-7486-4a3d-9dcd-1facffdb78ad",
   "metadata": {},
   "source": [
    "# Simple Gradio App"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "723c13c7-36f5-4af6-bc0b-bbf6d65c2e3a",
   "metadata": {
    "collapsed": true,
    "jupyter": {
     "outputs_hidden": true
    },
    "tags": []
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Defaulting to user installation because normal site-packages is not writeable\n",
      "\u001b[33mWARNING: Ignoring invalid distribution -orch (/home/dongsun/.local/lib/python3.10/site-packages)\u001b[0m\u001b[33m\n",
      "\u001b[0m\u001b[33mWARNING: Ignoring invalid distribution -orch (/home/dongsun/.local/lib/python3.10/site-packages)\u001b[0m\u001b[33m\n",
      "\u001b[0mRequirement already satisfied: gradio in /home/dongsun/.local/lib/python3.10/site-packages (3.32.0)\n",
      "Requirement already satisfied: markdown-it-py[linkify]>=2.0.0 in /home/dongsun/.local/lib/python3.10/site-packages (from gradio) (2.1.0)\n",
      "Requirement already satisfied: semantic-version in /home/dongsun/.local/lib/python3.10/site-packages (from gradio) (2.10.0)\n",
      "Requirement already satisfied: pandas in /home/dongsun/.local/lib/python3.10/site-packages (from gradio) (2.0.3)\n",
      "Requirement already satisfied: uvicorn>=0.14.0 in /home/dongsun/.local/lib/python3.10/site-packages (from gradio) (0.19.0)\n",
      "Requirement already satisfied: mdit-py-plugins<=0.3.3 in /home/dongsun/.local/lib/python3.10/site-packages (from gradio) (0.3.1)\n",
      "Requirement already satisfied: httpx in /home/dongsun/.local/lib/python3.10/site-packages (from gradio) (0.23.0)\n",
      "Requirement already satisfied: orjson in /home/dongsun/.local/lib/python3.10/site-packages (from gradio) (3.8.0)\n",
      "Requirement already satisfied: ffmpy in /home/dongsun/.local/lib/python3.10/site-packages (from gradio) (0.3.0)\n",
      "Requirement already satisfied: pygments>=2.12.0 in /home/dongsun/.local/lib/python3.10/site-packages (from gradio) (2.14.0)\n",
      "Requirement already satisfied: pillow in /home/dongsun/.local/lib/python3.10/site-packages (from gradio) (9.5.0)\n",
      "Requirement already satisfied: numpy in /home/dongsun/.local/lib/python3.10/site-packages (from gradio) (1.23.0)\n",
      "Requirement already satisfied: python-multipart in /home/dongsun/.local/lib/python3.10/site-packages (from gradio) (0.0.5)\n",
      "Requirement already satisfied: markupsafe in /home/dongsun/.local/lib/python3.10/site-packages (from gradio) (2.1.0)\n",
      "Requirement already satisfied: pydantic in /home/dongsun/.local/lib/python3.10/site-packages (from gradio) (1.8.2)\n",
      "Requirement already satisfied: aiohttp in /home/dongsun/.local/lib/python3.10/site-packages (from gradio) (3.8.1)\n",
      "Requirement already satisfied: websockets>=10.0 in /home/dongsun/.local/lib/python3.10/site-packages (from gradio) (10.3)\n",
      "Requirement already satisfied: typing-extensions in /home/dongsun/.local/lib/python3.10/site-packages (from gradio) (4.5.0)\n",
      "Requirement already satisfied: gradio-client>=0.2.4 in /home/dongsun/.local/lib/python3.10/site-packages (from gradio) (0.2.5)\n",
      "Requirement already satisfied: matplotlib in /home/dongsun/.local/lib/python3.10/site-packages (from gradio) (3.7.0)\n",
      "Requirement already satisfied: huggingface-hub>=0.13.0 in /home/dongsun/.local/lib/python3.10/site-packages (from gradio) (0.15.1)\n",
      "Requirement already satisfied: pydub in /home/dongsun/.local/lib/python3.10/site-packages (from gradio) (0.25.1)\n",
      "Requirement already satisfied: fastapi in /home/dongsun/.local/lib/python3.10/site-packages (from gradio) (0.94.0)\n",
      "Requirement already satisfied: requests in /home/dongsun/.local/lib/python3.10/site-packages (from gradio) (2.31.0)\n",
      "Requirement already satisfied: jinja2 in /home/dongsun/.local/lib/python3.10/site-packages (from gradio) (3.0.3)\n",
      "Requirement already satisfied: pyyaml in /home/dongsun/.local/lib/python3.10/site-packages (from gradio) (6.0)\n",
      "Requirement already satisfied: aiofiles in /home/dongsun/.local/lib/python3.10/site-packages (from gradio) (23.1.0)\n",
      "Requirement already satisfied: altair>=4.2.0 in /home/dongsun/.local/lib/python3.10/site-packages (from gradio) (4.2.2)\n",
      "Requirement already satisfied: jsonschema>=3.0 in /home/dongsun/.local/lib/python3.10/site-packages (from altair>=4.2.0->gradio) (4.4.0)\n",
      "Requirement already satisfied: entrypoints in /home/dongsun/.local/lib/python3.10/site-packages (from altair>=4.2.0->gradio) (0.4)\n",
      "Requirement already satisfied: toolz in /home/dongsun/.local/lib/python3.10/site-packages (from altair>=4.2.0->gradio) (0.11.2)\n",
      "Requirement already satisfied: fsspec in /home/dongsun/.local/lib/python3.10/site-packages (from gradio-client>=0.2.4->gradio) (2022.3.0)\n",
      "Requirement already satisfied: packaging in /home/dongsun/.local/lib/python3.10/site-packages (from gradio-client>=0.2.4->gradio) (23.1)\n",
      "Requirement already satisfied: filelock in /home/dongsun/.local/lib/python3.10/site-packages (from huggingface-hub>=0.13.0->gradio) (3.11.0)\n",
      "Requirement already satisfied: tqdm>=4.42.1 in /home/dongsun/.local/lib/python3.10/site-packages (from huggingface-hub>=0.13.0->gradio) (4.65.0)\n",
      "Requirement already satisfied: mdurl~=0.1 in /home/dongsun/.local/lib/python3.10/site-packages (from markdown-it-py[linkify]>=2.0.0->gradio) (0.1.2)\n",
      "Requirement already satisfied: linkify-it-py~=1.0 in /home/dongsun/.local/lib/python3.10/site-packages (from markdown-it-py[linkify]>=2.0.0->gradio) (1.0.3)\n",
      "Requirement already satisfied: pytz>=2020.1 in /usr/lib/python3.10/site-packages (from pandas->gradio) (2022.7)\n",
      "Requirement already satisfied: tzdata>=2022.1 in /home/dongsun/.local/lib/python3.10/site-packages (from pandas->gradio) (2022.7)\n",
      "Requirement already satisfied: python-dateutil>=2.8.2 in /usr/lib/python3.10/site-packages (from pandas->gradio) (2.8.2)\n",
      "Requirement already satisfied: h11>=0.8 in /home/dongsun/.local/lib/python3.10/site-packages (from uvicorn>=0.14.0->gradio) (0.12.0)\n",
      "Requirement already satisfied: click>=7.0 in /usr/lib/python3.10/site-packages (from uvicorn>=0.14.0->gradio) (8.1.3)\n",
      "Requirement already satisfied: frozenlist>=1.1.1 in /home/dongsun/.local/lib/python3.10/site-packages (from aiohttp->gradio) (1.3.0)\n",
      "Requirement already satisfied: async-timeout<5.0,>=4.0.0a3 in /home/dongsun/.local/lib/python3.10/site-packages (from aiohttp->gradio) (4.0.2)\n",
      "Requirement already satisfied: charset-normalizer<3.0,>=2.0 in /home/dongsun/.local/lib/python3.10/site-packages (from aiohttp->gradio) (2.1.1)\n",
      "Requirement already satisfied: attrs>=17.3.0 in /home/dongsun/.local/lib/python3.10/site-packages (from aiohttp->gradio) (21.4.0)\n",
      "Requirement already satisfied: yarl<2.0,>=1.0 in /home/dongsun/.local/lib/python3.10/site-packages (from aiohttp->gradio) (1.7.2)\n",
      "Requirement already satisfied: multidict<7.0,>=4.5 in /home/dongsun/.local/lib/python3.10/site-packages (from aiohttp->gradio) (6.0.2)\n",
      "Requirement already satisfied: aiosignal>=1.1.2 in /home/dongsun/.local/lib/python3.10/site-packages (from aiohttp->gradio) (1.2.0)\n",
      "Requirement already satisfied: starlette<0.27.0,>=0.26.0 in /home/dongsun/.local/lib/python3.10/site-packages (from fastapi->gradio) (0.26.1)\n",
      "Requirement already satisfied: certifi in /home/dongsun/.local/lib/python3.10/site-packages (from httpx->gradio) (2022.12.7)\n",
      "Requirement already satisfied: sniffio in /home/dongsun/.local/lib/python3.10/site-packages (from httpx->gradio) (1.2.0)\n",
      "Requirement already satisfied: rfc3986[idna2008]<2,>=1.3 in /home/dongsun/.local/lib/python3.10/site-packages (from httpx->gradio) (1.5.0)\n",
      "Requirement already satisfied: httpcore<0.16.0,>=0.15.0 in /home/dongsun/.local/lib/python3.10/site-packages (from httpx->gradio) (0.15.0)\n",
      "Requirement already satisfied: kiwisolver>=1.0.1 in /home/dongsun/.local/lib/python3.10/site-packages (from matplotlib->gradio) (1.3.2)\n",
      "Requirement already satisfied: fonttools>=4.22.0 in /home/dongsun/.local/lib/python3.10/site-packages (from matplotlib->gradio) (4.29.1)\n",
      "Requirement already satisfied: contourpy>=1.0.1 in /home/dongsun/.local/lib/python3.10/site-packages (from matplotlib->gradio) (1.0.7)\n",
      "Requirement already satisfied: pyparsing>=2.3.1 in /usr/lib/python3.10/site-packages (from matplotlib->gradio) (3.0.9)\n",
      "Requirement already satisfied: cycler>=0.10 in /home/dongsun/.local/lib/python3.10/site-packages (from matplotlib->gradio) (0.11.0)\n",
      "Requirement already satisfied: six>=1.4.0 in /usr/lib/python3.10/site-packages (from python-multipart->gradio) (1.16.0)\n",
      "Requirement already satisfied: idna<4,>=2.5 in /home/dongsun/.local/lib/python3.10/site-packages (from requests->gradio) (2.10)\n",
      "Requirement already satisfied: urllib3<3,>=1.21.1 in /home/dongsun/.local/lib/python3.10/site-packages (from requests->gradio) (1.26.15)\n",
      "Requirement already satisfied: anyio==3.* in /home/dongsun/.local/lib/python3.10/site-packages (from httpcore<0.16.0,>=0.15.0->httpx->gradio) (3.5.0)\n",
      "Requirement already satisfied: pyrsistent!=0.17.0,!=0.17.1,!=0.17.2,>=0.14.0 in /home/dongsun/.local/lib/python3.10/site-packages (from jsonschema>=3.0->altair>=4.2.0->gradio) (0.18.1)\n",
      "Requirement already satisfied: uc-micro-py in /home/dongsun/.local/lib/python3.10/site-packages (from linkify-it-py~=1.0->markdown-it-py[linkify]>=2.0.0->gradio) (1.0.1)\n",
      "\u001b[33mWARNING: Ignoring invalid distribution -orch (/home/dongsun/.local/lib/python3.10/site-packages)\u001b[0m\u001b[33m\n",
      "\u001b[0m\u001b[33mWARNING: Ignoring invalid distribution -orch (/home/dongsun/.local/lib/python3.10/site-packages)\u001b[0m\u001b[33m\n",
      "\u001b[0m\u001b[33mWARNING: Ignoring invalid distribution -orch (/home/dongsun/.local/lib/python3.10/site-packages)\u001b[0m\u001b[33m\n",
      "\u001b[0m\u001b[33mWARNING: Ignoring invalid distribution -orch (/home/dongsun/.local/lib/python3.10/site-packages)\u001b[0m\u001b[33m\n",
      "\u001b[0m\n",
      "\u001b[1m[\u001b[0m\u001b[34;49mnotice\u001b[0m\u001b[1;39;49m]\u001b[0m\u001b[39;49m A new release of pip is available: \u001b[0m\u001b[31;49m23.0.1\u001b[0m\u001b[39;49m -> \u001b[0m\u001b[32;49m23.2.1\u001b[0m\n",
      "\u001b[1m[\u001b[0m\u001b[34;49mnotice\u001b[0m\u001b[1;39;49m]\u001b[0m\u001b[39;49m To update, run: \u001b[0m\u001b[32;49mpython -m pip install --upgrade pip\u001b[0m\n"
     ]
    }
   ],
   "source": [
    "!pip install gradio"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "6b59cf2b-2826-40be-a27f-e6dbfe0cc1c0",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Running on local URL:  http://127.0.0.1:7860\n",
      "Running on public URL: https://b3512daf295a0b63b1.gradio.live\n",
      "\n",
      "This share link expires in 72 hours. For free permanent hosting and GPU upgrades (NEW!), check out Spaces: https://huggingface.co/spaces\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div><iframe src=\"https://b3512daf295a0b63b1.gradio.live\" width=\"100%\" height=\"500\" allow=\"autoplay; camera; microphone; clipboard-read; clipboard-write;\" frameborder=\"0\" allowfullscreen></iframe></div>"
      ],
      "text/plain": [
       "<IPython.core.display.HTML object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/plain": []
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "text_loaded\n",
      "Audio encoded\n",
      "VALL-E EOS [356 -> 899]\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "/home/dongsun/.local/lib/python3.10/site-packages/gradio/processing_utils.py:171: UserWarning: Trying to convert audio automatically from float32 to 16-bit int format.\n",
      "  warnings.warn(warning.format(data.dtype))\n"
     ]
    }
   ],
   "source": [
    "import gradio as gr\n",
    "app = gr.Blocks(title=\"VALL-E Korean\")\n",
    "with app:\n",
    "    #gr.Markdown(top_md)\n",
    "    with gr.Tab(\"VALL-E Korean Demo\"):\n",
    "        #gr.Markdown(infer_from_prompt_md)\n",
    "        with gr.Row():\n",
    "            with gr.Column():\n",
    "                text_prompt = gr.TextArea(label=\"Input Text\",\n",
    "                                      placeholder=\"Type text in the audio file (Korean)\",)\n",
    "                audio_prompt= gr.Audio(label=\"Input Audio\", source='upload', interactive=True, type=\"filepath\")\n",
    "                text_input = gr.TextArea(label=\"Output Text\",\n",
    "                                      placeholder=\"Type text you want to generate (Korean)\",)\n",
    "            with gr.Column():\n",
    "                text_output = gr.Textbox(label=\"Message\")\n",
    "                audio_output= gr.Audio(label=\"Output Audio\")\n",
    "                btn = gr.Button(\"Generate!\")\n",
    "                btn.click(infer_from_prompt,\n",
    "                          inputs=[text_prompt, audio_prompt, text_input],\n",
    "                          outputs=[text_output, audio_output])\n",
    "webbrowser.open(\"http://127.0.0.1:7860\")\n",
    "app.launch(share=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "fafc648b-2165-45a1-b422-38ced5f4d8fa",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.9"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}