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
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
{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "HpzC9I3uDBud"
   },
   "source": [
    "<a href=\"https://colab.research.google.com/github/vanderbilt-data-science/lo-achievement/blob/main/instructor_vector_store_creator.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "hbthVGIgDBug"
   },
   "source": [
    "# Creating a Shared Vector Store (for Instructors)\n",
    "\n",
    "This notebook is for instructors to create a *vector store* which contains all of the information necessary for students to generate their own self-study materials using large language models."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "NpYSvDgzDBuh"
   },
   "source": [
    "## Using This Notebook\n",
    "This notebook is split up into a bunch of *cells*, which contain explanations / instructions or code. You should go through the cells in order from top to bottom.\n",
    "\n",
    "When you encounter a code cell, hover the mouse over it and press the 'run' button (the circle with a triangle inside of it) to execute the code in the cell. Wait until the green checkmark appears to the right of the run button before proceeding to the next cell.\n",
    "\n",
    "Run the following code block to test it out. It should display `4` below the code.\n",
    "\n",
    "*Note: Before running, there may be a pop-up saying 'Warning: This notebook was not authored by Google'. In that case, click 'Run anyways'.*"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "id": "ACE73ZmZDBuh"
   },
   "outputs": [],
   "source": [
    "print(2+2)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "dTrRB_2rDBui"
   },
   "source": [
    "## Importing Libraries\n",
    "Continue running the code below. Ignore any warnings that pop up."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "id": "0MHRWInBDBuj"
   },
   "outputs": [],
   "source": [
    "# install libraries here\n",
    "# -q flag for \"quiet\" install\n",
    "!pip install -q langchain openai unstructured tiktoken deeplake trafilatura justext yt_dlp pydub"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "id": "2FpSOOlEDBuk"
   },
   "outputs": [],
   "source": [
    "# import libraries here\n",
    "import os\n",
    "\n",
    "from google.colab import files\n",
    "from getpass import getpass\n",
    "from IPython.display import display, Markdown\n",
    "\n",
    "import openai\n",
    "from langchain.docstore.document import Document\n",
    "from langchain.text_splitter import RecursiveCharacterTextSplitter\n",
    "from langchain.embeddings import OpenAIEmbeddings\n",
    "from langchain.document_loaders.unstructured import UnstructuredFileLoader\n",
    "\n",
    "from langchain.document_loaders.generic import GenericLoader\n",
    "from langchain.document_loaders.parsers import OpenAIWhisperParser\n",
    "from langchain.document_loaders.blob_loaders.youtube_audio import YoutubeAudioLoader\n",
    "\n",
    "from langchain.document_loaders import WebBaseLoader\n",
    "import trafilatura\n",
    "import requests\n",
    "import justext\n",
    "\n",
    "import deeplake\n",
    "from langchain.vectorstores import DeepLake"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "TIFQUXspDBul"
   },
   "source": [
    "## Setting Up API Access\n",
    "Much of the following code rely on certain *APIs* (application programming interfaces) which have limited access. You will need to get an *API key* for each of those services which will be inserted into the code to let the service know you are an authorized user."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "vKXV9FubDBum"
   },
   "source": [
    "#### OpenAI"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "GG9GwadDDBuo"
   },
   "source": [
    "First, you will need an **OpenAI API key**. To do this:\n",
    "1. Visit [platform.openai.com/account/api-keys](https://platform.openai.com/account/api-keys) and sign up for an account.\n",
    "2. Click 'Create a secret API key', and give it any name you want.\n",
    "3. Copy the newly created key, either by right-clicking and pressing 'Copy' or using the keyboard shortcut -- Ctrl+C on Windows, Cmd+C on a Mac.\n",
    "\n",
    "Run the following code cell. You'll see a blank text box pop up -- paste your API key there (using the shortcut Ctrl+V on Windows, or Cmd+V if you are using a Mac) and press Enter."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "id": "Dv3l_ZKiDBup"
   },
   "outputs": [],
   "source": [
    "OPENAI_API_KEY = getpass(\"OpenAI API key: \")\n",
    "os.environ[\"OPENAI_API_KEY\"] = OPENAI_API_KEY\n",
    "openai.api_key = OPENAI_API_KEY"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "1Xbl8szQDBup"
   },
   "source": [
    "#### DeepLake\n",
    "\n",
    "Next, you will need to input a **DeepLake API key**, found in the DeepLake dashboard at [app.activeloop.ai](https://app.activeloop.ai).\n",
    "\n",
    "1. Click the link above and create an account.\n",
    "2. After making an account, you will be prompted to set a username. Once you have set your username, copy it, run the code below, paste the username into the text box, and press Enter. (This username will be shared with students.)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "id": "rfzGVvm-DBup"
   },
   "outputs": [],
   "source": [
    "DEEPLAKE_USERNAME = input(\"DeepLake username: \")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "o9_N6ychDBur"
   },
   "source": [
    "3. You should then be on the DeepLake dashboard. At the top, click 'Create API token'. You should see an empty table with the columns 'Name', 'Expiration date', and 'Token'.\n",
    "4. Click the 'Create API token' button ![image.png](data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAJYAAAAwCAYAAADzRIMRAAALoElEQVR4Xu1caXBT1xX+nvZdssFm8+DYgGPWAVMggFkyMWuJyYBDgRICDZ1JO6HJkNKkAYakEHcgSxsyQybDUkqLW9bWCVsh7GFJ2NywhuASJyQ4GCxZaF973nuWbFmSbWHJjjXv/tLy3r3nnvPdc7577nmP8VOD0AQNxFkDjACsOGtU6I7TgAAsAQgJ0YAArISoVehUAJaAgYRoQABWQtQqdBozsLhNpM8J193P4a78FO6q8/CZr8NruQp4BIW2Ww1IALGmD0S6XEjTBkPaOR+y9KGASA6GYWKeVvOB5ffCY70D+5cb4aooBSQqyDuPhTj9J5AaciFSZ0AkVccsgHDDj0MDPrcVPuttuE3kJO6eg7PyKDkKG2SZU6F89BeQqLvQVk/cbGGbBpbfB5/bDNul92AjUCmynoay12xIO+Y1exDhwvapAfe9C7B/VQLHre1QEbhU/V8k56EjgImanFCjwPJ7HXDeOQZr2VuQ6nO4jiWGR5vsVLgguTTgM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I8TRChNbk17JM1YTZYmszMVHqZIGnu3ykSa9zAF57WEx79axSJJMEhMj3/xEVF4YDUJ7J7QKcT+wGqtOMIj9gm1S7vu/KEfsQ/MWngpSLu2f0KEb/FLQYLgorDIZuWtZauE1xglxFTto9PQ1xi9wj0wEel9DfVnI7x4rX3Ytk2kTNiL10JmI7wqsk2M21qDtv6rIhvMTHi5bWuZupXHabOX27byPIXh2rcGmuZY7Xt+gvRtpAEBWG2k+GQfVgBWslu4jeb3f6EJmcthjHP3AAAAAElFTkSuQmCC) at the right of the page, choose a name for the token, then click 'Create API token'. (You do not need to change the expiration date.)\n",
    "5. Afterwards, you should see the table look something like this:"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "ivyqa05xDBur"
   },
   "source": [
    "![image.png](data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAsMAAABrCAYAAACSXI/oAAAgAElEQVR4Xu3dCVhN6QMG8DctSiZC9p0xzFgG2ZUlFMLIkkGWwYx9+BvZMxhjzSTTDJM9JoPIGMvIln2isa9DlsgMkZSi7f7POffe3K5KqZN7u+99nnlmps7yfb/vfPe85zvfORkphA/4oQAFKEABClCAAhSggAEKGDEMG2Crs8oUoAAFKEABClCAApIAwzAPBApQgAIUoAAFKEABgxVgGDbYpmfFKUABClCAAhSgAAUYhnkMUIACFKAABShAAQoYrADDsME2PStOAQpQgAIUoAAFKMAwzGOAAhSgAAUoQAEKUMBgBRiGDbbpWXEKUIACFKAABShAAYZhHgMUoAAFKEABClCAAgYrwDBssE3PilOAAhSgAAUoQAEKMAzzGKAABShAAQpQgAIUMFgBhmGDbXpWnAIUoAAFKEABClCAYZjHAAUoQAEKUIACFKCAwQowDBts07PiFKAABShAAQpQgAIMwzwGKEABClCAAhSgAAUMVoBh2GCbnhWnAAUoQAEKUIACFGAY5jFAAQpQgAIUoAAFKGCwAgzDBtv0rDgFKEABClCAAhSgAMMwjwEKUIACFKAABShAAYMVYBg22KZnxSlAAQpQgAIUoAAFGIZ5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jUS83NshtUEAGAXUYzs6mxWkUtra22VlFZ5ZlGNaZpmBBKEABClCAAhSgwPsXEOfwRkREZKsg4h/HyO7UiGztQMaFGYZlxOWmKUABClCAAhSgAAV0W4BhWLfbh6WjAAUoQAEKUIACFJBRgGFYRlxumgIUoAAFKEABClBAtwUYhnW7fVg6ClCAAhSgAAUoQAEZBRiGZcTlpilAAQpQgAIUoAAFdFuAYVi324elowAFKEABClCAAhSQUYBhWEZcbpoCFKAABShAAQpQQLcFGIZ1u31YOgpQgAIUoAAFKEABGQUYhmXE5aYpQAEKUIACFKAABXRbgGFYt9uHpaMABShAAQpQgAIUkFGAYVhGXG6aAhSgAAUoQAEKUEC3BRiGdbt9WDoKUIACFKAABShAARkFGIZlxOWmKUABClCAAhSgAAV0W4BhWLfbh6WjAAUoQAEKUIACFJBRgGFYRlxumgIUoAAFKEABClBAtwUYhnW7fVg6ClCAAhSgAAUoQAEZBRiGZcTlpilAAQpQgAIUoAAFdFuAYVi324elowAFKEABClCAAhSQUYBhWEZcbpoCFKAABShAAQpQQLcFGIZ1u31YOgpQgL34LDMAAACaSURBVAIUoAAFKEABGQUYhmXE5aYpQAEKUIACFKAABXRbgGFYt9uHpaMABShAAQpQgAIUkFGAYVhGXG6aAhSgAAUoQAEKUEC3BRiGdbt9WDoKUIACFKAABShAARkFGIZlxOWmKUABClCAAhSgAAV0W4BhWLfbh6WjAAUoQAEKUIACFJBRgGFYRlxumgIUoAAFKEABClBAtwX+D4/nW2ut3arDAAAAAElFTkSuQmCC)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "WSI47-j0DBur"
   },
   "source": [
    "6. Click the two overlaid squares ![image.png](data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEEAAAA/CAYAAAC/36X0AAABf0lEQVR4Xu2aPYqFMBhFvwcWKlhoqaWFG9DNuwVXYGGprYUgdjMRMTgyPHRiRpk5AeEJ5u+8e6+R5PWhivzz8gKCCBCUC4AAhCUMUQIQUIJeGGAH7IAdsMP2S4FMuDoT+r6Xqqoe8TlWFIWEYXhoLJcqAQiKORC+geC6rvi+f0iSpg+N4yjTNOlmHmOHNE1lvn6jNE0j87UWICgSQLANYQ6/tTiOI0EQ6Pt9MP5ZO5RlqScdRZHkeQ4EIKAEEeygkgAIQFheCCgBCCiBxRIrRqUBIABhiQKUAASUoF+L2AE7YAfssN03IBPIhPOZEMexJEmyFZK1323bStd1un2rmy9n7GBtxgcaBoKCBIQ7IQzDIHVdHxCr/UeyLPuyRfiux9MnVd5lgv2p2ekBCIorEEwheJ4n81rgjjIfBbpqDWKkhDsmv/a53/gxGQsQTO1gQt+07q1K2B7XMZ2ISf39USGTtk7bwaSzp9YFwk8y4an/psm4UAJKWPSDEoCwKOET7bDhYssL2DsAAAAASUVORK5CYII=) to copy the API key; then run the code below and paste it into the input text box and press Enter."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "id": "uNA8U5gvDBus"
   },
   "outputs": [],
   "source": [
    "os.environ['ACTIVELOOP_TOKEN'] = getpass(\"DeepLake API key: \")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "8CmfEgseDBus"
   },
   "source": [
    "Finally, pick a name for your dataset. It doesn't matter what this is, but keep in mind that it will be shared with the students."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "id": "dosq4FolDBus"
   },
   "outputs": [],
   "source": [
    "dataset_name = input(\"Enter a name for your dataset: \")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "m0zs864gDBut"
   },
   "source": [
    "## Processing The Document(s)\n",
    "\n",
    "In this part, you will upload the documents you want the students / model to reference; the embeddings will be created from those documents.\n",
    "\n",
    "**Note: The embeddings of all the documents you share will be publicly available. Do not use this for any documents you want to keep private.**"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "eOEJ7rnlDBut"
   },
   "source": [
    "First, upload your documents to Google Colab. To do this:\n",
    "1. Click on the 'file' icon ![image1_3.png](data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAFQAAABUCAYAAAAcaxDBAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAALEoAACxKAXd6dE0AAAIKSURBVHhe7do/kmFRFMfxM7MAGyCRKZEI60CA0CJkEjKJHZApAevwJxJhAWyABfTM6T7JdDZ1v6/rvfL7VHV1ndfJ7W9f+ql3f338ZYL5Hd8FoqAwBYUpKExBYQoKU1CYgsIUFKagMAWFKShMQWEKClNQmILCFBSmoDAFhSkoTEFhCgpTUJiCwrCDDs/n01arlW23W3s8HnH1/83nc+v1ejEVDxLUYw4GA7ter3ElTZGjIi/56XSKxXTj8fhzpxdR8g713dloNGJiFXGnJgc9HA42HA5j4k0mE6vX6zExyuWyVSqVmFi5D5qVVquVyR/rbW+bjsfj5z/Sy+USVxhvfR/6er1sNpvFxHj7G3vfqff7PaZ0mbyHNptNa7fbMeWLr/d0OsX0Zb1ec+v1oCn2+/1HtVr952uxWMRP88fX9n29/jtQ9FkepqAwBYUpKExBYQoKU1CYgsIUFKagMAWFKShMQWEKClNQmILCFBSmoDAFhSkoTEFhmTxGzvLsUCp/Bv/9/Cr5GDnXp+9+yvl8tlKpFFOa5Je8L6TT6cRUPL52KqZL3qHOd2m/37fb7RZXiqFWq9lms8lfUOdRl8ul7Xa7pDP2P8Hf47vdro1GIzSmw4LKF902wRQUpqAwBYUpKExBYQoKU1CYgsIUFKagMAWFKShMQWEKClNQmILCFBSmoDAFhSkoyuwPHzLZbD4ZgJMAAAAASUVORK5CYII=) at the bottom of the sidebar to the left of these instructions.\n",
    "2. Click on the 'upload file' icon ![image2_1.png](data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAFcAAABaCAYAAADNVsqyAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAALEoAACxKAXd6dE0AAAKKSURBVHhe7dw7bsJAFIVhJx3UtLARaNkILIKakkXAGhAlNSyCmj3QJjnRjOQgY173eO5kzi+h2Fgok08Tg8zAx9dPlaL0GX4qQsIlJlxiwiUmXGLCJSZcYsIlJlxiwiUmXGLCJSZcYsIlJlxiwiUmXGLCJUZ9m+d4PFb7/b46n8/hHm7j8biaz+dhL30U3MvlUq1Wq85Q63kCppwWUsEi/Les1+uwlzZz3MPhkAw25gXYHBd/mIc8AJvjnk6nsJW+1MDmT2iz2Sxs/W2z2YQt2279vnqpnuSKeJ2bagYXgYtSABeDi7oGLgoXdQlcHC7qCrhIXNQFcLG4iA1cNC5iAhePi1jAwg0xgIVbyxpYuFcB2CrhEhMusewvOb4Te6yaucSES0y4xIRLTLjEssLFmgjcmFeyLMsGF6h4iYQb80qWZVngRth6OQC7x22CjXkHdo3bBhvzDOwW9xHYGIC3223Y85NL3GdgY7vd7vdxnnKH+wpsDI/zBOwK9x3YmCdgN7gWsDEvwC5wLWFjHoCT496D7fV6Yau5tuOpgZPjtq1EB9xisQh7zeF4G3DKle7JcbHiGyu/r4uwo9Eo3NMcjt8CTv2xKRfn3Gvg4XBYLZfLu7CxJmAPn0dzgYsiMGABNRgMwpHHqgN7gEVucBFAANTv98M9zwVgzHgPsMgVLnoVNvbsjGfmDvc/JVxiwiUmXGLCJSZcYlrl2JDVWDVziQmXWGenhZxye1rAhZecsxy/Oe50Og1beWY5fnPcyWSS7ezFuDF+qyhPaLhsmBswxotxW0b5RrwYvmoQS41Sf89YW0DFqcByxsaouKWn17nEhEtMuMSES0y4xIRLTLjEhEtMuMSES6uqvgFS+TQXb05HUQAAAABJRU5ErkJggg==) on the left of the Files toolbar.\n",
    "3. Select all of the files you want to upload, then click 'Open'.\n",
    "4. A warning should pop up. Click 'OK' to continue.\n",
    "5. Wait until the spinning circle in the bottom of the 'Files' section disappears. This means that all of the files have been uploaded."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "hcRqREcvIeY7"
   },
   "source": [
    "### Adding YouTube Videos / Websites\n",
    "If you have any websites or YouTube videos which also contain content which you want to put into your data lake, paste those links one at a time into the text box below, pressing 'Enter' after each one. Once you have entered all the links, press 'Enter' without typing anything to finish execution of the code cell.\n",
    "\n",
    "If you have no URLs to add, just click on the box and press 'Enter' without typing anything."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "id": "19tljTkqIiz9"
   },
   "outputs": [],
   "source": [
    "url_list = []\n",
    "while (url := input(\"Enter a YouTube / website link: \")): url_list.append(url)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "qAVRPqDsDBuu"
   },
   "source": [
    "## Embedding & Database Creation"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "_N4erDDkDBuu"
   },
   "source": [
    "Finally, run the following code."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "id": "G2DNpm5dDqJ8"
   },
   "outputs": [],
   "source": [
    "# Functions to extract the text from YouTube videos / websites\n",
    "def save_text(text, text_name = None):\n",
    "  if not text_name: text_name = text[:20]\n",
    "  text_path = os.path.join(\"/content\",text_name+\".txt\")\n",
    "  with open(text_path, \"x\") as f:\n",
    "    f.write(text)\n",
    "  # Return the location at which the transcript is saved\n",
    "  return text_path\n",
    "\n",
    "def save_youtube_transcript(url, save_dir = \"sample_data\"):\n",
    "  # Transcribe the videos to text and save to file in /content\n",
    "  # save_dir: directory to save audio files\n",
    "  youtube_loader = GenericLoader(YoutubeAudioLoader([url], save_dir),\n",
    "                                 OpenAIWhisperParser())\n",
    "  youtube_docs = youtube_loader.load()\n",
    "  # Combine doc\n",
    "  combined_docs = [doc.page_content for doc in youtube_docs]\n",
    "  text = \" \".join(combined_docs)\n",
    "  # Save text to file\n",
    "  video_path = youtube_docs[0].metadata[\"source\"]\n",
    "  youtube_name = os.path.splitext(os.path.basename(video_path))[0]\n",
    "  return save_text(text, youtube_name)\n",
    "\n",
    "# Multiple ways of extracting web content\n",
    "\n",
    "def website_webbase(url):\n",
    "  website_loader = WebBaseLoader(url)\n",
    "  website_data = website_loader.load()\n",
    "  # Combine doc\n",
    "  combined_docs = [doc.page_content for doc in website_data]\n",
    "  text = \" \".join(combined_docs)\n",
    "  return text\n",
    "\n",
    "def website_trafilatura(url):\n",
    "  downloaded = trafilatura.fetch_url(url)\n",
    "  return trafilatura.extract(downloaded)\n",
    "\n",
    "def website_justext(url):\n",
    "  response = requests.get(url)\n",
    "  paragraphs = justext.justext(response.content, justext.get_stoplist(\"English\"))\n",
    "  content = [paragraph.text for paragraph in paragraphs \\\n",
    "            if not paragraph.is_boilerplate]\n",
    "  text = \" \".join(content)\n",
    "  return text\n",
    "\n",
    "def get_website_youtube_text_file(urls):\n",
    "  for url in urls:\n",
    "    # This is a bit of a hacky way to determine whether it's youtube video\n",
    "    if \"youtube.com\" in url or \"youtu.be\" in url: save_youtube_transcript(url)\n",
    "    else: save_text(website_webbase(url))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "id": "H3gtJjSfoK5C"
   },
   "outputs": [],
   "source": [
    "get_website_youtube_text_file(url_list)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "id": "gFNbFdEKDBuu"
   },
   "outputs": [],
   "source": [
    "### Embedding Creation ###\n",
    "\n",
    "# See https://github.com/hwchase17/langchain/discussions/3786\n",
    "# for discussion of which splitter to use\n",
    "text_splitter = RecursiveCharacterTextSplitter(chunk_size=500, chunk_overlap=0)\n",
    "\n",
    "all_document_segments = []\n",
    "print(\"The following files have been uploaded:\")\n",
    "for filename in os.listdir():\n",
    "  if filename not in [\".config\", \"sample_data\"]:\n",
    "    print(\"\\t\"+filename)\n",
    "    loader = UnstructuredFileLoader(filename)\n",
    "    documents = loader.load()\n",
    "    document_segments = text_splitter.split_documents(documents)\n",
    "    all_document_segments.extend(document_segments)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "cBcOSf2rDBuv"
   },
   "source": [
    "Make sure that all of your documents are shown in the output from the previous code cell, then continue execution."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "id": "HH8WMgWSDBuw"
   },
   "outputs": [],
   "source": [
    "model_name = 'text-embedding-ada-002'\n",
    "model_embedding_dimension = 1536\n",
    "\n",
    "embeddings = OpenAIEmbeddings(\n",
    "    model=model_name\n",
    ")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "id": "HXJYOjYKDBuw"
   },
   "outputs": [],
   "source": [
    "### Dataset Creation ###\n",
    "dataset_path = f\"hub://{DEEPLAKE_USERNAME}/{dataset_name}\"\n",
    "db = DeepLake.from_documents(all_document_segments, dataset_path=dataset_path,\n",
    "                             embedding=embeddings, public=True)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "01UMqQcHDBux"
   },
   "source": [
    "### Sharing With Students"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "id": "l3TMy84LDBux"
   },
   "outputs": [],
   "source": [
    "display(Markdown(f'''To let students access the repository, give them the following URL:\n",
    "\n",
    "`{dataset_path}`'''))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "iUeTuV-WDBuy"
   },
   "source": [
    "Distribute the URL above to students. They will copy and paste it into the LLM learning application, which then allows their models to use all of the documents you uploaded as reference sources when responding to or creating questions."
   ]
  }
 ],
 "metadata": {
  "colab": {
   "include_colab_link": true,
   "provenance": []
  },
  "kernelspec": {
   "display_name": "Python 3",
   "name": "python3"
  },
  "language_info": {
   "name": "python"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}