{ "cells": [ { "cell_type": "code", "execution_count": null, "metadata": { "colab": { "base_uri": "https://localhost:8080/" }, "id": "i_g3-tUqCEQN", "outputId": "6fdc0d31-a2ca-4896-ea47-8ff7cfde008e" }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Fri Mar 10 06:08:27 2023 \n", "+-----------------------------------------------------------------------------+\n", "| NVIDIA-SMI 525.85.12 Driver Version: 525.85.12 CUDA Version: 12.0 |\n", "|-------------------------------+----------------------+----------------------+\n", "| GPU Name Persistence-M| Bus-Id Disp.A | Volatile Uncorr. ECC |\n", "| Fan Temp Perf Pwr:Usage/Cap| Memory-Usage | GPU-Util Compute M. |\n", "| | | MIG M. |\n", "|===============================+======================+======================|\n", "| 0 Tesla T4 Off | 00000000:00:04.0 Off | 0 |\n", "| N/A 67C P0 29W / 70W | 2275MiB / 15360MiB | 0% Default |\n", "| | | N/A |\n", "+-------------------------------+----------------------+----------------------+\n", " \n", "+-----------------------------------------------------------------------------+\n", "| Processes: |\n", "| GPU GI CI PID Type Process name GPU Memory |\n", "| ID ID Usage |\n", "|=============================================================================|\n", "+-----------------------------------------------------------------------------+\n" ] } ], "source": [ "# Runtime > Change runtime type > Hardware accelerator: GPU\n", "# Install Driver\n", "!nvidia-smi" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "colab": { "base_uri": "https://localhost:8080/" }, "id": "8EkL3CcxFtjh", "outputId": "bd44b1fb-33e4-45cb-9b77-917a6eca0743" }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ " Preparing metadata (setup.py) ... \u001b[?25l\u001b[?25hdone\n", " Preparing metadata (setup.py) ... \u001b[?25l\u001b[?25hdone\n", " Installing build dependencies ... \u001b[?25l\u001b[?25hdone\n", " Getting requirements to build wheel ... \u001b[?25l\u001b[?25hdone\n", " Installing backend dependencies ... \u001b[?25l\u001b[?25hdone\n", " Preparing metadata (pyproject.toml) ... \u001b[?25l\u001b[?25hdone\n", "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m7.6/7.6 MB\u001b[0m \u001b[31m87.4 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m199.2/199.2 KB\u001b[0m \u001b[31m22.6 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m1.3/1.3 MB\u001b[0m \u001b[31m16.3 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m49.1/49.1 KB\u001b[0m \u001b[31m6.3 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m73.5/73.5 KB\u001b[0m \u001b[31m8.4 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m62.8/62.8 KB\u001b[0m \u001b[31m6.4 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m2.1/2.1 MB\u001b[0m \u001b[31m65.7 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", "\u001b[?25h Building wheel for llama-index (setup.py) ... \u001b[?25l\u001b[?25hdone\n", " Building wheel for sentence_transformers (setup.py) ... \u001b[?25l\u001b[?25hdone\n", " Building wheel for openai (pyproject.toml) ... \u001b[?25l\u001b[?25hdone\n" ] } ], "source": [ "# Install LLM tools\n", "! pip install -q langchain gpt-index llama-index transformers sentence_transformers" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "id": "C8nj-t_YFuSH" }, "outputs": [], "source": [ "# Install visualization tools\n", "!pip install -q gradio" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "id": "Xqn1yfpEDy8D" }, "outputs": [], "source": [ "# Import Libraries\n", "import gradio as gr\n", "\n", "## Features\n", "from llama_index import Document\n", "\n", "## Model\n", "from langchain.llms.base import LLM\n", "from llama_index import LLMPredictor, GPTSimpleVectorIndex\n", "from transformers import pipeline\n", "import torch\n", "\n", "from langchain.embeddings.huggingface import HuggingFaceEmbeddings\n", "from llama_index import LangchainEmbedding" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "id": "sL4ORAReD766" }, "outputs": [], "source": [ "# Feature Functions\n", "\n", "## Text to Document\n", "def text_to_document(input_text):\n", " text_list = [input_text]\n", " return [Document(t) for t in text_list] # documents" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "colab": { "base_uri": "https://localhost:8080/", "height": 689, "referenced_widgets": [ "a62752f8b273454099934062834b43aa", "5ea8251fe45146919104e7c6ba120e54", "a6f984b2a739477eb6854061a3ab2508", "827465ed846a4acd9221d974005d3cde", "becf45a954004ff4b7b74a308982ccc4", "8f4523a674534550a606438526b110ca", "33d24d5a2b43499283fe3174148f22f6", "4ab2f2a9c39446d48e021d40113302dd", "ca55faf66d7f49fba36365c198405e0e", "298eb83b6986439ca974ccbdd8c5451e", "64c0cb906d254397ad4a2567fec81d2f", "f4c8fc7c8ea445218924d2939b8732cc", "f7ce3d98f1ba47008b3bb7834d9c64c7", "c78d26181fb243e2a8adc5d9e7df756a", "ce1b844c250841b3b8b1a610ed42101e", "37a153c91e8442e398b7936732501a13", "4e3194d1356d41978aefed6f348598e1", "938c12e3eb434292a010390cb1cd1795", "90297b0d395645018d768a74bd56aaea", "cbe13d611af8478681250eab2f498819", "9cb46c681dcb43bbaceaae48808a63a2", "91675384e9a64a0785960b79976f2ab1", "33df3276d7b44e5d9511bed035d29deb", "30f30440a3524d2a8ad93383294d55b8", "012eacd5e8f84b96b64602870bf89118", "6a554ba70f91443e8ccc282a2805f9f1", "e0474165792f4bcfb1b7c79933bd9e6b", "bd91a7b673d04e428c0f33832befc798", "34fd1db0bf344f84b72717af0400cbfb", "c18645f49481424091f0d865ba8b41d2", "c69c3b49661a4032a3e86491cda14fa8", "cb789f990afa4c8391b2932f539422fd", "ddbf20ff619f4edb9a2bbfee7aa27641", "dc10b56fab3d4951a1b499a38e474b9f", "e552daa5d40b476c98e45edf2ce4c1d0", "700d34f7579849c69c1c5f22ebefb4ca", "cef6361b7d5f43aea0e559ea968e8b34", "6e957758880143ec950225431aa85ba5", "bb098c15022d41bf9250ecd5a583bcaa", "c7ac04694d8e4cd2ae1a1e8f56f8fd01", "a52f16965bcf4804b75840cb67af1e05", "cc2996b59f54450ea5089270d30410f6", "09db2f2488ff4358af9b6ce886aeaee9", "b75ab46e984d4fedbf110b1e26424a7d", "65f95764b27144d3902c04dd22d58766", "491428ba1c0b4d1bbf989008e9357f64", "a6b984c958ad408dae40b7ada00a5a73", "9102d2057a2b4fd39a4c6b37f615bf75", "1e4c884c6811479895ba6c1b419a247d", "e37193ddb9b94bf0a10bb8ade7379cea", "87312b5acc2749c3a1568069ca2be2f3", "6b5f2538fbb04315996da0dc73fa6bf7", "d7119e88285241b4953122fd2f9daadc", "2ec76f71b85c4476b32ef7609c5866ab", "d58dfa50e76f49ada973252bef8b0817", "bb8abe6ddf14489dab9919a7ba0407af", "f9742ad038834588a898ed84a87b37b7", "113e54ea8c174bb1b853d306a86ca9b6", "73fc41f7e9214b2d897babdd543f8fb5", "7c81a9f364b54b9b8e930143b408d876", "90078b3940444270948d8f56757b3ca6", "55e96ec7673a47aabd92c6561b2a968e", "b62a12bba42848e8b9759f97b75782ba", "7250cdcfcb624bcbbce27932e9c3e273", "2d7a26a4496b4feda2513b96ec879a69", "0051ad8d5d9c4624ba2b92933978ab92", "eb05933f68184efe93af26e8f94d85b7", "44143f6e26a549a79826dc1bbc32fdb7", "cfee545d03b849118d8bc209fd4aa8e6", "8bd74be1855a4a97a6e2fb5cdb820e93", "002c2465ff2245ebb04f8c475b70e059", "d22192532e764e5bbf010201d20b291b", "2d49717e3b7d4ffe860e7c451ef2b198", "90708dfa2c434a7492738b76e612313d", "560094d7e1b545599fdc0632fef351d9", "35dccb533d154dfc96280f84925705c4", "718a664cd7c045d686efb15c3c548dbe", "9d599b312249491e879fab66def7a37f", "d2ab1d3d66624b84a7e41ecea9c59241", "c5a52c983948470ba8cf3347628a405b", "798d6cdd782a4283b7e6b92a71a3ec67", "e8cea35accdb4562982ff6b8d2a6dffb", "60bcdaa7057a4eeea5933e62170ed94c", "e9fb7b0cc96742a689ce634a523bdfc5", "913923e2e4ba41319188f7568f7ff0ae", "41eb2ec59bed4f4b916ed45e386b2423", "9b9efb16e5e649ea831af19aaae92fe1", "8f0d8343b50247f7a5d87b0a75db43ae", "8db676b82e1d418c801a27875041f23e", "f6658f38565148e8a6881e409a1d6ef2", "a110f97c91e64bc98c3e5616b14d4079", "994a40582f7240368f024189d43b6449", "44ba25de0cf74541ac3c9ff98546560d", "36580e99edbc49e39cc59ef0becae272", "896aef965c7d4c9e80bccb8af6e966d5", "3109c7f64aa246d1904c0967386b368c", "c6f690e1afc34f7dbd7e953c35e5766f", "fe1f45c738dd431781fb32ad11e568e4", "0472ce5ecb9e41bba939cb4040ac0fca", "3900157fa8964759b505e43236005d5b", "679b5ad24f134275a8cfd2713121f48a", "472d62b9bd5e4921999fc5d731c881ae", "4ec8cbabf1434363b4c487e1a8a5db1b", "9e0a6d66189b4932ac38b749ed7140d7", "d9a58cb20b5047fa9587be9956b5eb27", "2560b4521508494198a83b8ab9d29e12", "1bcecfebab3a46a29fe4549b7f1586f1", "dfde1b7498fa44f2a99d1a38a2e4147f", "ab9226e1884c477d947a74c15614b7ad", "c93c591201944121866e17b504c0976f", "bd3a1306f3d0474c972ef63274406da1", "7a06c041e2254a2c8f1de99ca560d76b", "c7a2a045e7ea484f81eb44d083e1b1c7", "c9599581a34b41de809465f36a799222", "8b1ef3a7730c4dfca27690c0ec21f4ea", "e9c66950b5b94ff395a5bd58833f1cd0", "998d27ceae3541bb814775b530ee9417", "e1e36a6999104a2cb8d34f219babaaf4", "fad766867c6d47f182904116928c118b", "2694e97512c54771b8f3eb5bdb3ca05a", "045a7b3acde14966a65b7e6cac263818", "96c457c80f4c449e897b8487ae79b008", "7e827aca35564d418e1ebb9852fdd091", "4dfdb0de22ca4246b0631f96fc98f434", "24a66a2378e8467d8070f4880060c831", "5e04061d4b7c414daf4cf4cf195d01e3", "51588c415ef34f3c8b1e3da8168361b7", "4a0d3cbbf46f49f5a315842214295998", "4717683ca4ea49d38ef75e2fde6c4ec6", "a7765f514b324b6b812563135e2c0aac", "e8d8caad5e07439db6b9fa57075f5a40", "35abf5dd6ddb4292a28e49e07e386e5e", "4688d92dc36f4dc4bbf2a5ecbbdf4cb3", "0ee02e0e5988480089947a35b8a005b5", "3b2db8b5db234fb6a3edafca82045fef", "92d1799c69674862a1f1771c9b86a75e", "850c0661c035406ea9d7bb01858da401", "fb5214ac34664ad18e44a616ed476c91", "f1f6db95185a44789d70fc2b80969b7f", "bdf48eda7aa8454292ec743e6d3dc9ee", "c506ae0c35424776ad41c78eaf48dba6", "cda61d0176854a688d73a6cc87002306", "13c8c6a692be4c63b98beb9ab9bd3e6c", "a9d935c691e946e1a56424365cb9adf3", "a872d330d67b48429d74eea2dd85c14c", "3ffcb9d6e100439cb639e7e1e3dc6a5e", "0a3fc4abb45a4f07b4898c663fe05e25", "ce0dabd15672438abf5397f117548c6a", "002dde98b7674f71a7259db76000f250", "b7e50e495f0a453abbbd742abd95de04", "b08a25029add421bb8c8a0c90fac6352", "3f84b45c188b4e64815429b03f3d602c", "05d0fb91fd924f6595d36c87895f24dc", "2497c27627394569964f61326bd928cd", "35144c703d814559a15369f1453fc742", "2d23c45a1bed4a469d8c9c8037d776cf", "3b02ac23d11740e487fe72dfc68026fb", "8b4c852b95104d3084781bc992476fe2", "75243f94d9ad4a2892ba28e57e6c4a9f", "0ca294348f6e4c4694b0d3a5dd95b5f6", "5700b12fe14341ce83e21faabb2ae3b1", "d8e7a12580524be8a90c55c132427bdc", "988d52820a9742fe82dc502f63ec08f3", "33de6c2088584f3ab89c3778d7c65efc", "a23272f0812f486bbad5daba0866e205", "a74b66b299d54419a246e22d9886ead3", "8d2873a29d284683a3a069f56e7346cb", "5b4e0756e1144ca79fa0becf318915ea", "abf2ce88d6354c72be14a23e58f2134e", "585c83d53e6a4783acb6053838b92066", "6bb3cc182aa444a9a3f4ac861534551f", "6cfbc23fe4264a2cbe724e969659ae02", "cfa8132e178643c49c21570945780f02", "a16c32bbf9cb4260bf4f7eb2fb99dc6e", "3d7878af46e4470bb7d0e6b7d14f5b07", "4e283927c7af4a3ea0e96481e775cc99", "ecec3ed36dc34552bad285fad776e663", "cc6d920f7c25476aad073f375e3a83d0", "28f59ae819904244983e7d8f751928ab", "52a60cd393c4408e9aa098e173dd2633", "605b7f6085df4925a3f21bc358292b91", "6b5ee719caf3485d8a0dcf3e5159a445", "216432163c004ab0902deee9815531e4", "ebd123da7e7a46b88ad48fa7e8509426", "415d19f218ce4bf2bac7a8b299cfb884", "39b67782cb8f4e2191e7d0ffc43cbfc4", "0e8992ef6c554d4eae263e65cbe02e00", "2971f33a128643f88e509640683e2589", "656178a1a86f49d68fc904547242ab49", "36ece5c7bf064a71b728d5e7337ebd51", "c850bafb544948968f03a0110181df0f", "c6cbd85b231c4d8dac41025a2b0549af", "081251b7427547f0add131559086d801", "d2e46bac097a4945bf84def6d861feae", "6cca80bdf71b43dcad78ed7aaf2c7b38", "421184495620403b96f84cdffcd81a7d", "4b42dbc08cdc4f09ae6ea88e1cfb52c1", "752881a2ae444587b523e6db062efa4e", "18ac711875804f27a9d408171e5ba3e2", "2ee467014e474b91a4d19112c1975c2e", "3d6ae4c00eb9481bbfa7740259e772fc", "f1e7fccbc55548e8a0dc06e19bf5eb8d", "c1d37a40890d42e28beddcaf74fbefc4", "522e053dd83d423bb0e255b94f591fd1", "fa42580684194ccdb04a1a9b99b2ed0e", "81c556fb5cf34e4c8fa3c616fdf0afa4", "d127574d77eb4e388cf48d9a636b1541", "3cd87ab67ed047f1b658016200033f5e", "1250531200554a88a96317be2cd960d6", "a65c71937e8f4be9a4cd70db1b9d87f5", "026f6bb04c364a10854e3fa7c97cd9ca", "8bf84fc1b05e4ab4b890505fe0b8fe87", "9129d01c97a74a8fabdbb853d52f5db5", "ead8eafa27af4b03964c45bab2d7b278", "c496aba2e1b7485bbda97b36e359db8e", "c7309469906d492599ca6014c629cdcf", "5d69b79c68874cae93030666f5550061", "7b8cec12810742e08cca9dd3cc14d640", "c4ab60daad1b450291e33af873b199a5", "f74ae6767dc14dd8938b64df74b669a4", "8c2b8f13e5be45ed98949666e8fdb0fc", "b240f543e0124cfd99da4e3f8d6ddcb0", "b262120d60994618a39efa8575d30f13", "634a80530443419683851b7b1880bc53", "82a6c558fab04cd6938f571b36102f7d", "9be363a1ccbb4032bd0b76af5fde77c1", "7f2b1068f84247689bb1127d83d380a1", "6b6b564527c3436d926167928b1ed5bb", "d1272987b2404d85bdbc8d567bc4bb9f", "f49aaa0757f2429dbd7ffd2ef33cc0e4", "c6640a63c4984e4cadf7479ccdf54f4b" ] }, "id": "FgRIa2ZPD_aj", "outputId": "e7962b5b-8833-4cb5-ef84-189375e28352" }, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "a62752f8b273454099934062834b43aa", "version_major": 2, "version_minor": 0 }, "text/plain": [ "Downloading (…)lve/main/config.json: 0%| | 0.00/1.40k [00:00, ?B/s]" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "f4c8fc7c8ea445218924d2939b8732cc", "version_major": 2, "version_minor": 0 }, "text/plain": [ "Downloading pytorch_model.bin: 0%| | 0.00/990M [00:00, ?B/s]" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "33df3276d7b44e5d9511bed035d29deb", "version_major": 2, "version_minor": 0 }, "text/plain": [ "Downloading (…)neration_config.json: 0%| | 0.00/147 [00:00, ?B/s]" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "dc10b56fab3d4951a1b499a38e474b9f", "version_major": 2, "version_minor": 0 }, "text/plain": [ "Downloading (…)okenizer_config.json: 0%| | 0.00/2.54k [00:00, ?B/s]" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "65f95764b27144d3902c04dd22d58766", "version_major": 2, "version_minor": 0 }, "text/plain": [ "Downloading spiece.model: 0%| | 0.00/792k [00:00, ?B/s]" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "bb8abe6ddf14489dab9919a7ba0407af", "version_major": 2, "version_minor": 0 }, "text/plain": [ "Downloading (…)/main/tokenizer.json: 0%| | 0.00/2.42M [00:00, ?B/s]" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "eb05933f68184efe93af26e8f94d85b7", "version_major": 2, "version_minor": 0 }, "text/plain": [ "Downloading (…)cial_tokens_map.json: 0%| | 0.00/2.20k [00:00, ?B/s]" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "9d599b312249491e879fab66def7a37f", "version_major": 2, "version_minor": 0 }, "text/plain": [ "Downloading (…)a8e1d/.gitattributes: 0%| | 0.00/1.18k [00:00, ?B/s]" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "8db676b82e1d418c801a27875041f23e", "version_major": 2, "version_minor": 0 }, "text/plain": [ "Downloading (…)_Pooling/config.json: 0%| | 0.00/190 [00:00, ?B/s]" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "3900157fa8964759b505e43236005d5b", "version_major": 2, "version_minor": 0 }, "text/plain": [ "Downloading (…)b20bca8e1d/README.md: 0%| | 0.00/10.6k [00:00, ?B/s]" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "bd3a1306f3d0474c972ef63274406da1", "version_major": 2, "version_minor": 0 }, "text/plain": [ "Downloading (…)0bca8e1d/config.json: 0%| | 0.00/571 [00:00, ?B/s]" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "96c457c80f4c449e897b8487ae79b008", "version_major": 2, "version_minor": 0 }, "text/plain": [ "Downloading (…)ce_transformers.json: 0%| | 0.00/116 [00:00, ?B/s]" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "4688d92dc36f4dc4bbf2a5ecbbdf4cb3", "version_major": 2, "version_minor": 0 }, "text/plain": [ "Downloading (…)e1d/data_config.json: 0%| | 0.00/39.3k [00:00, ?B/s]" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "a9d935c691e946e1a56424365cb9adf3", "version_major": 2, "version_minor": 0 }, "text/plain": [ "Downloading pytorch_model.bin: 0%| | 0.00/438M [00:00, ?B/s]" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "35144c703d814559a15369f1453fc742", "version_major": 2, "version_minor": 0 }, "text/plain": [ "Downloading (…)nce_bert_config.json: 0%| | 0.00/53.0 [00:00, ?B/s]" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "a74b66b299d54419a246e22d9886ead3", "version_major": 2, "version_minor": 0 }, "text/plain": [ "Downloading (…)cial_tokens_map.json: 0%| | 0.00/239 [00:00, ?B/s]" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "ecec3ed36dc34552bad285fad776e663", "version_major": 2, "version_minor": 0 }, "text/plain": [ "Downloading (…)a8e1d/tokenizer.json: 0%| | 0.00/466k [00:00, ?B/s]" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "2971f33a128643f88e509640683e2589", "version_major": 2, "version_minor": 0 }, "text/plain": [ "Downloading (…)okenizer_config.json: 0%| | 0.00/363 [00:00, ?B/s]" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "18ac711875804f27a9d408171e5ba3e2", "version_major": 2, "version_minor": 0 }, "text/plain": [ "Downloading (…)8e1d/train_script.py: 0%| | 0.00/13.1k [00:00, ?B/s]" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "a65c71937e8f4be9a4cd70db1b9d87f5", "version_major": 2, "version_minor": 0 }, "text/plain": [ "Downloading (…)b20bca8e1d/vocab.txt: 0%| | 0.00/232k [00:00, ?B/s]" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "8c2b8f13e5be45ed98949666e8fdb0fc", "version_major": 2, "version_minor": 0 }, "text/plain": [ "Downloading (…)bca8e1d/modules.json: 0%| | 0.00/349 [00:00, ?B/s]" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "# Model Functions & Class\n", "class FlanLLM(LLM):\n", " model_name = \"google/flan-t5-base\"\n", " pipeline = pipeline(\"text2text-generation\", model=model_name,\n", " device=0, model_kwargs={\"torch_dtype\": torch.bfloat16})\n", "\n", " def _call(self, prompt, stop=None):\n", " return self.pipeline(prompt, max_length=9999)[0][\"generated_text\"]\n", "\n", " def _identifying_params(self):\n", " return {\"name_of_model\": self.model_name}\n", "\n", " def _llm_type(self):\n", " return \"custom\"\n", "\n", "llm_predictor = LLMPredictor(llm=FlanLLM())\n", "hfemb = HuggingFaceEmbeddings()\n", "embed_model = LangchainEmbedding(hfemb)\n", "\n", "def document_to_index(documents):\n", " global index\n", " index = GPTSimpleVectorIndex(\n", " documents, embed_model=embed_model, llm_predictor=llm_predictor)\n", " return('Index successfully saved.')\n", "\n", "def query_and_response(chat_history, user_query):\n", " bot_response = index.query(user_query)\n", " response = \"\"\n", " for letter in ''.join(bot_response.response):\n", " response += f'{letter}'\n", " yield chat_history + [(user_query, response)]" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "colab": { "base_uri": "https://localhost:8080/", "height": 660 }, "id": "A3GUCanLERGD", "outputId": "418e1c6c-e039-4354-8c29-6baf06e39597" }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Setting queue=True in a Colab notebook requires sharing enabled. Setting `share=True` (you can turn this off by setting `share=False` in `launch()` explicitly).\n", "\n", "Colab notebook detected. This cell will run indefinitely so that you can see errors and logs. To turn off, set debug=False in launch().\n", "Running on public URL: https://1010e1d1a156b247ae.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": [ "
" ], "text/plain": [ "