switch
Browse files- Chatbot_pdf.ipynb +0 -636
- app.py +4 -0
Chatbot_pdf.ipynb
DELETED
|
@@ -1,636 +0,0 @@
|
|
| 1 |
-
{
|
| 2 |
-
"cells": [
|
| 3 |
-
{
|
| 4 |
-
"cell_type": "markdown",
|
| 5 |
-
"id": "04815d1b-44ee-4bd3-878e-fa0c3bf9fa7f",
|
| 6 |
-
"metadata": {
|
| 7 |
-
"id": "04815d1b-44ee-4bd3-878e-fa0c3bf9fa7f",
|
| 8 |
-
"tags": []
|
| 9 |
-
},
|
| 10 |
-
"source": [
|
| 11 |
-
"# LangChain QA Panel App\n",
|
| 12 |
-
"#Dan"
|
| 13 |
-
]
|
| 14 |
-
},
|
| 15 |
-
{
|
| 16 |
-
"cell_type": "code",
|
| 17 |
-
"execution_count": null,
|
| 18 |
-
"id": "VY41CG0Nzrv8",
|
| 19 |
-
"metadata": {
|
| 20 |
-
"colab": {
|
| 21 |
-
"base_uri": "https://localhost:8080/"
|
| 22 |
-
},
|
| 23 |
-
"id": "VY41CG0Nzrv8",
|
| 24 |
-
"outputId": "15f50e07-c724-4074-c3a3-5087a386e1cb"
|
| 25 |
-
},
|
| 26 |
-
"outputs": [],
|
| 27 |
-
"source": [
|
| 28 |
-
"#pip install langchain openai chromadb tiktoken pypdf panel langchain_community"
|
| 29 |
-
]
|
| 30 |
-
},
|
| 31 |
-
{
|
| 32 |
-
"cell_type": "code",
|
| 33 |
-
"execution_count": 23,
|
| 34 |
-
"id": "9a464409-d064-4766-a9cb-5119f6c4b8f5",
|
| 35 |
-
"metadata": {
|
| 36 |
-
"id": "9a464409-d064-4766-a9cb-5119f6c4b8f5",
|
| 37 |
-
"tags": []
|
| 38 |
-
},
|
| 39 |
-
"outputs": [],
|
| 40 |
-
"source": [
|
| 41 |
-
"import os\n",
|
| 42 |
-
"from langchain.chains import RetrievalQA\n",
|
| 43 |
-
"from langchain_openai import OpenAI, OpenAIEmbeddings\n",
|
| 44 |
-
"from langchain.document_loaders import TextLoader\n",
|
| 45 |
-
"from langchain.document_loaders import PyPDFLoader\n",
|
| 46 |
-
"from langchain.indexes import VectorstoreIndexCreator\n",
|
| 47 |
-
"from langchain.text_splitter import CharacterTextSplitter\n",
|
| 48 |
-
"from langchain.vectorstores import Chroma\n",
|
| 49 |
-
"import panel as pn\n",
|
| 50 |
-
"import tempfile\n"
|
| 51 |
-
]
|
| 52 |
-
},
|
| 53 |
-
{
|
| 54 |
-
"cell_type": "code",
|
| 55 |
-
"execution_count": 24,
|
| 56 |
-
"id": "b2d07ea5-9ff2-4c96-a8dc-92895d870b73",
|
| 57 |
-
"metadata": {
|
| 58 |
-
"id": "b2d07ea5-9ff2-4c96-a8dc-92895d870b73",
|
| 59 |
-
"tags": []
|
| 60 |
-
},
|
| 61 |
-
"outputs": [
|
| 62 |
-
{
|
| 63 |
-
"data": {
|
| 64 |
-
"text/html": [
|
| 65 |
-
"<script type=\"esms-options\">{\"shimMode\": true}</script><style>*[data-root-id],\n",
|
| 66 |
-
"*[data-root-id] > * {\n",
|
| 67 |
-
" box-sizing: border-box;\n",
|
| 68 |
-
" font-family: var(--jp-ui-font-family);\n",
|
| 69 |
-
" font-size: var(--jp-ui-font-size1);\n",
|
| 70 |
-
" color: var(--vscode-editor-foreground, var(--jp-ui-font-color1));\n",
|
| 71 |
-
"}\n",
|
| 72 |
-
"\n",
|
| 73 |
-
"/* Override VSCode background color */\n",
|
| 74 |
-
".cell-output-ipywidget-background:has(\n",
|
| 75 |
-
" > .cell-output-ipywidget-background > .lm-Widget > *[data-root-id]\n",
|
| 76 |
-
" ),\n",
|
| 77 |
-
".cell-output-ipywidget-background:has(> .lm-Widget > *[data-root-id]) {\n",
|
| 78 |
-
" background-color: transparent !important;\n",
|
| 79 |
-
"}\n",
|
| 80 |
-
"</style>"
|
| 81 |
-
]
|
| 82 |
-
},
|
| 83 |
-
"metadata": {},
|
| 84 |
-
"output_type": "display_data"
|
| 85 |
-
},
|
| 86 |
-
{
|
| 87 |
-
"data": {
|
| 88 |
-
"application/javascript": "(function(root) {\n function now() {\n return new Date();\n }\n\n const force = true;\n const py_version = '3.6.2'.replace('rc', '-rc.').replace('.dev', '-dev.');\n const reloading = false;\n const Bokeh = root.Bokeh;\n\n // Set a timeout for this load but only if we are not already initializing\n if (typeof (root._bokeh_timeout) === \"undefined\" || (force || !root._bokeh_is_initializing)) {\n root._bokeh_timeout = Date.now() + 5000;\n root._bokeh_failed_load = false;\n }\n\n function run_callbacks() {\n try {\n root._bokeh_onload_callbacks.forEach(function(callback) {\n if (callback != null)\n callback();\n });\n } finally {\n delete root._bokeh_onload_callbacks;\n }\n console.debug(\"Bokeh: all callbacks have finished\");\n }\n\n function load_libs(css_urls, js_urls, js_modules, js_exports, callback) {\n if (css_urls == null) css_urls = [];\n if (js_urls == null) js_urls = [];\n if (js_modules == null) js_modules = [];\n if (js_exports == null) js_exports = {};\n\n root._bokeh_onload_callbacks.push(callback);\n\n if (root._bokeh_is_loading > 0) {\n // Don't load bokeh if it is still initializing\n console.debug(\"Bokeh: BokehJS is being loaded, scheduling callback at\", now());\n return null;\n } else if (js_urls.length === 0 && js_modules.length === 0 && Object.keys(js_exports).length === 0) {\n // There is nothing to load\n run_callbacks();\n return null;\n }\n\n function on_load() {\n root._bokeh_is_loading--;\n if (root._bokeh_is_loading === 0) {\n console.debug(\"Bokeh: all BokehJS libraries/stylesheets loaded\");\n run_callbacks()\n }\n }\n window._bokeh_on_load = on_load\n\n function on_error(e) {\n const src_el = e.srcElement\n console.error(\"failed to load \" + (src_el.href || src_el.src));\n }\n\n const skip = [];\n if (window.requirejs) {\n window.requirejs.config({'packages': {}, 'paths': {'Quill': 'https://cdn.quilljs.com/1.3.7/quill'}, 'shim': {}});\n require([\"Quill\"], function(Quill) {\n window.Quill = Quill\n on_load()\n })\n root._bokeh_is_loading = css_urls.length + 1;\n } else {\n root._bokeh_is_loading = css_urls.length + js_urls.length + js_modules.length + Object.keys(js_exports).length;\n }\n\n const existing_stylesheets = []\n const links = document.getElementsByTagName('link')\n for (let i = 0; i < links.length; i++) {\n const link = links[i]\n if (link.href != null) {\n existing_stylesheets.push(link.href)\n }\n }\n for (let i = 0; i < css_urls.length; i++) {\n const url = css_urls[i];\n const escaped = encodeURI(url)\n if (existing_stylesheets.indexOf(escaped) !== -1) {\n on_load()\n continue;\n }\n const element = document.createElement(\"link\");\n element.onload = on_load;\n element.onerror = on_error;\n element.rel = \"stylesheet\";\n element.type = \"text/css\";\n element.href = url;\n console.debug(\"Bokeh: injecting link tag for BokehJS stylesheet: \", url);\n document.body.appendChild(element);\n } if (((window.Quill !== undefined) && (!(window.Quill instanceof HTMLElement))) || window.requirejs) {\n var urls = ['https://cdn.holoviz.org/panel/1.5.4/dist/bundled/quillinput/1.3.7/quill.js'];\n for (var i = 0; i < urls.length; i++) {\n skip.push(encodeURI(urls[i]))\n }\n } var existing_scripts = []\n const scripts = document.getElementsByTagName('script')\n for (let i = 0; i < scripts.length; i++) {\n var script = scripts[i]\n if (script.src != null) {\n existing_scripts.push(script.src)\n }\n }\n for (let i = 0; i < js_urls.length; i++) {\n const url = js_urls[i];\n const escaped = encodeURI(url)\n if (skip.indexOf(escaped) !== -1 || existing_scripts.indexOf(escaped) !== -1) {\n if (!window.requirejs) {\n on_load();\n }\n continue;\n }\n const element = document.createElement('script');\n element.onload = on_load;\n element.onerror = on_error;\n element.async = false;\n element.src = url;\n console.debug(\"Bokeh: injecting script tag for BokehJS library: \", url);\n document.head.appendChild(element);\n }\n for (let i = 0; i < js_modules.length; i++) {\n const url = js_modules[i];\n const escaped = encodeURI(url)\n if (skip.indexOf(escaped) !== -1 || existing_scripts.indexOf(escaped) !== -1) {\n if (!window.requirejs) {\n on_load();\n }\n continue;\n }\n var element = document.createElement('script');\n element.onload = on_load;\n element.onerror = on_error;\n element.async = false;\n element.src = url;\n element.type = \"module\";\n console.debug(\"Bokeh: injecting script tag for BokehJS library: \", url);\n document.head.appendChild(element);\n }\n for (const name in js_exports) {\n const url = js_exports[name];\n const escaped = encodeURI(url)\n if (skip.indexOf(escaped) >= 0 || root[name] != null) {\n if (!window.requirejs) {\n on_load();\n }\n continue;\n }\n var element = document.createElement('script');\n element.onerror = on_error;\n element.async = false;\n element.type = \"module\";\n console.debug(\"Bokeh: injecting script tag for BokehJS library: \", url);\n element.textContent = `\n import ${name} from \"${url}\"\n window.${name} = ${name}\n window._bokeh_on_load()\n `\n document.head.appendChild(element);\n }\n if (!js_urls.length && !js_modules.length) {\n on_load()\n }\n };\n\n function inject_raw_css(css) {\n const element = document.createElement(\"style\");\n element.appendChild(document.createTextNode(css));\n document.body.appendChild(element);\n }\n\n const js_urls = [\"https://cdn.holoviz.org/panel/1.5.4/dist/bundled/reactiveesm/es-module-shims@^1.10.0/dist/es-module-shims.min.js\", \"https://cdn.holoviz.org/panel/1.5.4/dist/bundled/quillinput/1.3.7/quill.js\", \"https://cdn.bokeh.org/bokeh/release/bokeh-3.6.2.min.js\", \"https://cdn.bokeh.org/bokeh/release/bokeh-gl-3.6.2.min.js\", \"https://cdn.bokeh.org/bokeh/release/bokeh-widgets-3.6.2.min.js\", \"https://cdn.bokeh.org/bokeh/release/bokeh-tables-3.6.2.min.js\", \"https://cdn.holoviz.org/panel/1.5.4/dist/panel.min.js\"];\n const js_modules = [];\n const js_exports = {};\n const css_urls = [\"https://cdn.holoviz.org/panel/1.5.4/dist/bundled/quillinput/1.3.7/quill.bubble.css?v=1.5.4\", \"https://cdn.holoviz.org/panel/1.5.4/dist/bundled/quillinput/1.3.7/quill.snow.css?v=1.5.4\"];\n const inline_js = [ function(Bokeh) {\n Bokeh.set_log_level(\"info\");\n },\nfunction(Bokeh) {} // ensure no trailing comma for IE\n ];\n\n function run_inline_js() {\n if ((root.Bokeh !== undefined) || (force === true)) {\n for (let i = 0; i < inline_js.length; i++) {\n try {\n inline_js[i].call(root, root.Bokeh);\n } catch(e) {\n if (!reloading) {\n throw e;\n }\n }\n }\n // Cache old bokeh versions\n if (Bokeh != undefined && !reloading) {\n var NewBokeh = root.Bokeh;\n if (Bokeh.versions === undefined) {\n Bokeh.versions = new Map();\n }\n if (NewBokeh.version !== Bokeh.version) {\n Bokeh.versions.set(NewBokeh.version, NewBokeh)\n }\n root.Bokeh = Bokeh;\n }\n } else if (Date.now() < root._bokeh_timeout) {\n setTimeout(run_inline_js, 100);\n } else if (!root._bokeh_failed_load) {\n console.log(\"Bokeh: BokehJS failed to load within specified timeout.\");\n root._bokeh_failed_load = true;\n }\n root._bokeh_is_initializing = false\n }\n\n function load_or_wait() {\n // Implement a backoff loop that tries to ensure we do not load multiple\n // versions of Bokeh and its dependencies at the same time.\n // In recent versions we use the root._bokeh_is_initializing flag\n // to determine whether there is an ongoing attempt to initialize\n // bokeh, however for backward compatibility we also try to ensure\n // that we do not start loading a newer (Panel>=1.0 and Bokeh>3) version\n // before older versions are fully initialized.\n if (root._bokeh_is_initializing && Date.now() > root._bokeh_timeout) {\n // If the timeout and bokeh was not successfully loaded we reset\n // everything and try loading again\n root._bokeh_timeout = Date.now() + 5000;\n root._bokeh_is_initializing = false;\n root._bokeh_onload_callbacks = undefined;\n root._bokeh_is_loading = 0\n console.log(\"Bokeh: BokehJS was loaded multiple times but one version failed to initialize.\");\n load_or_wait();\n } else if (root._bokeh_is_initializing || (typeof root._bokeh_is_initializing === \"undefined\" && root._bokeh_onload_callbacks !== undefined)) {\n setTimeout(load_or_wait, 100);\n } else {\n root._bokeh_is_initializing = true\n root._bokeh_onload_callbacks = []\n const bokeh_loaded = root.Bokeh != null && (root.Bokeh.version === py_version || (root.Bokeh.versions !== undefined && root.Bokeh.versions.has(py_version)));\n if (!reloading && !bokeh_loaded) {\n if (root.Bokeh) {\n root.Bokeh = undefined;\n }\n console.debug(\"Bokeh: BokehJS not loaded, scheduling load and callback at\", now());\n }\n load_libs(css_urls, js_urls, js_modules, js_exports, function() {\n console.debug(\"Bokeh: BokehJS plotting callback run at\", now());\n run_inline_js();\n });\n }\n }\n // Give older versions of the autoload script a head-start to ensure\n // they initialize before we start loading newer version.\n setTimeout(load_or_wait, 100)\n}(window));",
|
| 89 |
-
"application/vnd.holoviews_load.v0+json": ""
|
| 90 |
-
},
|
| 91 |
-
"metadata": {},
|
| 92 |
-
"output_type": "display_data"
|
| 93 |
-
},
|
| 94 |
-
{
|
| 95 |
-
"data": {
|
| 96 |
-
"application/javascript": "\nif ((window.PyViz === undefined) || (window.PyViz instanceof HTMLElement)) {\n window.PyViz = {comms: {}, comm_status:{}, kernels:{}, receivers: {}, plot_index: []}\n}\n\n\n function JupyterCommManager() {\n }\n\n JupyterCommManager.prototype.register_target = function(plot_id, comm_id, msg_handler) {\n if (window.comm_manager || ((window.Jupyter !== undefined) && (Jupyter.notebook.kernel != null))) {\n var comm_manager = window.comm_manager || Jupyter.notebook.kernel.comm_manager;\n comm_manager.register_target(comm_id, function(comm) {\n comm.on_msg(msg_handler);\n });\n } else if ((plot_id in window.PyViz.kernels) && (window.PyViz.kernels[plot_id])) {\n window.PyViz.kernels[plot_id].registerCommTarget(comm_id, function(comm) {\n comm.onMsg = msg_handler;\n });\n } else if (typeof google != 'undefined' && google.colab.kernel != null) {\n google.colab.kernel.comms.registerTarget(comm_id, (comm) => {\n var messages = comm.messages[Symbol.asyncIterator]();\n function processIteratorResult(result) {\n var message = result.value;\n console.log(message)\n var content = {data: message.data, comm_id};\n var buffers = []\n for (var buffer of message.buffers || []) {\n buffers.push(new DataView(buffer))\n }\n var metadata = message.metadata || {};\n var msg = {content, buffers, metadata}\n msg_handler(msg);\n return messages.next().then(processIteratorResult);\n }\n return messages.next().then(processIteratorResult);\n })\n }\n }\n\n JupyterCommManager.prototype.get_client_comm = function(plot_id, comm_id, msg_handler) {\n if (comm_id in window.PyViz.comms) {\n return window.PyViz.comms[comm_id];\n } else if (window.comm_manager || ((window.Jupyter !== undefined) && (Jupyter.notebook.kernel != null))) {\n var comm_manager = window.comm_manager || Jupyter.notebook.kernel.comm_manager;\n var comm = comm_manager.new_comm(comm_id, {}, {}, {}, comm_id);\n if (msg_handler) {\n comm.on_msg(msg_handler);\n }\n } else if ((plot_id in window.PyViz.kernels) && (window.PyViz.kernels[plot_id])) {\n var comm = window.PyViz.kernels[plot_id].connectToComm(comm_id);\n comm.open();\n if (msg_handler) {\n comm.onMsg = msg_handler;\n }\n } else if (typeof google != 'undefined' && google.colab.kernel != null) {\n var comm_promise = google.colab.kernel.comms.open(comm_id)\n comm_promise.then((comm) => {\n window.PyViz.comms[comm_id] = comm;\n if (msg_handler) {\n var messages = comm.messages[Symbol.asyncIterator]();\n function processIteratorResult(result) {\n var message = result.value;\n var content = {data: message.data};\n var metadata = message.metadata || {comm_id};\n var msg = {content, metadata}\n msg_handler(msg);\n return messages.next().then(processIteratorResult);\n }\n return messages.next().then(processIteratorResult);\n }\n }) \n var sendClosure = (data, metadata, buffers, disposeOnDone) => {\n return comm_promise.then((comm) => {\n comm.send(data, metadata, buffers, disposeOnDone);\n });\n };\n var comm = {\n send: sendClosure\n };\n }\n window.PyViz.comms[comm_id] = comm;\n return comm;\n }\n window.PyViz.comm_manager = new JupyterCommManager();\n \n\n\nvar JS_MIME_TYPE = 'application/javascript';\nvar HTML_MIME_TYPE = 'text/html';\nvar EXEC_MIME_TYPE = 'application/vnd.holoviews_exec.v0+json';\nvar CLASS_NAME = 'output';\n\n/**\n * Render data to the DOM node\n */\nfunction render(props, node) {\n var div = document.createElement(\"div\");\n var script = document.createElement(\"script\");\n node.appendChild(div);\n node.appendChild(script);\n}\n\n/**\n * Handle when a new output is added\n */\nfunction handle_add_output(event, handle) {\n var output_area = handle.output_area;\n var output = handle.output;\n if ((output.data == undefined) || (!output.data.hasOwnProperty(EXEC_MIME_TYPE))) {\n return\n }\n var id = output.metadata[EXEC_MIME_TYPE][\"id\"];\n var toinsert = output_area.element.find(\".\" + CLASS_NAME.split(' ')[0]);\n if (id !== undefined) {\n var nchildren = toinsert.length;\n var html_node = toinsert[nchildren-1].children[0];\n html_node.innerHTML = output.data[HTML_MIME_TYPE];\n var scripts = [];\n var nodelist = html_node.querySelectorAll(\"script\");\n for (var i in nodelist) {\n if (nodelist.hasOwnProperty(i)) {\n scripts.push(nodelist[i])\n }\n }\n\n scripts.forEach( function (oldScript) {\n var newScript = document.createElement(\"script\");\n var attrs = [];\n var nodemap = oldScript.attributes;\n for (var j in nodemap) {\n if (nodemap.hasOwnProperty(j)) {\n attrs.push(nodemap[j])\n }\n }\n attrs.forEach(function(attr) { newScript.setAttribute(attr.name, attr.value) });\n newScript.appendChild(document.createTextNode(oldScript.innerHTML));\n oldScript.parentNode.replaceChild(newScript, oldScript);\n });\n if (JS_MIME_TYPE in output.data) {\n toinsert[nchildren-1].children[1].textContent = output.data[JS_MIME_TYPE];\n }\n output_area._hv_plot_id = id;\n if ((window.Bokeh !== undefined) && (id in Bokeh.index)) {\n window.PyViz.plot_index[id] = Bokeh.index[id];\n } else {\n window.PyViz.plot_index[id] = null;\n }\n } else if (output.metadata[EXEC_MIME_TYPE][\"server_id\"] !== undefined) {\n var bk_div = document.createElement(\"div\");\n bk_div.innerHTML = output.data[HTML_MIME_TYPE];\n var script_attrs = bk_div.children[0].attributes;\n for (var i = 0; i < script_attrs.length; i++) {\n toinsert[toinsert.length - 1].childNodes[1].setAttribute(script_attrs[i].name, script_attrs[i].value);\n }\n // store reference to server id on output_area\n output_area._bokeh_server_id = output.metadata[EXEC_MIME_TYPE][\"server_id\"];\n }\n}\n\n/**\n * Handle when an output is cleared or removed\n */\nfunction handle_clear_output(event, handle) {\n var id = handle.cell.output_area._hv_plot_id;\n var server_id = handle.cell.output_area._bokeh_server_id;\n if (((id === undefined) || !(id in PyViz.plot_index)) && (server_id !== undefined)) { return; }\n var comm = window.PyViz.comm_manager.get_client_comm(\"hv-extension-comm\", \"hv-extension-comm\", function () {});\n if (server_id !== null) {\n comm.send({event_type: 'server_delete', 'id': server_id});\n return;\n } else if (comm !== null) {\n comm.send({event_type: 'delete', 'id': id});\n }\n delete PyViz.plot_index[id];\n if ((window.Bokeh !== undefined) & (id in window.Bokeh.index)) {\n var doc = window.Bokeh.index[id].model.document\n doc.clear();\n const i = window.Bokeh.documents.indexOf(doc);\n if (i > -1) {\n window.Bokeh.documents.splice(i, 1);\n }\n }\n}\n\n/**\n * Handle kernel restart event\n */\nfunction handle_kernel_cleanup(event, handle) {\n delete PyViz.comms[\"hv-extension-comm\"];\n window.PyViz.plot_index = {}\n}\n\n/**\n * Handle update_display_data messages\n */\nfunction handle_update_output(event, handle) {\n handle_clear_output(event, {cell: {output_area: handle.output_area}})\n handle_add_output(event, handle)\n}\n\nfunction register_renderer(events, OutputArea) {\n function append_mime(data, metadata, element) {\n // create a DOM node to render to\n var toinsert = this.create_output_subarea(\n metadata,\n CLASS_NAME,\n EXEC_MIME_TYPE\n );\n this.keyboard_manager.register_events(toinsert);\n // Render to node\n var props = {data: data, metadata: metadata[EXEC_MIME_TYPE]};\n render(props, toinsert[0]);\n element.append(toinsert);\n return toinsert\n }\n\n events.on('output_added.OutputArea', handle_add_output);\n events.on('output_updated.OutputArea', handle_update_output);\n events.on('clear_output.CodeCell', handle_clear_output);\n events.on('delete.Cell', handle_clear_output);\n events.on('kernel_ready.Kernel', handle_kernel_cleanup);\n\n OutputArea.prototype.register_mime_type(EXEC_MIME_TYPE, append_mime, {\n safe: true,\n index: 0\n });\n}\n\nif (window.Jupyter !== undefined) {\n try {\n var events = require('base/js/events');\n var OutputArea = require('notebook/js/outputarea').OutputArea;\n if (OutputArea.prototype.mime_types().indexOf(EXEC_MIME_TYPE) == -1) {\n register_renderer(events, OutputArea);\n }\n } catch(err) {\n }\n}\n",
|
| 97 |
-
"application/vnd.holoviews_load.v0+json": ""
|
| 98 |
-
},
|
| 99 |
-
"metadata": {},
|
| 100 |
-
"output_type": "display_data"
|
| 101 |
-
},
|
| 102 |
-
{
|
| 103 |
-
"data": {
|
| 104 |
-
"application/vnd.holoviews_exec.v0+json": "",
|
| 105 |
-
"text/html": [
|
| 106 |
-
"<div id='bf537540-951b-4913-a81d-dceaed1c2b15'>\n",
|
| 107 |
-
" <div id=\"cd494ea2-9730-4b89-9bc3-9d460553970b\" data-root-id=\"bf537540-951b-4913-a81d-dceaed1c2b15\" style=\"display: contents;\"></div>\n",
|
| 108 |
-
"</div>\n",
|
| 109 |
-
"<script type=\"application/javascript\">(function(root) {\n",
|
| 110 |
-
" var docs_json = {\"c12a0b84-d09f-49d6-9a65-a55b87f9b880\":{\"version\":\"3.6.2\",\"title\":\"Bokeh Application\",\"roots\":[{\"type\":\"object\",\"name\":\"panel.models.browser.BrowserInfo\",\"id\":\"bf537540-951b-4913-a81d-dceaed1c2b15\"},{\"type\":\"object\",\"name\":\"panel.models.comm_manager.CommManager\",\"id\":\"f4566710-3a4c-43d3-8736-ed2a40fa8226\",\"attributes\":{\"plot_id\":\"bf537540-951b-4913-a81d-dceaed1c2b15\",\"comm_id\":\"2e9389a2a0264bb7955f94b13b9d1a52\",\"client_comm_id\":\"88d85376d3ea41bcb796b5668a35f378\"}}],\"defs\":[{\"type\":\"model\",\"name\":\"ReactiveHTML1\"},{\"type\":\"model\",\"name\":\"FlexBox1\",\"properties\":[{\"name\":\"align_content\",\"kind\":\"Any\",\"default\":\"flex-start\"},{\"name\":\"align_items\",\"kind\":\"Any\",\"default\":\"flex-start\"},{\"name\":\"flex_direction\",\"kind\":\"Any\",\"default\":\"row\"},{\"name\":\"flex_wrap\",\"kind\":\"Any\",\"default\":\"wrap\"},{\"name\":\"gap\",\"kind\":\"Any\",\"default\":\"\"},{\"name\":\"justify_content\",\"kind\":\"Any\",\"default\":\"flex-start\"}]},{\"type\":\"model\",\"name\":\"FloatPanel1\",\"properties\":[{\"name\":\"config\",\"kind\":\"Any\",\"default\":{\"type\":\"map\"}},{\"name\":\"contained\",\"kind\":\"Any\",\"default\":true},{\"name\":\"position\",\"kind\":\"Any\",\"default\":\"right-top\"},{\"name\":\"offsetx\",\"kind\":\"Any\",\"default\":null},{\"name\":\"offsety\",\"kind\":\"Any\",\"default\":null},{\"name\":\"theme\",\"kind\":\"Any\",\"default\":\"primary\"},{\"name\":\"status\",\"kind\":\"Any\",\"default\":\"normalized\"}]},{\"type\":\"model\",\"name\":\"GridStack1\",\"properties\":[{\"name\":\"mode\",\"kind\":\"Any\",\"default\":\"warn\"},{\"name\":\"ncols\",\"kind\":\"Any\",\"default\":null},{\"name\":\"nrows\",\"kind\":\"Any\",\"default\":null},{\"name\":\"allow_resize\",\"kind\":\"Any\",\"default\":true},{\"name\":\"allow_drag\",\"kind\":\"Any\",\"default\":true},{\"name\":\"state\",\"kind\":\"Any\",\"default\":[]}]},{\"type\":\"model\",\"name\":\"drag1\",\"properties\":[{\"name\":\"slider_width\",\"kind\":\"Any\",\"default\":5},{\"name\":\"slider_color\",\"kind\":\"Any\",\"default\":\"black\"},{\"name\":\"value\",\"kind\":\"Any\",\"default\":50}]},{\"type\":\"model\",\"name\":\"click1\",\"properties\":[{\"name\":\"terminal_output\",\"kind\":\"Any\",\"default\":\"\"},{\"name\":\"debug_name\",\"kind\":\"Any\",\"default\":\"\"},{\"name\":\"clears\",\"kind\":\"Any\",\"default\":0}]},{\"type\":\"model\",\"name\":\"FastWrapper1\",\"properties\":[{\"name\":\"object\",\"kind\":\"Any\",\"default\":null},{\"name\":\"style\",\"kind\":\"Any\",\"default\":null}]},{\"type\":\"model\",\"name\":\"NotificationAreaBase1\",\"properties\":[{\"name\":\"js_events\",\"kind\":\"Any\",\"default\":{\"type\":\"map\"}},{\"name\":\"position\",\"kind\":\"Any\",\"default\":\"bottom-right\"},{\"name\":\"_clear\",\"kind\":\"Any\",\"default\":0}]},{\"type\":\"model\",\"name\":\"NotificationArea1\",\"properties\":[{\"name\":\"js_events\",\"kind\":\"Any\",\"default\":{\"type\":\"map\"}},{\"name\":\"notifications\",\"kind\":\"Any\",\"default\":[]},{\"name\":\"position\",\"kind\":\"Any\",\"default\":\"bottom-right\"},{\"name\":\"_clear\",\"kind\":\"Any\",\"default\":0},{\"name\":\"types\",\"kind\":\"Any\",\"default\":[{\"type\":\"map\",\"entries\":[[\"type\",\"warning\"],[\"background\",\"#ffc107\"],[\"icon\",{\"type\":\"map\",\"entries\":[[\"className\",\"fas fa-exclamation-triangle\"],[\"tagName\",\"i\"],[\"color\",\"white\"]]}]]},{\"type\":\"map\",\"entries\":[[\"type\",\"info\"],[\"background\",\"#007bff\"],[\"icon\",{\"type\":\"map\",\"entries\":[[\"className\",\"fas fa-info-circle\"],[\"tagName\",\"i\"],[\"color\",\"white\"]]}]]}]}]},{\"type\":\"model\",\"name\":\"Notification\",\"properties\":[{\"name\":\"background\",\"kind\":\"Any\",\"default\":null},{\"name\":\"duration\",\"kind\":\"Any\",\"default\":3000},{\"name\":\"icon\",\"kind\":\"Any\",\"default\":null},{\"name\":\"message\",\"kind\":\"Any\",\"default\":\"\"},{\"name\":\"notification_type\",\"kind\":\"Any\",\"default\":null},{\"name\":\"_destroyed\",\"kind\":\"Any\",\"default\":false}]},{\"type\":\"model\",\"name\":\"TemplateActions1\",\"properties\":[{\"name\":\"open_modal\",\"kind\":\"Any\",\"default\":0},{\"name\":\"close_modal\",\"kind\":\"Any\",\"default\":0}]},{\"type\":\"model\",\"name\":\"BootstrapTemplateActions1\",\"properties\":[{\"name\":\"open_modal\",\"kind\":\"Any\",\"default\":0},{\"name\":\"close_modal\",\"kind\":\"Any\",\"default\":0}]},{\"type\":\"model\",\"name\":\"TemplateEditor1\",\"properties\":[{\"name\":\"layout\",\"kind\":\"Any\",\"default\":[]}]},{\"type\":\"model\",\"name\":\"MaterialTemplateActions1\",\"properties\":[{\"name\":\"open_modal\",\"kind\":\"Any\",\"default\":0},{\"name\":\"close_modal\",\"kind\":\"Any\",\"default\":0}]},{\"type\":\"model\",\"name\":\"ReactiveESM1\",\"properties\":[{\"name\":\"esm_constants\",\"kind\":\"Any\",\"default\":{\"type\":\"map\"}}]},{\"type\":\"model\",\"name\":\"JSComponent1\",\"properties\":[{\"name\":\"esm_constants\",\"kind\":\"Any\",\"default\":{\"type\":\"map\"}}]},{\"type\":\"model\",\"name\":\"ReactComponent1\",\"properties\":[{\"name\":\"esm_constants\",\"kind\":\"Any\",\"default\":{\"type\":\"map\"}}]},{\"type\":\"model\",\"name\":\"AnyWidgetComponent1\",\"properties\":[{\"name\":\"esm_constants\",\"kind\":\"Any\",\"default\":{\"type\":\"map\"}}]},{\"type\":\"model\",\"name\":\"request_value1\",\"properties\":[{\"name\":\"fill\",\"kind\":\"Any\",\"default\":\"none\"},{\"name\":\"_synced\",\"kind\":\"Any\",\"default\":null},{\"name\":\"_request_sync\",\"kind\":\"Any\",\"default\":0}]}]}};\n",
|
| 111 |
-
" var render_items = [{\"docid\":\"c12a0b84-d09f-49d6-9a65-a55b87f9b880\",\"roots\":{\"bf537540-951b-4913-a81d-dceaed1c2b15\":\"cd494ea2-9730-4b89-9bc3-9d460553970b\"},\"root_ids\":[\"bf537540-951b-4913-a81d-dceaed1c2b15\"]}];\n",
|
| 112 |
-
" var docs = Object.values(docs_json)\n",
|
| 113 |
-
" if (!docs) {\n",
|
| 114 |
-
" return\n",
|
| 115 |
-
" }\n",
|
| 116 |
-
" const py_version = docs[0].version.replace('rc', '-rc.').replace('.dev', '-dev.')\n",
|
| 117 |
-
" async function embed_document(root) {\n",
|
| 118 |
-
" var Bokeh = get_bokeh(root)\n",
|
| 119 |
-
" await Bokeh.embed.embed_items_notebook(docs_json, render_items);\n",
|
| 120 |
-
" for (const render_item of render_items) {\n",
|
| 121 |
-
" for (const root_id of render_item.root_ids) {\n",
|
| 122 |
-
"\tconst id_el = document.getElementById(root_id)\n",
|
| 123 |
-
"\tif (id_el.children.length && id_el.children[0].hasAttribute('data-root-id')) {\n",
|
| 124 |
-
"\t const root_el = id_el.children[0]\n",
|
| 125 |
-
"\t root_el.id = root_el.id + '-rendered'\n",
|
| 126 |
-
"\t for (const child of root_el.children) {\n",
|
| 127 |
-
" // Ensure JupyterLab does not capture keyboard shortcuts\n",
|
| 128 |
-
" // see: https://jupyterlab.readthedocs.io/en/4.1.x/extension/notebook.html#keyboard-interaction-model\n",
|
| 129 |
-
"\t child.setAttribute('data-lm-suppress-shortcuts', 'true')\n",
|
| 130 |
-
"\t }\n",
|
| 131 |
-
"\t}\n",
|
| 132 |
-
" }\n",
|
| 133 |
-
" }\n",
|
| 134 |
-
" }\n",
|
| 135 |
-
" function get_bokeh(root) {\n",
|
| 136 |
-
" if (root.Bokeh === undefined) {\n",
|
| 137 |
-
" return null\n",
|
| 138 |
-
" } else if (root.Bokeh.version !== py_version) {\n",
|
| 139 |
-
" if (root.Bokeh.versions === undefined || !root.Bokeh.versions.has(py_version)) {\n",
|
| 140 |
-
"\treturn null\n",
|
| 141 |
-
" }\n",
|
| 142 |
-
" return root.Bokeh.versions.get(py_version);\n",
|
| 143 |
-
" } else if (root.Bokeh.version === py_version) {\n",
|
| 144 |
-
" return root.Bokeh\n",
|
| 145 |
-
" }\n",
|
| 146 |
-
" return null\n",
|
| 147 |
-
" }\n",
|
| 148 |
-
" function is_loaded(root) {\n",
|
| 149 |
-
" var Bokeh = get_bokeh(root)\n",
|
| 150 |
-
" return (Bokeh != null && Bokeh.Panel !== undefined)\n",
|
| 151 |
-
" }\n",
|
| 152 |
-
" if (is_loaded(root)) {\n",
|
| 153 |
-
" embed_document(root);\n",
|
| 154 |
-
" } else {\n",
|
| 155 |
-
" var attempts = 0;\n",
|
| 156 |
-
" var timer = setInterval(function(root) {\n",
|
| 157 |
-
" if (is_loaded(root)) {\n",
|
| 158 |
-
" clearInterval(timer);\n",
|
| 159 |
-
" embed_document(root);\n",
|
| 160 |
-
" } else if (document.readyState == \"complete\") {\n",
|
| 161 |
-
" attempts++;\n",
|
| 162 |
-
" if (attempts > 200) {\n",
|
| 163 |
-
" clearInterval(timer);\n",
|
| 164 |
-
"\t var Bokeh = get_bokeh(root)\n",
|
| 165 |
-
"\t if (Bokeh == null || Bokeh.Panel == null) {\n",
|
| 166 |
-
" console.warn(\"Panel: ERROR: Unable to run Panel code because Bokeh or Panel library is missing\");\n",
|
| 167 |
-
"\t } else {\n",
|
| 168 |
-
"\t console.warn(\"Panel: WARNING: Attempting to render but not all required libraries could be resolved.\")\n",
|
| 169 |
-
"\t embed_document(root)\n",
|
| 170 |
-
"\t }\n",
|
| 171 |
-
" }\n",
|
| 172 |
-
" }\n",
|
| 173 |
-
" }, 25, root)\n",
|
| 174 |
-
" }\n",
|
| 175 |
-
"})(window);</script>"
|
| 176 |
-
]
|
| 177 |
-
},
|
| 178 |
-
"metadata": {
|
| 179 |
-
"application/vnd.holoviews_exec.v0+json": {
|
| 180 |
-
"id": "bf537540-951b-4913-a81d-dceaed1c2b15"
|
| 181 |
-
}
|
| 182 |
-
},
|
| 183 |
-
"output_type": "display_data"
|
| 184 |
-
},
|
| 185 |
-
{
|
| 186 |
-
"data": {
|
| 187 |
-
"text/plain": [
|
| 188 |
-
"<param.parameterized._ParametersRestorer at 0x26d5c6dbef0>"
|
| 189 |
-
]
|
| 190 |
-
},
|
| 191 |
-
"execution_count": 24,
|
| 192 |
-
"metadata": {},
|
| 193 |
-
"output_type": "execute_result"
|
| 194 |
-
}
|
| 195 |
-
],
|
| 196 |
-
"source": [
|
| 197 |
-
"pn.extension('texteditor', template=\"bootstrap\", sizing_mode='stretch_width')\n",
|
| 198 |
-
"pn.state.template.param.update(\n",
|
| 199 |
-
" main_max_width=\"690px\",\n",
|
| 200 |
-
" header_background=\"#F08080\",\n",
|
| 201 |
-
")"
|
| 202 |
-
]
|
| 203 |
-
},
|
| 204 |
-
{
|
| 205 |
-
"cell_type": "code",
|
| 206 |
-
"execution_count": null,
|
| 207 |
-
"id": "763db4d0-3436-41d3-8b0f-e66ce16468cd",
|
| 208 |
-
"metadata": {
|
| 209 |
-
"colab": {
|
| 210 |
-
"base_uri": "https://localhost:8080/",
|
| 211 |
-
"height": 248
|
| 212 |
-
},
|
| 213 |
-
"id": "763db4d0-3436-41d3-8b0f-e66ce16468cd",
|
| 214 |
-
"outputId": "d121cb2e-563b-4a4d-c498-68641282a4be",
|
| 215 |
-
"tags": []
|
| 216 |
-
},
|
| 217 |
-
"outputs": [],
|
| 218 |
-
"source": [
|
| 219 |
-
"file_input = pn.widgets.FileInput(width=300)\n",
|
| 220 |
-
"\n",
|
| 221 |
-
"openaikey = pn.widgets.PasswordInput(\n",
|
| 222 |
-
" value=\"\", placeholder=\"Enter your OpenAI API Key here...\", width=300\n",
|
| 223 |
-
")\n",
|
| 224 |
-
"prompt = pn.widgets.TextEditor(\n",
|
| 225 |
-
" value=\"\", placeholder=\"Enter your questions here...\", height=160, toolbar=False\n",
|
| 226 |
-
")\n",
|
| 227 |
-
"run_button = pn.widgets.Button(name=\"Run!\")\n",
|
| 228 |
-
"\n",
|
| 229 |
-
"select_k = pn.widgets.IntSlider(\n",
|
| 230 |
-
" name=\"Number of relevant chunks\", start=1, end=5, step=1, value=2\n",
|
| 231 |
-
")\n",
|
| 232 |
-
"select_chain_type = pn.widgets.RadioButtonGroup(\n",
|
| 233 |
-
" name='Chain type', \n",
|
| 234 |
-
" options=['stuff', 'map_reduce', \"refine\", \"map_rerank\"],\n",
|
| 235 |
-
" value='map_reduce'\n",
|
| 236 |
-
")\n",
|
| 237 |
-
"\n",
|
| 238 |
-
"# Organizare pe două coloane\n",
|
| 239 |
-
"left_column = pn.Column(\n",
|
| 240 |
-
" prompt, run_button, sizing_mode=\"stretch_width\"\n",
|
| 241 |
-
")\n",
|
| 242 |
-
"right_column = pn.Column(\n",
|
| 243 |
-
" pn.Card(\n",
|
| 244 |
-
" \"Chain type:\",\n",
|
| 245 |
-
" pn.Column(select_chain_type, select_k),\n",
|
| 246 |
-
" title=\"Advanced settings\",\n",
|
| 247 |
-
" ),\n",
|
| 248 |
-
" margin=10, sizing_mode=\"stretch_width\"\n",
|
| 249 |
-
")\n",
|
| 250 |
-
"\n",
|
| 251 |
-
"widgets = pn.Row(\n",
|
| 252 |
-
" left_column,\n",
|
| 253 |
-
" right_column,\n",
|
| 254 |
-
" sizing_mode=\"stretch_width\", # Se aplică rândului principal\n",
|
| 255 |
-
" max_width=800\n",
|
| 256 |
-
" \n",
|
| 257 |
-
")\n",
|
| 258 |
-
"\n",
|
| 259 |
-
"\n"
|
| 260 |
-
]
|
| 261 |
-
},
|
| 262 |
-
{
|
| 263 |
-
"cell_type": "code",
|
| 264 |
-
"execution_count": 26,
|
| 265 |
-
"id": "S_kpVLPKr794",
|
| 266 |
-
"metadata": {
|
| 267 |
-
"colab": {
|
| 268 |
-
"base_uri": "https://localhost:8080/",
|
| 269 |
-
"height": 248
|
| 270 |
-
},
|
| 271 |
-
"id": "S_kpVLPKr794",
|
| 272 |
-
"outputId": "f07f750a-ea7a-4151-a29f-5bdd6b9411a4"
|
| 273 |
-
},
|
| 274 |
-
"outputs": [],
|
| 275 |
-
"source": [
|
| 276 |
-
"# widgets"
|
| 277 |
-
]
|
| 278 |
-
},
|
| 279 |
-
{
|
| 280 |
-
"cell_type": "code",
|
| 281 |
-
"execution_count": 27,
|
| 282 |
-
"id": "b4029c79-808a-47d7-8011-4b498c39c556",
|
| 283 |
-
"metadata": {},
|
| 284 |
-
"outputs": [],
|
| 285 |
-
"source": [
|
| 286 |
-
"# file_input"
|
| 287 |
-
]
|
| 288 |
-
},
|
| 289 |
-
{
|
| 290 |
-
"cell_type": "code",
|
| 291 |
-
"execution_count": 28,
|
| 292 |
-
"id": "db7b7e1c-8704-4a86-897e-b4a690008d27",
|
| 293 |
-
"metadata": {},
|
| 294 |
-
"outputs": [],
|
| 295 |
-
"source": [
|
| 296 |
-
"#file_input.value"
|
| 297 |
-
]
|
| 298 |
-
},
|
| 299 |
-
{
|
| 300 |
-
"cell_type": "code",
|
| 301 |
-
"execution_count": 29,
|
| 302 |
-
"id": "9b83cc06-3401-498f-8f84-8a98370f3121",
|
| 303 |
-
"metadata": {
|
| 304 |
-
"id": "9b83cc06-3401-498f-8f84-8a98370f3121",
|
| 305 |
-
"tags": []
|
| 306 |
-
},
|
| 307 |
-
"outputs": [],
|
| 308 |
-
"source": [
|
| 309 |
-
"\n",
|
| 310 |
-
"\n",
|
| 311 |
-
"# Functia pentru a procesa fișierul și a răspunde la întrebări\n",
|
| 312 |
-
"def qa(file, query, chain_type, k):\n",
|
| 313 |
-
" # Încarcă documentul\n",
|
| 314 |
-
" loader = PyPDFLoader(file) # Folosește calea fișierului local\n",
|
| 315 |
-
" documents = loader.load()\n",
|
| 316 |
-
"\n",
|
| 317 |
-
" # Împarte documentele în fragmente\n",
|
| 318 |
-
" text_splitter = CharacterTextSplitter(chunk_size=1000, chunk_overlap=0)\n",
|
| 319 |
-
" texts = text_splitter.split_documents(documents)\n",
|
| 320 |
-
"\n",
|
| 321 |
-
" # Selectează care embedding-uri vor fi folosite\n",
|
| 322 |
-
" embeddings = OpenAIEmbeddings(model=\"text-embedding-ada-002\")\n",
|
| 323 |
-
"\n",
|
| 324 |
-
" # Creează vectorul de stocare a datelor (indexul)\n",
|
| 325 |
-
" db = Chroma.from_documents(texts, embeddings)\n",
|
| 326 |
-
"\n",
|
| 327 |
-
" # Expune acest index într-o interfață de căutare\n",
|
| 328 |
-
" retriever = db.as_retriever(search_type=\"similarity\", search_kwargs={\"k\": k})\n",
|
| 329 |
-
"\n",
|
| 330 |
-
" # Creează o „chain” pentru a răspunde la întrebări\n",
|
| 331 |
-
" qa_chain = RetrievalQA.from_chain_type(\n",
|
| 332 |
-
" llm=OpenAI(), chain_type=chain_type, retriever=retriever, return_source_documents=True\n",
|
| 333 |
-
" )\n",
|
| 334 |
-
"\n",
|
| 335 |
-
" # Răspunde la întrebarea dată\n",
|
| 336 |
-
" result = qa_chain.invoke({\"query\": query})\n",
|
| 337 |
-
"\n",
|
| 338 |
-
" # Filtrarea documentelor sursă pentru a elimina duplicatele\n",
|
| 339 |
-
" unique_documents = []\n",
|
| 340 |
-
" seen_content = set()\n",
|
| 341 |
-
" for doc in result[\"source_documents\"]:\n",
|
| 342 |
-
" if doc.page_content not in seen_content:\n",
|
| 343 |
-
" unique_documents.append(doc)\n",
|
| 344 |
-
" seen_content.add(doc.page_content)\n",
|
| 345 |
-
"\n",
|
| 346 |
-
" # Actualizează sursele cu documentele unice\n",
|
| 347 |
-
" result[\"source_documents\"] = unique_documents\n",
|
| 348 |
-
" \n",
|
| 349 |
-
" # Afișează rezultatul\n",
|
| 350 |
-
" print(result[\"result\"])\n",
|
| 351 |
-
" return result\n",
|
| 352 |
-
"\n",
|
| 353 |
-
"\n"
|
| 354 |
-
]
|
| 355 |
-
},
|
| 356 |
-
{
|
| 357 |
-
"cell_type": "code",
|
| 358 |
-
"execution_count": 30,
|
| 359 |
-
"id": "9d7ef1f2-959e-4e29-b377-655f85db7203",
|
| 360 |
-
"metadata": {},
|
| 361 |
-
"outputs": [],
|
| 362 |
-
"source": [
|
| 363 |
-
"# import os\n",
|
| 364 |
-
"\n",
|
| 365 |
-
"# # Setează cheia API pentru OpenAI\n",
|
| 366 |
-
"# os.environ[\"OPENAI_API_KEY\"] = \"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\"\n",
|
| 367 |
-
"# # Calea către fișierul PDF local\n",
|
| 368 |
-
"# file = r\"C:\\Users\\Harry\\Documents\\AI\\AI_projects\\example.pdf\" # Modifică cu calea reală a fișierului tău\n",
|
| 369 |
-
"\n",
|
| 370 |
-
"# # Exemplu de apelare a funcției\n",
|
| 371 |
-
"# qa(file, query=\"What is the total number of AI publications?\", chain_type=\"map_reduce\", k=2)"
|
| 372 |
-
]
|
| 373 |
-
},
|
| 374 |
-
{
|
| 375 |
-
"cell_type": "code",
|
| 376 |
-
"execution_count": 31,
|
| 377 |
-
"id": "60e1b3d3-c0d2-4260-ae0c-26b03f1b8824",
|
| 378 |
-
"metadata": {
|
| 379 |
-
"id": "60e1b3d3-c0d2-4260-ae0c-26b03f1b8824"
|
| 380 |
-
},
|
| 381 |
-
"outputs": [],
|
| 382 |
-
"source": [
|
| 383 |
-
"convos = [] # store all panel objects in a list\n",
|
| 384 |
-
"\n",
|
| 385 |
-
"def qa_result(_):\n",
|
| 386 |
-
" try:\n",
|
| 387 |
-
" # Afișează cheia API OpenAI și mesajul de inițializare\n",
|
| 388 |
-
" # os.environ[\"OPENAI_API_KEY\"] = \"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\"\n",
|
| 389 |
-
" os.environ[\"OPENAI_API_KEY\"] = openaikey.value\n",
|
| 390 |
-
" # save pdf file to a temp file\n",
|
| 391 |
-
" if file_input.value is not None:\n",
|
| 392 |
-
" file_input.save(\"temp.pdf\")\n",
|
| 393 |
-
"\n",
|
| 394 |
-
" prompt_text = prompt.value\n",
|
| 395 |
-
" if prompt_text:\n",
|
| 396 |
-
" result = qa(file=\"temp.pdf\", query=prompt_text, chain_type=select_chain_type.value, k=select_k.value)\n",
|
| 397 |
-
" # Curăță convo-urile anterioare înainte de a adăuga noi rezultate\n",
|
| 398 |
-
" convos.clear() # Curăță lista de conversații\n",
|
| 399 |
-
" convos.append(\n",
|
| 400 |
-
" pn.Row(pn.panel(\"\\U0001F60A\", width=10), prompt_text, width=600)\n",
|
| 401 |
-
" )\n",
|
| 402 |
-
" # Construiește un singur bloc Markdown pentru textele relevante\n",
|
| 403 |
-
" relevant_text = '\\n'.join([\n",
|
| 404 |
-
" f\"### Document {i + 1}:\\n\" + doc.page_content \n",
|
| 405 |
-
" for i, doc in enumerate(result[\"source_documents\"])\n",
|
| 406 |
-
" ])\n",
|
| 407 |
-
" \n",
|
| 408 |
-
" # Adăugăm blocul de text relevant\n",
|
| 409 |
-
" convos.append(\n",
|
| 410 |
-
" pn.Row(pn.panel(\"\\U0001F916\", width=10), pn.Column(\n",
|
| 411 |
-
" result[\"result\"], \"Relevant source text:\", pn.pane.Markdown(relevant_text)\n",
|
| 412 |
-
" ))\n",
|
| 413 |
-
" )\n",
|
| 414 |
-
" \n",
|
| 415 |
-
" return pn.Column(*convos, margin=15, width=575, min_height=400)\n",
|
| 416 |
-
" except Exception as e:\n",
|
| 417 |
-
" # În caz de eroare, afișează mesajul de eroare\n",
|
| 418 |
-
" print(f\"Error: {str(e)}\")\n",
|
| 419 |
-
" return pn.Column(pn.panel(f\"An error occurred: {str(e)}\"))\n"
|
| 420 |
-
]
|
| 421 |
-
},
|
| 422 |
-
{
|
| 423 |
-
"cell_type": "code",
|
| 424 |
-
"execution_count": 32,
|
| 425 |
-
"id": "c3a70857-0b98-4f62-a9c0-b62ca42b474c",
|
| 426 |
-
"metadata": {
|
| 427 |
-
"colab": {
|
| 428 |
-
"base_uri": "https://localhost:8080/"
|
| 429 |
-
},
|
| 430 |
-
"id": "c3a70857-0b98-4f62-a9c0-b62ca42b474c",
|
| 431 |
-
"outputId": "13bf88d7-17c6-440b-eb26-d59020e4b10b",
|
| 432 |
-
"tags": []
|
| 433 |
-
},
|
| 434 |
-
"outputs": [],
|
| 435 |
-
"source": [
|
| 436 |
-
"qa_interactive = pn.panel(\n",
|
| 437 |
-
" pn.bind(qa_result, run_button),\n",
|
| 438 |
-
" loading_indicator=True,\n",
|
| 439 |
-
")"
|
| 440 |
-
]
|
| 441 |
-
},
|
| 442 |
-
{
|
| 443 |
-
"cell_type": "code",
|
| 444 |
-
"execution_count": 33,
|
| 445 |
-
"id": "228e2b42-b1ed-43af-b923-031a70241ab0",
|
| 446 |
-
"metadata": {
|
| 447 |
-
"id": "228e2b42-b1ed-43af-b923-031a70241ab0",
|
| 448 |
-
"tags": []
|
| 449 |
-
},
|
| 450 |
-
"outputs": [],
|
| 451 |
-
"source": [
|
| 452 |
-
"output = pn.WidgetBox('*Output will show up here:*', qa_interactive, margin=10, width=800, height=300, align='start', scroll=True)"
|
| 453 |
-
]
|
| 454 |
-
},
|
| 455 |
-
{
|
| 456 |
-
"cell_type": "code",
|
| 457 |
-
"execution_count": 34,
|
| 458 |
-
"id": "1b0ec253-2bcd-4f91-96d8-d8456e900a58",
|
| 459 |
-
"metadata": {
|
| 460 |
-
"colab": {
|
| 461 |
-
"base_uri": "https://localhost:8080/",
|
| 462 |
-
"height": 1000
|
| 463 |
-
},
|
| 464 |
-
"id": "1b0ec253-2bcd-4f91-96d8-d8456e900a58",
|
| 465 |
-
"outputId": "4a802a73-77b5-4eb8-86da-9c0490ea7136",
|
| 466 |
-
"tags": []
|
| 467 |
-
},
|
| 468 |
-
"outputs": [
|
| 469 |
-
{
|
| 470 |
-
"data": {},
|
| 471 |
-
"metadata": {},
|
| 472 |
-
"output_type": "display_data"
|
| 473 |
-
},
|
| 474 |
-
{
|
| 475 |
-
"data": {
|
| 476 |
-
"application/vnd.holoviews_exec.v0+json": "",
|
| 477 |
-
"text/html": [
|
| 478 |
-
"<div id='2020c7e1-2eb6-4d04-9556-9f1dcc3922e8'>\n",
|
| 479 |
-
" <div id=\"e17b016e-176d-40f9-a704-88f1d749f956\" data-root-id=\"2020c7e1-2eb6-4d04-9556-9f1dcc3922e8\" style=\"display: contents;\"></div>\n",
|
| 480 |
-
"</div>\n",
|
| 481 |
-
"<script type=\"application/javascript\">(function(root) {\n",
|
| 482 |
-
" var docs_json = {\"40866006-4e00-49f6-a4f0-7a9dbd367ff7\":{\"version\":\"3.6.2\",\"title\":\"Bokeh Application\",\"roots\":[{\"type\":\"object\",\"name\":\"panel.models.layout.Column\",\"id\":\"2020c7e1-2eb6-4d04-9556-9f1dcc3922e8\",\"attributes\":{\"name\":\"Column00230\",\"stylesheets\":[\"\\n:host(.pn-loading):before, .pn-loading:before {\\n background-color: #c3c3c3;\\n mask-size: auto calc(min(50%, 400px));\\n -webkit-mask-size: auto calc(min(50%, 400px));\\n}\",{\"type\":\"object\",\"name\":\"ImportedStyleSheet\",\"id\":\"bbf7f501-00c4-43f6-87a0-debddfc0712a\",\"attributes\":{\"url\":\"https://cdn.holoviz.org/panel/1.5.4/dist/css/loading.css\"}},{\"type\":\"object\",\"name\":\"ImportedStyleSheet\",\"id\":\"49842c38-3000-4cf3-a9bf-3e3ab2bb4c07\",\"attributes\":{\"url\":\"https://cdn.holoviz.org/panel/1.5.4/dist/css/listpanel.css\"}},{\"type\":\"object\",\"name\":\"ImportedStyleSheet\",\"id\":\"d75912f0-9132-43e5-adb9-51efbd7932b4\",\"attributes\":{\"url\":\"https://cdn.holoviz.org/panel/1.5.4/dist/bundled/bootstrap5/css/bootstrap.min.css\"}},{\"type\":\"object\",\"name\":\"ImportedStyleSheet\",\"id\":\"f75971ef-42e4-4eee-ab00-de882056c0a7\",\"attributes\":{\"url\":\"https://cdn.holoviz.org/panel/1.5.4/dist/bundled/theme/default.css\"}},{\"type\":\"object\",\"name\":\"ImportedStyleSheet\",\"id\":\"866e9859-0f60-4001-b36c-494773ca9355\",\"attributes\":{\"url\":\"https://cdn.holoviz.org/panel/1.5.4/dist/bundled/theme/bootstrap_default.css\"}},{\"type\":\"object\",\"name\":\"ImportedStyleSheet\",\"id\":\"e0a8107e-ab13-4f9b-ad66-231a6455972f\",\"attributes\":{\"url\":\"https://cdn.holoviz.org/panel/1.5.4/dist/bundled/theme/bootstrap.css\"}}],\"min_width\":800,\"margin\":0,\"sizing_mode\":\"stretch_width\",\"align\":\"start\",\"children\":[{\"type\":\"object\",\"name\":\"panel.models.markup.HTML\",\"id\":\"f4153fe5-e7ca-45b4-9743-e0b09d6a1600\",\"attributes\":{\"css_classes\":[\"markdown\"],\"stylesheets\":[\"\\n:host(.pn-loading):before, .pn-loading:before {\\n background-color: #c3c3c3;\\n mask-size: auto calc(min(50%, 400px));\\n -webkit-mask-size: auto calc(min(50%, 400px));\\n}\",{\"id\":\"bbf7f501-00c4-43f6-87a0-debddfc0712a\"},{\"type\":\"object\",\"name\":\"ImportedStyleSheet\",\"id\":\"e5c44e93-a883-478b-aa46-28355dcc4db9\",\"attributes\":{\"url\":\"https://cdn.holoviz.org/panel/1.5.4/dist/css/markdown.css\"}},{\"id\":\"d75912f0-9132-43e5-adb9-51efbd7932b4\"},{\"id\":\"f75971ef-42e4-4eee-ab00-de882056c0a7\"},{\"id\":\"866e9859-0f60-4001-b36c-494773ca9355\"},{\"id\":\"e0a8107e-ab13-4f9b-ad66-231a6455972f\"}],\"margin\":[5,10],\"sizing_mode\":\"stretch_width\",\"align\":\"start\",\"text\":\"<h2 id="-question-answering-with-your-pdf-file">\\ud83d\\ude0a! Question Answering with your PDF file <a class="header-anchor" href="#-question-answering-with-your-pdf-file">\\u00b6</a></h2>\\n<ol>\\n<li>Upload a PDF. 2) Enter OpenAI API key. This costs $. Set up billing at <a href="https://platform.openai.com/account">OpenAI</a>. 3) Type a question and click &quot;Run&quot;</li>\\n</ol>\\n\"}},{\"type\":\"object\",\"name\":\"Row\",\"id\":\"c4e17c49-934a-4e46-be1f-8f093db92a05\",\"attributes\":{\"name\":\"Row00229\",\"stylesheets\":[\"\\n:host(.pn-loading):before, .pn-loading:before {\\n background-color: #c3c3c3;\\n mask-size: auto calc(min(50%, 400px));\\n -webkit-mask-size: auto calc(min(50%, 400px));\\n}\",{\"id\":\"bbf7f501-00c4-43f6-87a0-debddfc0712a\"},{\"id\":\"49842c38-3000-4cf3-a9bf-3e3ab2bb4c07\"},{\"id\":\"d75912f0-9132-43e5-adb9-51efbd7932b4\"},{\"id\":\"f75971ef-42e4-4eee-ab00-de882056c0a7\"},{\"id\":\"866e9859-0f60-4001-b36c-494773ca9355\"},{\"id\":\"e0a8107e-ab13-4f9b-ad66-231a6455972f\"}],\"min_width\":600,\"margin\":0,\"sizing_mode\":\"stretch_width\",\"align\":\"start\",\"children\":[{\"type\":\"object\",\"name\":\"FileInput\",\"id\":\"6a184af8-ccd4-48d2-8b0e-2134f557f4f4\",\"attributes\":{\"stylesheets\":[\"\\n:host(.pn-loading):before, .pn-loading:before {\\n background-color: #c3c3c3;\\n mask-size: auto calc(min(50%, 400px));\\n -webkit-mask-size: auto calc(min(50%, 400px));\\n}\",{\"id\":\"bbf7f501-00c4-43f6-87a0-debddfc0712a\"},{\"id\":\"d75912f0-9132-43e5-adb9-51efbd7932b4\"},{\"id\":\"f75971ef-42e4-4eee-ab00-de882056c0a7\"},{\"id\":\"866e9859-0f60-4001-b36c-494773ca9355\"},{\"id\":\"e0a8107e-ab13-4f9b-ad66-231a6455972f\"}],\"width\":300,\"min_width\":300,\"margin\":[5,10],\"align\":\"start\",\"accept\":\"\"}},{\"type\":\"object\",\"name\":\"PasswordInput\",\"id\":\"5f777e56-0ec7-4bb7-9870-aefd3c652a1a\",\"attributes\":{\"stylesheets\":[\"\\n:host(.pn-loading):before, .pn-loading:before {\\n background-color: #c3c3c3;\\n mask-size: auto calc(min(50%, 400px));\\n -webkit-mask-size: auto calc(min(50%, 400px));\\n}\",{\"id\":\"bbf7f501-00c4-43f6-87a0-debddfc0712a\"},{\"id\":\"d75912f0-9132-43e5-adb9-51efbd7932b4\"},{\"id\":\"f75971ef-42e4-4eee-ab00-de882056c0a7\"},{\"id\":\"866e9859-0f60-4001-b36c-494773ca9355\"},{\"id\":\"e0a8107e-ab13-4f9b-ad66-231a6455972f\"}],\"width\":300,\"min_width\":300,\"margin\":[5,10],\"align\":\"start\",\"placeholder\":\"Enter your OpenAI API Key here...\",\"max_length\":5000}}]}},{\"type\":\"object\",\"name\":\"Row\",\"id\":\"7efa74c5-bbbb-4009-9477-adf81c43c91d\",\"attributes\":{\"name\":\"Row00216\",\"stylesheets\":[\"\\n:host(.pn-loading):before, .pn-loading:before {\\n background-color: #c3c3c3;\\n mask-size: auto calc(min(50%, 400px));\\n -webkit-mask-size: auto calc(min(50%, 400px));\\n}\",{\"id\":\"bbf7f501-00c4-43f6-87a0-debddfc0712a\"},{\"id\":\"49842c38-3000-4cf3-a9bf-3e3ab2bb4c07\"},{\"id\":\"d75912f0-9132-43e5-adb9-51efbd7932b4\"},{\"id\":\"f75971ef-42e4-4eee-ab00-de882056c0a7\"},{\"id\":\"866e9859-0f60-4001-b36c-494773ca9355\"},{\"id\":\"e0a8107e-ab13-4f9b-ad66-231a6455972f\"}],\"margin\":0,\"sizing_mode\":\"stretch_width\",\"align\":\"start\",\"children\":[{\"type\":\"object\",\"name\":\"panel.models.layout.Column\",\"id\":\"204b8620-86d0-4318-ae2b-e848b2bc19f8\",\"attributes\":{\"name\":\"Column00207\",\"stylesheets\":[\"\\n:host(.pn-loading):before, .pn-loading:before {\\n background-color: #c3c3c3;\\n mask-size: auto calc(min(50%, 400px));\\n -webkit-mask-size: auto calc(min(50%, 400px));\\n}\",{\"id\":\"bbf7f501-00c4-43f6-87a0-debddfc0712a\"},{\"id\":\"49842c38-3000-4cf3-a9bf-3e3ab2bb4c07\"},{\"id\":\"d75912f0-9132-43e5-adb9-51efbd7932b4\"},{\"id\":\"f75971ef-42e4-4eee-ab00-de882056c0a7\"},{\"id\":\"866e9859-0f60-4001-b36c-494773ca9355\"},{\"id\":\"e0a8107e-ab13-4f9b-ad66-231a6455972f\"}],\"margin\":0,\"sizing_mode\":\"stretch_width\",\"align\":\"start\",\"children\":[{\"type\":\"object\",\"name\":\"panel.models.quill.QuillInput\",\"id\":\"caac671b-9194-46ab-b8ee-b3aee6c91731\",\"attributes\":{\"name\":\"\",\"stylesheets\":[{\"type\":\"object\",\"name\":\"ImportedStyleSheet\",\"id\":\"80f977fc-f96e-4375-8e89-7d0bc61c2ef8\",\"attributes\":{\"url\":\"https://cdn.holoviz.org/panel/1.5.4/dist/bundled/quillinput/1.3.7/quill.bubble.css\"}},{\"type\":\"object\",\"name\":\"ImportedStyleSheet\",\"id\":\"0b14c8b4-e0ad-4671-a70a-d9d9f3979627\",\"attributes\":{\"url\":\"https://cdn.holoviz.org/panel/1.5.4/dist/bundled/quillinput/1.3.7/quill.snow.css\"}},\"\\n:host(.pn-loading):before, .pn-loading:before {\\n background-color: #c3c3c3;\\n mask-size: auto calc(min(50%, 400px));\\n -webkit-mask-size: auto calc(min(50%, 400px));\\n}\",{\"id\":\"bbf7f501-00c4-43f6-87a0-debddfc0712a\"},{\"id\":\"d75912f0-9132-43e5-adb9-51efbd7932b4\"},{\"id\":\"f75971ef-42e4-4eee-ab00-de882056c0a7\"},{\"id\":\"866e9859-0f60-4001-b36c-494773ca9355\"},{\"id\":\"e0a8107e-ab13-4f9b-ad66-231a6455972f\"}],\"height\":160,\"margin\":[5,10],\"sizing_mode\":\"stretch_width\",\"align\":\"start\",\"placeholder\":\"Enter your questions here...\",\"toolbar\":false}},{\"type\":\"object\",\"name\":\"panel.models.widgets.Button\",\"id\":\"8b73411b-cbfd-4e28-85b3-3ea9278f7bfb\",\"attributes\":{\"js_event_callbacks\":{\"type\":\"map\",\"entries\":[[\"button_click\",[{\"type\":\"object\",\"name\":\"CustomJS\",\"id\":\"23d9c8a4-aae6-4cba-8b51-69ec4d697974\",\"attributes\":{\"tags\":[[2668707870864,[null,\"event:button_click\"],[null,\"loading\"]]],\"args\":{\"type\":\"map\",\"entries\":[[\"bidirectional\",false],[\"properties\",{\"type\":\"map\",\"entries\":[[\"event:button_click\",\"loading\"]]}],[\"source\",{\"id\":\"8b73411b-cbfd-4e28-85b3-3ea9278f7bfb\"}],[\"target\",{\"type\":\"object\",\"name\":\"panel.models.layout.Column\",\"id\":\"7538bffb-58df-48df-b71d-3d5bc56b717a\",\"attributes\":{\"name\":\"Column00221\",\"stylesheets\":[\"\\n:host(.pn-loading):before, .pn-loading:before {\\n background-color: #c3c3c3;\\n mask-size: auto calc(min(50%, 400px));\\n -webkit-mask-size: auto calc(min(50%, 400px));\\n}\",{\"id\":\"bbf7f501-00c4-43f6-87a0-debddfc0712a\"},{\"id\":\"49842c38-3000-4cf3-a9bf-3e3ab2bb4c07\"},{\"id\":\"d75912f0-9132-43e5-adb9-51efbd7932b4\"},{\"id\":\"f75971ef-42e4-4eee-ab00-de882056c0a7\"},{\"id\":\"866e9859-0f60-4001-b36c-494773ca9355\"},{\"id\":\"e0a8107e-ab13-4f9b-ad66-231a6455972f\"}],\"margin\":0,\"align\":\"start\",\"children\":[{\"type\":\"object\",\"name\":\"panel.models.layout.Column\",\"id\":\"feafe90c-9fe4-4368-9b9f-5b785ce8cbb9\",\"attributes\":{\"name\":\"Column00223\",\"stylesheets\":[\"\\n:host(.pn-loading):before, .pn-loading:before {\\n background-color: #c3c3c3;\\n mask-size: auto calc(min(50%, 400px));\\n -webkit-mask-size: auto calc(min(50%, 400px));\\n}\",{\"id\":\"bbf7f501-00c4-43f6-87a0-debddfc0712a\"},{\"id\":\"49842c38-3000-4cf3-a9bf-3e3ab2bb4c07\"},{\"id\":\"d75912f0-9132-43e5-adb9-51efbd7932b4\"},{\"id\":\"f75971ef-42e4-4eee-ab00-de882056c0a7\"},{\"id\":\"866e9859-0f60-4001-b36c-494773ca9355\"},{\"id\":\"e0a8107e-ab13-4f9b-ad66-231a6455972f\"}],\"width\":575,\"min_width\":575,\"min_height\":400,\"margin\":15,\"align\":\"start\"}}]}}]]},\"code\":\"\\n if ('event:button_click'.startsWith('event:')) {\\n var value = true\\n } else {\\n var value = source['event:button_click'];\\n value = value;\\n }\\n if (typeof value !== 'boolean' || source.labels !== ['Loading']) {\\n value = true\\n }\\n var css_classes = target.css_classes.slice()\\n var loading_css = ['pn-loading', 'pn-arc']\\n if (value) {\\n for (var css of loading_css) {\\n if (!(css in css_classes)) {\\n css_classes.push(css)\\n }\\n }\\n } else {\\n for (var css of loading_css) {\\n var index = css_classes.indexOf(css)\\n if (index > -1) {\\n css_classes.splice(index, 1)\\n }\\n }\\n }\\n target['css_classes'] = css_classes\\n \"}}]]]},\"subscribed_events\":{\"type\":\"set\",\"entries\":[\"button_click\"]},\"css_classes\":[\"solid\"],\"stylesheets\":[\"\\n:host(.pn-loading):before, .pn-loading:before {\\n background-color: #c3c3c3;\\n mask-size: auto calc(min(50%, 400px));\\n -webkit-mask-size: auto calc(min(50%, 400px));\\n}\",{\"id\":\"bbf7f501-00c4-43f6-87a0-debddfc0712a\"},{\"type\":\"object\",\"name\":\"ImportedStyleSheet\",\"id\":\"2cb2191b-a2a9-4fab-a390-3f83d6cdd80a\",\"attributes\":{\"url\":\"https://cdn.holoviz.org/panel/1.5.4/dist/css/button.css\"}},{\"id\":\"d75912f0-9132-43e5-adb9-51efbd7932b4\"},{\"id\":\"f75971ef-42e4-4eee-ab00-de882056c0a7\"},{\"id\":\"866e9859-0f60-4001-b36c-494773ca9355\"},{\"id\":\"e0a8107e-ab13-4f9b-ad66-231a6455972f\"}],\"margin\":[5,10],\"sizing_mode\":\"stretch_width\",\"align\":\"start\",\"label\":\"Run!\"}}]}},{\"type\":\"object\",\"name\":\"panel.models.layout.Column\",\"id\":\"5936d38c-4347-4ccf-bf8f-8f2fbdf5e976\",\"attributes\":{\"name\":\"Column00215\",\"stylesheets\":[\"\\n:host(.pn-loading):before, .pn-loading:before {\\n background-color: #c3c3c3;\\n mask-size: auto calc(min(50%, 400px));\\n -webkit-mask-size: auto calc(min(50%, 400px));\\n}\",{\"id\":\"bbf7f501-00c4-43f6-87a0-debddfc0712a\"},{\"id\":\"49842c38-3000-4cf3-a9bf-3e3ab2bb4c07\"},{\"id\":\"d75912f0-9132-43e5-adb9-51efbd7932b4\"},{\"id\":\"f75971ef-42e4-4eee-ab00-de882056c0a7\"},{\"id\":\"866e9859-0f60-4001-b36c-494773ca9355\"},{\"id\":\"e0a8107e-ab13-4f9b-ad66-231a6455972f\"}],\"margin\":10,\"sizing_mode\":\"stretch_width\",\"align\":\"start\",\"children\":[{\"type\":\"object\",\"name\":\"panel.models.layout.Card\",\"id\":\"9726a784-7349-4294-ac80-564d270c7077\",\"attributes\":{\"name\":\"Card00210\",\"css_classes\":[\"card\"],\"stylesheets\":[\"\\n:host(.pn-loading):before, .pn-loading:before {\\n background-color: #c3c3c3;\\n mask-size: auto calc(min(50%, 400px));\\n -webkit-mask-size: auto calc(min(50%, 400px));\\n}\",{\"id\":\"bbf7f501-00c4-43f6-87a0-debddfc0712a\"},{\"id\":\"49842c38-3000-4cf3-a9bf-3e3ab2bb4c07\"},{\"id\":\"d75912f0-9132-43e5-adb9-51efbd7932b4\"},{\"id\":\"f75971ef-42e4-4eee-ab00-de882056c0a7\"},{\"id\":\"866e9859-0f60-4001-b36c-494773ca9355\"},{\"id\":\"e0a8107e-ab13-4f9b-ad66-231a6455972f\"}],\"margin\":[10,5],\"sizing_mode\":\"stretch_width\",\"align\":\"start\",\"children\":[{\"type\":\"object\",\"name\":\"Row\",\"id\":\"0ea37cd9-f685-47b6-b37a-52280478e1d2\",\"attributes\":{\"name\":\"Row00209\",\"css_classes\":[\"card-header-row\"],\"stylesheets\":[\"\\n:host(.pn-loading):before, .pn-loading:before {\\n background-color: #c3c3c3;\\n mask-size: auto calc(min(50%, 400px));\\n -webkit-mask-size: auto calc(min(50%, 400px));\\n}\",{\"id\":\"bbf7f501-00c4-43f6-87a0-debddfc0712a\"},{\"id\":\"49842c38-3000-4cf3-a9bf-3e3ab2bb4c07\"},{\"id\":\"d75912f0-9132-43e5-adb9-51efbd7932b4\"},{\"id\":\"f75971ef-42e4-4eee-ab00-de882056c0a7\"},{\"id\":\"866e9859-0f60-4001-b36c-494773ca9355\"},{\"id\":\"e0a8107e-ab13-4f9b-ad66-231a6455972f\"}],\"margin\":0,\"sizing_mode\":\"stretch_width\",\"align\":\"start\",\"children\":[{\"type\":\"object\",\"name\":\"panel.models.markup.HTML\",\"id\":\"9f23784c-bfdd-489f-97af-785d9936675c\",\"attributes\":{\"css_classes\":[\"card-title\"],\"stylesheets\":[\"\\n:host(.pn-loading):before, .pn-loading:before {\\n background-color: #c3c3c3;\\n mask-size: auto calc(min(50%, 400px));\\n -webkit-mask-size: auto calc(min(50%, 400px));\\n}\",{\"id\":\"bbf7f501-00c4-43f6-87a0-debddfc0712a\"},{\"id\":\"d75912f0-9132-43e5-adb9-51efbd7932b4\"},{\"id\":\"f75971ef-42e4-4eee-ab00-de882056c0a7\"},{\"id\":\"866e9859-0f60-4001-b36c-494773ca9355\"},{\"id\":\"e0a8107e-ab13-4f9b-ad66-231a6455972f\"}],\"margin\":[5,0],\"sizing_mode\":\"stretch_width\",\"align\":\"start\",\"text\":\"<h3>Advanced settings</h3>\",\"disable_math\":true}}]}},{\"type\":\"object\",\"name\":\"panel.models.markup.HTML\",\"id\":\"0f927761-99fb-475a-ac9d-5fb8401274f0\",\"attributes\":{\"css_classes\":[\"markdown\"],\"stylesheets\":[\"\\n:host(.pn-loading):before, .pn-loading:before {\\n background-color: #c3c3c3;\\n mask-size: auto calc(min(50%, 400px));\\n -webkit-mask-size: auto calc(min(50%, 400px));\\n}\",{\"id\":\"bbf7f501-00c4-43f6-87a0-debddfc0712a\"},{\"id\":\"e5c44e93-a883-478b-aa46-28355dcc4db9\"},{\"id\":\"d75912f0-9132-43e5-adb9-51efbd7932b4\"},{\"id\":\"f75971ef-42e4-4eee-ab00-de882056c0a7\"},{\"id\":\"866e9859-0f60-4001-b36c-494773ca9355\"},{\"id\":\"e0a8107e-ab13-4f9b-ad66-231a6455972f\"}],\"margin\":[5,10],\"sizing_mode\":\"stretch_width\",\"align\":\"start\",\"text\":\"<p>Chain type:</p>\\n\"}},{\"type\":\"object\",\"name\":\"panel.models.layout.Column\",\"id\":\"3bc68a3e-0d9a-4f2a-9477-1f993353c193\",\"attributes\":{\"name\":\"Column00208\",\"stylesheets\":[\"\\n:host(.pn-loading):before, .pn-loading:before {\\n background-color: #c3c3c3;\\n mask-size: auto calc(min(50%, 400px));\\n -webkit-mask-size: auto calc(min(50%, 400px));\\n}\",{\"id\":\"bbf7f501-00c4-43f6-87a0-debddfc0712a\"},{\"id\":\"49842c38-3000-4cf3-a9bf-3e3ab2bb4c07\"},{\"id\":\"d75912f0-9132-43e5-adb9-51efbd7932b4\"},{\"id\":\"f75971ef-42e4-4eee-ab00-de882056c0a7\"},{\"id\":\"866e9859-0f60-4001-b36c-494773ca9355\"},{\"id\":\"e0a8107e-ab13-4f9b-ad66-231a6455972f\"}],\"margin\":0,\"sizing_mode\":\"stretch_width\",\"align\":\"start\",\"children\":[{\"type\":\"object\",\"name\":\"panel.models.widgets.RadioButtonGroup\",\"id\":\"f721ff19-6be9-483f-a5cb-1f39210855f5\",\"attributes\":{\"css_classes\":[\"solid\"],\"stylesheets\":[\"\\n:host(.pn-loading):before, .pn-loading:before {\\n background-color: #c3c3c3;\\n mask-size: auto calc(min(50%, 400px));\\n -webkit-mask-size: auto calc(min(50%, 400px));\\n}\",{\"id\":\"bbf7f501-00c4-43f6-87a0-debddfc0712a\"},{\"id\":\"2cb2191b-a2a9-4fab-a390-3f83d6cdd80a\"},{\"id\":\"d75912f0-9132-43e5-adb9-51efbd7932b4\"},{\"id\":\"f75971ef-42e4-4eee-ab00-de882056c0a7\"},{\"id\":\"866e9859-0f60-4001-b36c-494773ca9355\"},{\"id\":\"e0a8107e-ab13-4f9b-ad66-231a6455972f\"}],\"margin\":[5,10],\"sizing_mode\":\"stretch_width\",\"align\":\"start\",\"labels\":[\"stuff\",\"map_reduce\",\"refine\",\"map_rerank\"],\"active\":1}},{\"type\":\"object\",\"name\":\"Slider\",\"id\":\"18d3f847-9821-43da-9656-2f39a5e0490d\",\"attributes\":{\"stylesheets\":[\"\\n:host(.pn-loading):before, .pn-loading:before {\\n background-color: #c3c3c3;\\n mask-size: auto calc(min(50%, 400px));\\n -webkit-mask-size: auto calc(min(50%, 400px));\\n}\",{\"id\":\"bbf7f501-00c4-43f6-87a0-debddfc0712a\"},{\"id\":\"d75912f0-9132-43e5-adb9-51efbd7932b4\"},{\"id\":\"f75971ef-42e4-4eee-ab00-de882056c0a7\"},{\"id\":\"866e9859-0f60-4001-b36c-494773ca9355\"},{\"id\":\"e0a8107e-ab13-4f9b-ad66-231a6455972f\"}],\"margin\":[5,10],\"sizing_mode\":\"stretch_width\",\"align\":\"start\",\"title\":\"Number of relevant chunks\",\"start\":1,\"end\":5,\"value\":2}}]}}],\"active_header_background\":\"\",\"button_css_classes\":[\"card-button\"],\"collapsed\":false,\"header_background\":\"\",\"header_color\":\"\",\"header_css_classes\":[\"card-header\"]}}]}}]}},{\"type\":\"object\",\"name\":\"panel.models.layout.Column\",\"id\":\"1b5df0c8-56dd-4772-afae-22e03a07d15a\",\"attributes\":{\"name\":\"WidgetBox00224\",\"css_classes\":[\"panel-widget-box\",\"scrollable-vertical\"],\"stylesheets\":[\"\\n:host(.pn-loading):before, .pn-loading:before {\\n background-color: #c3c3c3;\\n mask-size: auto calc(min(50%, 400px));\\n -webkit-mask-size: auto calc(min(50%, 400px));\\n}\",{\"id\":\"bbf7f501-00c4-43f6-87a0-debddfc0712a\"},{\"type\":\"object\",\"name\":\"ImportedStyleSheet\",\"id\":\"c7c75a96-acdf-45ea-bb50-88aa7c07abd3\",\"attributes\":{\"url\":\"https://cdn.holoviz.org/panel/1.5.4/dist/css/widgetbox.css\"}},{\"id\":\"49842c38-3000-4cf3-a9bf-3e3ab2bb4c07\"},{\"id\":\"d75912f0-9132-43e5-adb9-51efbd7932b4\"},{\"id\":\"f75971ef-42e4-4eee-ab00-de882056c0a7\"},{\"id\":\"866e9859-0f60-4001-b36c-494773ca9355\"},{\"id\":\"e0a8107e-ab13-4f9b-ad66-231a6455972f\"}],\"width\":800,\"height\":300,\"margin\":10,\"sizing_mode\":\"fixed\",\"align\":\"start\",\"children\":[{\"type\":\"object\",\"name\":\"panel.models.markup.HTML\",\"id\":\"a5f10ab3-ff22-4604-9b8c-d165279cea76\",\"attributes\":{\"css_classes\":[\"markdown\"],\"stylesheets\":[\"\\n:host(.pn-loading):before, .pn-loading:before {\\n background-color: #c3c3c3;\\n mask-size: auto calc(min(50%, 400px));\\n -webkit-mask-size: auto calc(min(50%, 400px));\\n}\",{\"id\":\"bbf7f501-00c4-43f6-87a0-debddfc0712a\"},{\"id\":\"e5c44e93-a883-478b-aa46-28355dcc4db9\"},{\"id\":\"d75912f0-9132-43e5-adb9-51efbd7932b4\"},{\"id\":\"f75971ef-42e4-4eee-ab00-de882056c0a7\"},{\"id\":\"866e9859-0f60-4001-b36c-494773ca9355\"},{\"id\":\"e0a8107e-ab13-4f9b-ad66-231a6455972f\"}],\"margin\":[5,10],\"sizing_mode\":\"stretch_width\",\"align\":\"start\",\"text\":\"<p><em>Output will show up here:</em></p>\\n\"}},{\"id\":\"7538bffb-58df-48df-b71d-3d5bc56b717a\"}]}}]}},{\"type\":\"object\",\"name\":\"panel.models.comm_manager.CommManager\",\"id\":\"e453d807-6660-435c-8c55-488cefe063ad\",\"attributes\":{\"plot_id\":\"2020c7e1-2eb6-4d04-9556-9f1dcc3922e8\",\"comm_id\":\"8e3f48adfd9a41f98e0c2f9af1aadb38\",\"client_comm_id\":\"d4e32a60717f44cabe12aca184c300f9\"}}],\"defs\":[{\"type\":\"model\",\"name\":\"ReactiveHTML1\"},{\"type\":\"model\",\"name\":\"FlexBox1\",\"properties\":[{\"name\":\"align_content\",\"kind\":\"Any\",\"default\":\"flex-start\"},{\"name\":\"align_items\",\"kind\":\"Any\",\"default\":\"flex-start\"},{\"name\":\"flex_direction\",\"kind\":\"Any\",\"default\":\"row\"},{\"name\":\"flex_wrap\",\"kind\":\"Any\",\"default\":\"wrap\"},{\"name\":\"gap\",\"kind\":\"Any\",\"default\":\"\"},{\"name\":\"justify_content\",\"kind\":\"Any\",\"default\":\"flex-start\"}]},{\"type\":\"model\",\"name\":\"FloatPanel1\",\"properties\":[{\"name\":\"config\",\"kind\":\"Any\",\"default\":{\"type\":\"map\"}},{\"name\":\"contained\",\"kind\":\"Any\",\"default\":true},{\"name\":\"position\",\"kind\":\"Any\",\"default\":\"right-top\"},{\"name\":\"offsetx\",\"kind\":\"Any\",\"default\":null},{\"name\":\"offsety\",\"kind\":\"Any\",\"default\":null},{\"name\":\"theme\",\"kind\":\"Any\",\"default\":\"primary\"},{\"name\":\"status\",\"kind\":\"Any\",\"default\":\"normalized\"}]},{\"type\":\"model\",\"name\":\"GridStack1\",\"properties\":[{\"name\":\"mode\",\"kind\":\"Any\",\"default\":\"warn\"},{\"name\":\"ncols\",\"kind\":\"Any\",\"default\":null},{\"name\":\"nrows\",\"kind\":\"Any\",\"default\":null},{\"name\":\"allow_resize\",\"kind\":\"Any\",\"default\":true},{\"name\":\"allow_drag\",\"kind\":\"Any\",\"default\":true},{\"name\":\"state\",\"kind\":\"Any\",\"default\":[]}]},{\"type\":\"model\",\"name\":\"drag1\",\"properties\":[{\"name\":\"slider_width\",\"kind\":\"Any\",\"default\":5},{\"name\":\"slider_color\",\"kind\":\"Any\",\"default\":\"black\"},{\"name\":\"value\",\"kind\":\"Any\",\"default\":50}]},{\"type\":\"model\",\"name\":\"click1\",\"properties\":[{\"name\":\"terminal_output\",\"kind\":\"Any\",\"default\":\"\"},{\"name\":\"debug_name\",\"kind\":\"Any\",\"default\":\"\"},{\"name\":\"clears\",\"kind\":\"Any\",\"default\":0}]},{\"type\":\"model\",\"name\":\"FastWrapper1\",\"properties\":[{\"name\":\"object\",\"kind\":\"Any\",\"default\":null},{\"name\":\"style\",\"kind\":\"Any\",\"default\":null}]},{\"type\":\"model\",\"name\":\"NotificationAreaBase1\",\"properties\":[{\"name\":\"js_events\",\"kind\":\"Any\",\"default\":{\"type\":\"map\"}},{\"name\":\"position\",\"kind\":\"Any\",\"default\":\"bottom-right\"},{\"name\":\"_clear\",\"kind\":\"Any\",\"default\":0}]},{\"type\":\"model\",\"name\":\"NotificationArea1\",\"properties\":[{\"name\":\"js_events\",\"kind\":\"Any\",\"default\":{\"type\":\"map\"}},{\"name\":\"notifications\",\"kind\":\"Any\",\"default\":[]},{\"name\":\"position\",\"kind\":\"Any\",\"default\":\"bottom-right\"},{\"name\":\"_clear\",\"kind\":\"Any\",\"default\":0},{\"name\":\"types\",\"kind\":\"Any\",\"default\":[{\"type\":\"map\",\"entries\":[[\"type\",\"warning\"],[\"background\",\"#ffc107\"],[\"icon\",{\"type\":\"map\",\"entries\":[[\"className\",\"fas fa-exclamation-triangle\"],[\"tagName\",\"i\"],[\"color\",\"white\"]]}]]},{\"type\":\"map\",\"entries\":[[\"type\",\"info\"],[\"background\",\"#007bff\"],[\"icon\",{\"type\":\"map\",\"entries\":[[\"className\",\"fas fa-info-circle\"],[\"tagName\",\"i\"],[\"color\",\"white\"]]}]]}]}]},{\"type\":\"model\",\"name\":\"Notification\",\"properties\":[{\"name\":\"background\",\"kind\":\"Any\",\"default\":null},{\"name\":\"duration\",\"kind\":\"Any\",\"default\":3000},{\"name\":\"icon\",\"kind\":\"Any\",\"default\":null},{\"name\":\"message\",\"kind\":\"Any\",\"default\":\"\"},{\"name\":\"notification_type\",\"kind\":\"Any\",\"default\":null},{\"name\":\"_destroyed\",\"kind\":\"Any\",\"default\":false}]},{\"type\":\"model\",\"name\":\"TemplateActions1\",\"properties\":[{\"name\":\"open_modal\",\"kind\":\"Any\",\"default\":0},{\"name\":\"close_modal\",\"kind\":\"Any\",\"default\":0}]},{\"type\":\"model\",\"name\":\"BootstrapTemplateActions1\",\"properties\":[{\"name\":\"open_modal\",\"kind\":\"Any\",\"default\":0},{\"name\":\"close_modal\",\"kind\":\"Any\",\"default\":0}]},{\"type\":\"model\",\"name\":\"TemplateEditor1\",\"properties\":[{\"name\":\"layout\",\"kind\":\"Any\",\"default\":[]}]},{\"type\":\"model\",\"name\":\"MaterialTemplateActions1\",\"properties\":[{\"name\":\"open_modal\",\"kind\":\"Any\",\"default\":0},{\"name\":\"close_modal\",\"kind\":\"Any\",\"default\":0}]},{\"type\":\"model\",\"name\":\"ReactiveESM1\",\"properties\":[{\"name\":\"esm_constants\",\"kind\":\"Any\",\"default\":{\"type\":\"map\"}}]},{\"type\":\"model\",\"name\":\"JSComponent1\",\"properties\":[{\"name\":\"esm_constants\",\"kind\":\"Any\",\"default\":{\"type\":\"map\"}}]},{\"type\":\"model\",\"name\":\"ReactComponent1\",\"properties\":[{\"name\":\"esm_constants\",\"kind\":\"Any\",\"default\":{\"type\":\"map\"}}]},{\"type\":\"model\",\"name\":\"AnyWidgetComponent1\",\"properties\":[{\"name\":\"esm_constants\",\"kind\":\"Any\",\"default\":{\"type\":\"map\"}}]},{\"type\":\"model\",\"name\":\"request_value1\",\"properties\":[{\"name\":\"fill\",\"kind\":\"Any\",\"default\":\"none\"},{\"name\":\"_synced\",\"kind\":\"Any\",\"default\":null},{\"name\":\"_request_sync\",\"kind\":\"Any\",\"default\":0}]}]}};\n",
|
| 483 |
-
" var render_items = [{\"docid\":\"40866006-4e00-49f6-a4f0-7a9dbd367ff7\",\"roots\":{\"2020c7e1-2eb6-4d04-9556-9f1dcc3922e8\":\"e17b016e-176d-40f9-a704-88f1d749f956\"},\"root_ids\":[\"2020c7e1-2eb6-4d04-9556-9f1dcc3922e8\"]}];\n",
|
| 484 |
-
" var docs = Object.values(docs_json)\n",
|
| 485 |
-
" if (!docs) {\n",
|
| 486 |
-
" return\n",
|
| 487 |
-
" }\n",
|
| 488 |
-
" const py_version = docs[0].version.replace('rc', '-rc.').replace('.dev', '-dev.')\n",
|
| 489 |
-
" async function embed_document(root) {\n",
|
| 490 |
-
" var Bokeh = get_bokeh(root)\n",
|
| 491 |
-
" await Bokeh.embed.embed_items_notebook(docs_json, render_items);\n",
|
| 492 |
-
" for (const render_item of render_items) {\n",
|
| 493 |
-
" for (const root_id of render_item.root_ids) {\n",
|
| 494 |
-
"\tconst id_el = document.getElementById(root_id)\n",
|
| 495 |
-
"\tif (id_el.children.length && id_el.children[0].hasAttribute('data-root-id')) {\n",
|
| 496 |
-
"\t const root_el = id_el.children[0]\n",
|
| 497 |
-
"\t root_el.id = root_el.id + '-rendered'\n",
|
| 498 |
-
"\t for (const child of root_el.children) {\n",
|
| 499 |
-
" // Ensure JupyterLab does not capture keyboard shortcuts\n",
|
| 500 |
-
" // see: https://jupyterlab.readthedocs.io/en/4.1.x/extension/notebook.html#keyboard-interaction-model\n",
|
| 501 |
-
"\t child.setAttribute('data-lm-suppress-shortcuts', 'true')\n",
|
| 502 |
-
"\t }\n",
|
| 503 |
-
"\t}\n",
|
| 504 |
-
" }\n",
|
| 505 |
-
" }\n",
|
| 506 |
-
" }\n",
|
| 507 |
-
" function get_bokeh(root) {\n",
|
| 508 |
-
" if (root.Bokeh === undefined) {\n",
|
| 509 |
-
" return null\n",
|
| 510 |
-
" } else if (root.Bokeh.version !== py_version) {\n",
|
| 511 |
-
" if (root.Bokeh.versions === undefined || !root.Bokeh.versions.has(py_version)) {\n",
|
| 512 |
-
"\treturn null\n",
|
| 513 |
-
" }\n",
|
| 514 |
-
" return root.Bokeh.versions.get(py_version);\n",
|
| 515 |
-
" } else if (root.Bokeh.version === py_version) {\n",
|
| 516 |
-
" return root.Bokeh\n",
|
| 517 |
-
" }\n",
|
| 518 |
-
" return null\n",
|
| 519 |
-
" }\n",
|
| 520 |
-
" function is_loaded(root) {\n",
|
| 521 |
-
" var Bokeh = get_bokeh(root)\n",
|
| 522 |
-
" return (Bokeh != null && Bokeh.Panel !== undefined)\n",
|
| 523 |
-
" }\n",
|
| 524 |
-
" if (is_loaded(root)) {\n",
|
| 525 |
-
" embed_document(root);\n",
|
| 526 |
-
" } else {\n",
|
| 527 |
-
" var attempts = 0;\n",
|
| 528 |
-
" var timer = setInterval(function(root) {\n",
|
| 529 |
-
" if (is_loaded(root)) {\n",
|
| 530 |
-
" clearInterval(timer);\n",
|
| 531 |
-
" embed_document(root);\n",
|
| 532 |
-
" } else if (document.readyState == \"complete\") {\n",
|
| 533 |
-
" attempts++;\n",
|
| 534 |
-
" if (attempts > 200) {\n",
|
| 535 |
-
" clearInterval(timer);\n",
|
| 536 |
-
"\t var Bokeh = get_bokeh(root)\n",
|
| 537 |
-
"\t if (Bokeh == null || Bokeh.Panel == null) {\n",
|
| 538 |
-
" console.warn(\"Panel: ERROR: Unable to run Panel code because Bokeh or Panel library is missing\");\n",
|
| 539 |
-
"\t } else {\n",
|
| 540 |
-
"\t console.warn(\"Panel: WARNING: Attempting to render but not all required libraries could be resolved.\")\n",
|
| 541 |
-
"\t embed_document(root)\n",
|
| 542 |
-
"\t }\n",
|
| 543 |
-
" }\n",
|
| 544 |
-
" }\n",
|
| 545 |
-
" }, 25, root)\n",
|
| 546 |
-
" }\n",
|
| 547 |
-
"})(window);</script>"
|
| 548 |
-
],
|
| 549 |
-
"text/plain": [
|
| 550 |
-
"Column(design=<class 'panel.theme.bootst..., sizing_mode='stretch_width')\n",
|
| 551 |
-
" [0] Markdown(str, design=<class 'panel.theme.bootst..., sizing_mode='stretch_width')\n",
|
| 552 |
-
" [1] Row(design=<class 'panel.theme.bootst..., sizing_mode='stretch_width')\n",
|
| 553 |
-
" [0] FileInput(design=<class 'panel.theme.bootst..., width=300)\n",
|
| 554 |
-
" [1] PasswordInput(design=<class 'panel.theme.bootst..., placeholder='Enter your OpenAI A...)\n",
|
| 555 |
-
" [2] Row(design=<class 'panel.theme.bootst..., sizing_mode='stretch_width')\n",
|
| 556 |
-
" [0] Column(design=<class 'panel.theme.bootst..., sizing_mode='stretch_width')\n",
|
| 557 |
-
" [0] TextEditor(design=<class 'panel.theme.bootst..., height=160, placeholder='Enter your questions h..., sizing_mode='stretch_width', toolbar=False)\n",
|
| 558 |
-
" [1] Button(design=<class 'panel.theme.bootst..., name='Run!', sizing_mode='stretch_width')\n",
|
| 559 |
-
" [1] Column(design=<class 'panel.theme.bootst..., margin=10, sizing_mode='stretch_width')\n",
|
| 560 |
-
" [0] Card(design=<class 'panel.theme.bootst..., sizing_mode='stretch_width', title='Advanced settings')\n",
|
| 561 |
-
" [0] Markdown(str, design=<class 'panel.theme.bootst..., sizing_mode='stretch_width')\n",
|
| 562 |
-
" [1] Column(design=<class 'panel.theme.bootst..., sizing_mode='stretch_width')\n",
|
| 563 |
-
" [0] RadioButtonGroup(design=<class 'panel.theme.bootst..., name='Chain type', options=['stuff', 'map_reduce', ...], sizing_mode='stretch_width', value='map_reduce')\n",
|
| 564 |
-
" [1] IntSlider(design=<class 'panel.theme.bootst..., end=5, name='Number of relevant c..., sizing_mode='stretch_width', start=1, value=2)\n",
|
| 565 |
-
" [3] WidgetBox(design=<class 'panel.theme.bootst..., height=300, margin=10, scroll=True, sizing_mode='fixed', width=800)\n",
|
| 566 |
-
" [0] Markdown(str, design=<class 'panel.theme.bootst..., sizing_mode='stretch_width')\n",
|
| 567 |
-
" [1] ParamFunction(function, _pane=Column, defer_load=False, design=<class 'panel.theme.bootst..., loading_indicator=True, sizing_mode='stretch_width')"
|
| 568 |
-
]
|
| 569 |
-
},
|
| 570 |
-
"execution_count": 34,
|
| 571 |
-
"metadata": {
|
| 572 |
-
"application/vnd.holoviews_exec.v0+json": {
|
| 573 |
-
"id": "2020c7e1-2eb6-4d04-9556-9f1dcc3922e8"
|
| 574 |
-
}
|
| 575 |
-
},
|
| 576 |
-
"output_type": "execute_result"
|
| 577 |
-
}
|
| 578 |
-
],
|
| 579 |
-
"source": [
|
| 580 |
-
"# layout\n",
|
| 581 |
-
"pn.Column(\n",
|
| 582 |
-
" pn.pane.Markdown(\"\"\"\n",
|
| 583 |
-
" ## \\U0001F60A! Question Answering with your PDF file\n",
|
| 584 |
-
"\n",
|
| 585 |
-
" 1) Upload a PDF. 2) Enter OpenAI API key. This costs $. Set up billing at [OpenAI](https://platform.openai.com/account). 3) Type a question and click \"Run\"\n",
|
| 586 |
-
"\n",
|
| 587 |
-
" \"\"\"),\n",
|
| 588 |
-
" pn.Row(file_input,openaikey),\n",
|
| 589 |
-
" widgets,\n",
|
| 590 |
-
" output,\n",
|
| 591 |
-
"\n",
|
| 592 |
-
").servable()"
|
| 593 |
-
]
|
| 594 |
-
},
|
| 595 |
-
{
|
| 596 |
-
"cell_type": "code",
|
| 597 |
-
"execution_count": null,
|
| 598 |
-
"id": "90840684-f179-419d-a411-8e0b3406596f",
|
| 599 |
-
"metadata": {},
|
| 600 |
-
"outputs": [],
|
| 601 |
-
"source": []
|
| 602 |
-
},
|
| 603 |
-
{
|
| 604 |
-
"cell_type": "code",
|
| 605 |
-
"execution_count": null,
|
| 606 |
-
"id": "46ba9292-a7c7-4021-a70f-3dfae1fc909e",
|
| 607 |
-
"metadata": {},
|
| 608 |
-
"outputs": [],
|
| 609 |
-
"source": []
|
| 610 |
-
}
|
| 611 |
-
],
|
| 612 |
-
"metadata": {
|
| 613 |
-
"colab": {
|
| 614 |
-
"provenance": []
|
| 615 |
-
},
|
| 616 |
-
"kernelspec": {
|
| 617 |
-
"display_name": "Python 3 (ipykernel)",
|
| 618 |
-
"language": "python",
|
| 619 |
-
"name": "python3"
|
| 620 |
-
},
|
| 621 |
-
"language_info": {
|
| 622 |
-
"codemirror_mode": {
|
| 623 |
-
"name": "ipython",
|
| 624 |
-
"version": 3
|
| 625 |
-
},
|
| 626 |
-
"file_extension": ".py",
|
| 627 |
-
"mimetype": "text/x-python",
|
| 628 |
-
"name": "python",
|
| 629 |
-
"nbconvert_exporter": "python",
|
| 630 |
-
"pygments_lexer": "ipython3",
|
| 631 |
-
"version": "3.12.8"
|
| 632 |
-
}
|
| 633 |
-
},
|
| 634 |
-
"nbformat": 4,
|
| 635 |
-
"nbformat_minor": 5
|
| 636 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
app.py
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
|
| 3 |
+
x = st.slider('Select a value')
|
| 4 |
+
st.write(x, 'squared is', x * x)
|