Spaces:
Runtime error
Runtime error
Delete GPT-4_PDF_summary.ipynb
Browse files- GPT-4_PDF_summary.ipynb +0 -424
GPT-4_PDF_summary.ipynb
DELETED
@@ -1,424 +0,0 @@
|
|
1 |
-
{
|
2 |
-
"cells": [
|
3 |
-
{
|
4 |
-
"cell_type": "code",
|
5 |
-
"execution_count": null,
|
6 |
-
"id": "409a312d",
|
7 |
-
"metadata": {},
|
8 |
-
"outputs": [
|
9 |
-
{
|
10 |
-
"name": "stdout",
|
11 |
-
"output_type": "stream",
|
12 |
-
"text": [
|
13 |
-
"Requirement already satisfied: langchain in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (0.0.136)\n",
|
14 |
-
"Requirement already satisfied: openai in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (0.27.4)\n",
|
15 |
-
"Requirement already satisfied: chromadb in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (0.3.21)\n",
|
16 |
-
"Requirement already satisfied: tiktoken in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (0.3.3)\n",
|
17 |
-
"Requirement already satisfied: pypdf in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (3.7.1)\n",
|
18 |
-
"Requirement already satisfied: panel in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (0.14.4)\n",
|
19 |
-
"Requirement already satisfied: SQLAlchemy<2,>=1 in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (from langchain) (1.4.47)\n",
|
20 |
-
"Requirement already satisfied: pydantic<2,>=1 in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (from langchain) (1.10.7)\n",
|
21 |
-
"Requirement already satisfied: dataclasses-json<0.6.0,>=0.5.7 in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (from langchain) (0.5.7)\n",
|
22 |
-
"Requirement already satisfied: PyYAML>=5.4.1 in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (from langchain) (6.0)\n",
|
23 |
-
"Requirement already satisfied: numpy<2,>=1 in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (from langchain) (1.24.2)\n",
|
24 |
-
"Requirement already satisfied: aiohttp<4.0.0,>=3.8.3 in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (from langchain) (3.8.4)\n",
|
25 |
-
"Requirement already satisfied: openapi-schema-pydantic<2.0,>=1.2 in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (from langchain) (1.2.4)\n",
|
26 |
-
"Requirement already satisfied: requests<3,>=2 in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (from langchain) (2.28.2)\n",
|
27 |
-
"Requirement already satisfied: tenacity<9.0.0,>=8.1.0 in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (from langchain) (8.2.2)\n",
|
28 |
-
"Requirement already satisfied: async-timeout<5.0.0,>=4.0.0 in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (from langchain) (4.0.2)\n",
|
29 |
-
"Requirement already satisfied: tqdm in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (from openai) (4.65.0)\n",
|
30 |
-
"Requirement already satisfied: uvicorn[standard]>=0.18.3 in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (from chromadb) (0.21.1)\n",
|
31 |
-
"Requirement already satisfied: pandas>=1.3 in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (from chromadb) (2.0.0)\n",
|
32 |
-
"Requirement already satisfied: hnswlib>=0.7 in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (from chromadb) (0.7.0)\n",
|
33 |
-
"Requirement already satisfied: fastapi>=0.85.1 in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (from chromadb) (0.95.0)\n",
|
34 |
-
"Requirement already satisfied: sentence-transformers>=2.2.2 in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (from chromadb) (2.2.2)\n",
|
35 |
-
"Requirement already satisfied: duckdb>=0.7.1 in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (from chromadb) (0.7.1)\n",
|
36 |
-
"Requirement already satisfied: posthog>=2.4.0 in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (from chromadb) (2.5.0)\n",
|
37 |
-
"Requirement already satisfied: clickhouse-connect>=0.5.7 in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (from chromadb) (0.5.20)\n",
|
38 |
-
"Requirement already satisfied: regex>=2022.1.18 in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (from tiktoken) (2023.3.23)\n",
|
39 |
-
"Requirement already satisfied: setuptools>=42 in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (from panel) (65.5.0)\n",
|
40 |
-
"Requirement already satisfied: pyviz-comms>=0.7.4 in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (from panel) (2.2.1)\n",
|
41 |
-
"Requirement already satisfied: pyct>=0.4.4 in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (from panel) (0.5.0)\n",
|
42 |
-
"Requirement already satisfied: bleach in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (from panel) (6.0.0)\n",
|
43 |
-
"Requirement already satisfied: param>=1.12.0 in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (from panel) (1.13.0)\n",
|
44 |
-
"Requirement already satisfied: typing-extensions in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (from panel) (4.5.0)\n",
|
45 |
-
"Requirement already satisfied: bokeh<2.5.0,>=2.4.0 in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (from panel) (2.4.3)\n",
|
46 |
-
"Requirement already satisfied: markdown in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (from panel) (3.4.3)\n",
|
47 |
-
"Requirement already satisfied: attrs>=17.3.0 in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (from aiohttp<4.0.0,>=3.8.3->langchain) (22.2.0)\n",
|
48 |
-
"Requirement already satisfied: yarl<2.0,>=1.0 in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (from aiohttp<4.0.0,>=3.8.3->langchain) (1.8.2)\n",
|
49 |
-
"Requirement already satisfied: multidict<7.0,>=4.5 in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (from aiohttp<4.0.0,>=3.8.3->langchain) (6.0.4)\n",
|
50 |
-
"Requirement already satisfied: aiosignal>=1.1.2 in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (from aiohttp<4.0.0,>=3.8.3->langchain) (1.3.1)\n",
|
51 |
-
"Requirement already satisfied: frozenlist>=1.1.1 in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (from aiohttp<4.0.0,>=3.8.3->langchain) (1.3.3)\n",
|
52 |
-
"Requirement already satisfied: charset-normalizer<4.0,>=2.0 in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (from aiohttp<4.0.0,>=3.8.3->langchain) (3.1.0)\n",
|
53 |
-
"Requirement already satisfied: Jinja2>=2.9 in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (from bokeh<2.5.0,>=2.4.0->panel) (3.1.2)\n",
|
54 |
-
"Requirement already satisfied: tornado>=5.1 in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (from bokeh<2.5.0,>=2.4.0->panel) (6.2)\n",
|
55 |
-
"Requirement already satisfied: pillow>=7.1.0 in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (from bokeh<2.5.0,>=2.4.0->panel) (9.5.0)\n",
|
56 |
-
"Requirement already satisfied: packaging>=16.8 in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (from bokeh<2.5.0,>=2.4.0->panel) (23.0)\n",
|
57 |
-
"Requirement already satisfied: pytz in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (from clickhouse-connect>=0.5.7->chromadb) (2023.3)\n",
|
58 |
-
"Requirement already satisfied: urllib3>=1.26 in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (from clickhouse-connect>=0.5.7->chromadb) (1.26.15)\n",
|
59 |
-
"Requirement already satisfied: certifi in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (from clickhouse-connect>=0.5.7->chromadb) (2022.12.7)\n",
|
60 |
-
"Requirement already satisfied: zstandard in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (from clickhouse-connect>=0.5.7->chromadb) (0.20.0)\n",
|
61 |
-
"Requirement already satisfied: lz4 in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (from clickhouse-connect>=0.5.7->chromadb) (4.3.2)\n",
|
62 |
-
"Requirement already satisfied: marshmallow<4.0.0,>=3.3.0 in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (from dataclasses-json<0.6.0,>=0.5.7->langchain) (3.19.0)\n",
|
63 |
-
"Requirement already satisfied: typing-inspect>=0.4.0 in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (from dataclasses-json<0.6.0,>=0.5.7->langchain) (0.8.0)\n",
|
64 |
-
"Requirement already satisfied: marshmallow-enum<2.0.0,>=1.5.1 in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (from dataclasses-json<0.6.0,>=0.5.7->langchain) (1.5.1)\n",
|
65 |
-
"Requirement already satisfied: starlette<0.27.0,>=0.26.1 in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (from fastapi>=0.85.1->chromadb) (0.26.1)\n"
|
66 |
-
]
|
67 |
-
},
|
68 |
-
{
|
69 |
-
"name": "stdout",
|
70 |
-
"output_type": "stream",
|
71 |
-
"text": [
|
72 |
-
"Requirement already satisfied: python-dateutil>=2.8.2 in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (from pandas>=1.3->chromadb) (2.8.2)\n",
|
73 |
-
"Requirement already satisfied: tzdata>=2022.1 in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (from pandas>=1.3->chromadb) (2023.3)\n",
|
74 |
-
"Requirement already satisfied: six>=1.5 in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (from posthog>=2.4.0->chromadb) (1.16.0)\n",
|
75 |
-
"Requirement already satisfied: monotonic>=1.5 in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (from posthog>=2.4.0->chromadb) (1.6)\n",
|
76 |
-
"Requirement already satisfied: backoff>=1.10.0 in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (from posthog>=2.4.0->chromadb) (2.2.1)\n",
|
77 |
-
"Requirement already satisfied: idna<4,>=2.5 in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (from requests<3,>=2->langchain) (3.4)\n",
|
78 |
-
"Requirement already satisfied: transformers<5.0.0,>=4.6.0 in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (from sentence-transformers>=2.2.2->chromadb) (4.27.4)\n",
|
79 |
-
"Requirement already satisfied: torch>=1.6.0 in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (from sentence-transformers>=2.2.2->chromadb) (2.0.0)\n",
|
80 |
-
"Requirement already satisfied: torchvision in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (from sentence-transformers>=2.2.2->chromadb) (0.15.1)\n",
|
81 |
-
"Requirement already satisfied: scikit-learn in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (from sentence-transformers>=2.2.2->chromadb) (1.2.2)\n",
|
82 |
-
"Requirement already satisfied: scipy in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (from sentence-transformers>=2.2.2->chromadb) (1.10.1)\n",
|
83 |
-
"Requirement already satisfied: nltk in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (from sentence-transformers>=2.2.2->chromadb) (3.8.1)\n",
|
84 |
-
"Requirement already satisfied: sentencepiece in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (from sentence-transformers>=2.2.2->chromadb) (0.1.97)\n",
|
85 |
-
"Requirement already satisfied: huggingface-hub>=0.4.0 in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (from sentence-transformers>=2.2.2->chromadb) (0.13.4)\n",
|
86 |
-
"Requirement already satisfied: click>=7.0 in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (from uvicorn[standard]>=0.18.3->chromadb) (8.1.3)\n",
|
87 |
-
"Requirement already satisfied: h11>=0.8 in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (from uvicorn[standard]>=0.18.3->chromadb) (0.14.0)\n",
|
88 |
-
"Requirement already satisfied: uvloop!=0.15.0,!=0.15.1,>=0.14.0 in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (from uvicorn[standard]>=0.18.3->chromadb) (0.17.0)\n",
|
89 |
-
"Requirement already satisfied: httptools>=0.5.0 in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (from uvicorn[standard]>=0.18.3->chromadb) (0.5.0)\n",
|
90 |
-
"Requirement already satisfied: websockets>=10.4 in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (from uvicorn[standard]>=0.18.3->chromadb) (11.0.1)\n",
|
91 |
-
"Requirement already satisfied: python-dotenv>=0.13 in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (from uvicorn[standard]>=0.18.3->chromadb) (1.0.0)\n",
|
92 |
-
"Requirement already satisfied: watchfiles>=0.13 in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (from uvicorn[standard]>=0.18.3->chromadb) (0.19.0)\n",
|
93 |
-
"Requirement already satisfied: webencodings in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (from bleach->panel) (0.5.1)\n",
|
94 |
-
"Requirement already satisfied: filelock in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (from huggingface-hub>=0.4.0->sentence-transformers>=2.2.2->chromadb) (3.11.0)\n",
|
95 |
-
"Requirement already satisfied: MarkupSafe>=2.0 in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (from Jinja2>=2.9->bokeh<2.5.0,>=2.4.0->panel) (2.1.2)\n",
|
96 |
-
"Requirement already satisfied: anyio<5,>=3.4.0 in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (from starlette<0.27.0,>=0.26.1->fastapi>=0.85.1->chromadb) (3.6.2)\n",
|
97 |
-
"Requirement already satisfied: sympy in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (from torch>=1.6.0->sentence-transformers>=2.2.2->chromadb) (1.11.1)\n",
|
98 |
-
"Requirement already satisfied: networkx in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (from torch>=1.6.0->sentence-transformers>=2.2.2->chromadb) (3.1)\n",
|
99 |
-
"Requirement already satisfied: tokenizers!=0.11.3,<0.14,>=0.11.1 in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (from transformers<5.0.0,>=4.6.0->sentence-transformers>=2.2.2->chromadb) (0.13.3)\n",
|
100 |
-
"Requirement already satisfied: mypy-extensions>=0.3.0 in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (from typing-inspect>=0.4.0->dataclasses-json<0.6.0,>=0.5.7->langchain) (1.0.0)\n",
|
101 |
-
"Requirement already satisfied: joblib in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (from nltk->sentence-transformers>=2.2.2->chromadb) (1.2.0)\n",
|
102 |
-
"Requirement already satisfied: threadpoolctl>=2.0.0 in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (from scikit-learn->sentence-transformers>=2.2.2->chromadb) (3.1.0)\n",
|
103 |
-
"Requirement already satisfied: sniffio>=1.1 in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (from anyio<5,>=3.4.0->starlette<0.27.0,>=0.26.1->fastapi>=0.85.1->chromadb) (1.3.0)\n",
|
104 |
-
"Requirement already satisfied: mpmath>=0.19 in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (from sympy->torch>=1.6.0->sentence-transformers>=2.2.2->chromadb) (1.3.0)\n"
|
105 |
-
]
|
106 |
-
}
|
107 |
-
],
|
108 |
-
"source": [
|
109 |
-
"!pip install langchain openai chromadb tiktoken pypdf panel"
|
110 |
-
]
|
111 |
-
},
|
112 |
-
{
|
113 |
-
"cell_type": "code",
|
114 |
-
"execution_count": null,
|
115 |
-
"id": "dcbbf6df",
|
116 |
-
"metadata": {},
|
117 |
-
"outputs": [
|
118 |
-
{
|
119 |
-
"data": {
|
120 |
-
"application/javascript": "(function(root) {\n function now() {\n return new Date();\n }\n\n var force = true;\n\n if (typeof root._bokeh_onload_callbacks === \"undefined\" || force === true) {\n root._bokeh_onload_callbacks = [];\n root._bokeh_is_loading = undefined;\n }\n\n if (typeof (root._bokeh_timeout) === \"undefined\" || force === true) {\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, callback) {\n if (css_urls == null) css_urls = [];\n if (js_urls == null) js_urls = [];\n if (js_modules == null) js_modules = [];\n\n root._bokeh_onload_callbacks.push(callback);\n if (root._bokeh_is_loading > 0) {\n console.debug(\"Bokeh: BokehJS is being loaded, scheduling callback at\", now());\n return null;\n }\n if (js_urls.length === 0 && js_modules.length === 0) {\n run_callbacks();\n return null;\n }\n console.debug(\"Bokeh: BokehJS not loaded, scheduling load and callback at\", now());\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\n function on_error() {\n console.error(\"failed to load \" + url);\n }\n\n for (var i = 0; i < css_urls.length; i++) {\n var url = css_urls[i];\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 }\n\n var skip = [];\n if (window.requirejs) {\n window.requirejs.config({'packages': {}, 'paths': {'Quill': 'https://cdn.quilljs.com/1.3.6/quill', 'gridstack': 'https://cdn.jsdelivr.net/npm/gridstack@4.2.5/dist/gridstack-h5', 'notyf': 'https://cdn.jsdelivr.net/npm/notyf@3/notyf.min'}, 'shim': {'gridstack': {'exports': 'GridStack'}}});\n require([\"Quill\"], function(Quill) {\n\twindow.Quill = Quill\n\ton_load()\n })\n require([\"gridstack\"], function(GridStack) {\n\twindow.GridStack = GridStack\n\ton_load()\n })\n require([\"notyf\"], function() {\n\ton_load()\n })\n root._bokeh_is_loading = css_urls.length + 3;\n } else {\n root._bokeh_is_loading = css_urls.length + js_urls.length + js_modules.length;\n } if (((window['Quill'] !== undefined) && (!(window['Quill'] instanceof HTMLElement))) || window.requirejs) {\n var urls = ['https://cdn.holoviz.org/panel/0.14.4/dist/bundled/quillinput/1.3.6/quill.js'];\n for (var i = 0; i < urls.length; i++) {\n skip.push(urls[i])\n }\n } if (((window['GridStack'] !== undefined) && (!(window['GridStack'] instanceof HTMLElement))) || window.requirejs) {\n var urls = ['https://cdn.holoviz.org/panel/0.14.4/dist/bundled/gridstack/gridstack@4.2.5/dist/gridstack-h5.js'];\n for (var i = 0; i < urls.length; i++) {\n skip.push(urls[i])\n }\n } if (((window['Notyf'] !== undefined) && (!(window['Notyf'] instanceof HTMLElement))) || window.requirejs) {\n var urls = ['https://cdn.holoviz.org/panel/0.14.4/dist/bundled/notificationarea/notyf@3/notyf.min.js'];\n for (var i = 0; i < urls.length; i++) {\n skip.push(urls[i])\n }\n } for (var i = 0; i < js_urls.length; i++) {\n var url = js_urls[i];\n if (skip.indexOf(url) >= 0) {\n\tif (!window.requirejs) {\n\t on_load();\n\t}\n\tcontinue;\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 console.debug(\"Bokeh: injecting script tag for BokehJS library: \", url);\n document.head.appendChild(element);\n }\n for (var i = 0; i < js_modules.length; i++) {\n var url = js_modules[i];\n if (skip.indexOf(url) >= 0) {\n\tif (!window.requirejs) {\n\t on_load();\n\t}\n\tcontinue;\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 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 var js_urls = [\"https://cdn.holoviz.org/panel/0.14.4/dist/bundled/quillinput/1.3.6/quill.js\", \"https://cdn.bokeh.org/bokeh/release/bokeh-2.4.3.min.js\", \"https://cdn.bokeh.org/bokeh/release/bokeh-gl-2.4.3.min.js\", \"https://cdn.bokeh.org/bokeh/release/bokeh-widgets-2.4.3.min.js\", \"https://cdn.bokeh.org/bokeh/release/bokeh-tables-2.4.3.min.js\", \"https://cdn.bokeh.org/bokeh/release/bokeh-mathjax-2.4.3.min.js\", \"https://unpkg.com/@holoviz/panel@0.14.4/dist/panel.min.js\"];\n var js_modules = [];\n var css_urls = [\"https://cdn.holoviz.org/panel/0.14.4/dist/bundled/quillinput/1.3.6/quill.bubble.css\", \"https://cdn.holoviz.org/panel/0.14.4/dist/bundled/quillinput/1.3.6/quill.snow.css\", \"https://cdn.holoviz.org/panel/0.14.4/dist/css/debugger.css\", \"https://cdn.holoviz.org/panel/0.14.4/dist/css/alerts.css\", \"https://cdn.holoviz.org/panel/0.14.4/dist/css/card.css\", \"https://cdn.holoviz.org/panel/0.14.4/dist/css/widgets.css\", \"https://cdn.holoviz.org/panel/0.14.4/dist/css/markdown.css\", \"https://cdn.holoviz.org/panel/0.14.4/dist/css/json.css\", \"https://cdn.holoviz.org/panel/0.14.4/dist/css/loading.css\", \"https://cdn.holoviz.org/panel/0.14.4/dist/css/dataframe.css\"];\n var inline_js = [ function(Bokeh) {\n inject_raw_css(\"\\n .bk.pn-loading.arc:before {\\n background-image: url(\\\"data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHN0eWxlPSJtYXJnaW46IGF1dG87IGJhY2tncm91bmQ6IG5vbmU7IGRpc3BsYXk6IGJsb2NrOyBzaGFwZS1yZW5kZXJpbmc6IGF1dG87IiB2aWV3Qm94PSIwIDAgMTAwIDEwMCIgcHJlc2VydmVBc3BlY3RSYXRpbz0ieE1pZFlNaWQiPiAgPGNpcmNsZSBjeD0iNTAiIGN5PSI1MCIgZmlsbD0ibm9uZSIgc3Ryb2tlPSIjYzNjM2MzIiBzdHJva2Utd2lkdGg9IjEwIiByPSIzNSIgc3Ryb2tlLWRhc2hhcnJheT0iMTY0LjkzMzYxNDMxMzQ2NDE1IDU2Ljk3Nzg3MTQzNzgyMTM4Ij4gICAgPGFuaW1hdGVUcmFuc2Zvcm0gYXR0cmlidXRlTmFtZT0idHJhbnNmb3JtIiB0eXBlPSJyb3RhdGUiIHJlcGVhdENvdW50PSJpbmRlZmluaXRlIiBkdXI9IjFzIiB2YWx1ZXM9IjAgNTAgNTA7MzYwIDUwIDUwIiBrZXlUaW1lcz0iMDsxIj48L2FuaW1hdGVUcmFuc2Zvcm0+ICA8L2NpcmNsZT48L3N2Zz4=\\\");\\n background-size: auto calc(min(50%, 400px));\\n }\\n \");\n }, 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 (var i = 0; i < inline_js.length; i++) {\n inline_js[i].call(root, root.Bokeh);\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 }\n\n if (root._bokeh_is_loading === 0) {\n console.debug(\"Bokeh: BokehJS loaded, going straight to plotting\");\n run_inline_js();\n } else {\n load_libs(css_urls, js_urls, js_modules, function() {\n console.debug(\"Bokeh: BokehJS plotting callback run at\", now());\n run_inline_js();\n });\n }\n}(window));",
|
121 |
-
"application/vnd.holoviews_load.v0+json": ""
|
122 |
-
},
|
123 |
-
"metadata": {},
|
124 |
-
"output_type": "display_data"
|
125 |
-
},
|
126 |
-
{
|
127 |
-
"data": {
|
128 |
-
"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",
|
129 |
-
"application/vnd.holoviews_load.v0+json": ""
|
130 |
-
},
|
131 |
-
"metadata": {},
|
132 |
-
"output_type": "display_data"
|
133 |
-
},
|
134 |
-
{
|
135 |
-
"data": {
|
136 |
-
"text/html": [
|
137 |
-
"<style>.bk-root, .bk-root .bk:before, .bk-root .bk:after {\n",
|
138 |
-
" font-family: var(--jp-ui-font-size1);\n",
|
139 |
-
" font-size: var(--jp-ui-font-size1);\n",
|
140 |
-
" color: var(--jp-ui-font-color1);\n",
|
141 |
-
"}\n",
|
142 |
-
"</style>"
|
143 |
-
]
|
144 |
-
},
|
145 |
-
"metadata": {},
|
146 |
-
"output_type": "display_data"
|
147 |
-
}
|
148 |
-
],
|
149 |
-
"source": [
|
150 |
-
"import os \n",
|
151 |
-
"from langchain.chains import RetrievalQA\n",
|
152 |
-
"from langchain.llms import OpenAI\n",
|
153 |
-
"from langchain.document_loaders import TextLoader\n",
|
154 |
-
"from langchain.document_loaders import PyPDFLoader\n",
|
155 |
-
"from langchain.indexes import VectorstoreIndexCreator\n",
|
156 |
-
"from langchain.text_splitter import CharacterTextSplitter\n",
|
157 |
-
"from langchain.embeddings import OpenAIEmbeddings\n",
|
158 |
-
"from langchain.vectorstores import Chroma\n",
|
159 |
-
"import panel as pn\n",
|
160 |
-
"import tempfile"
|
161 |
-
]
|
162 |
-
},
|
163 |
-
{
|
164 |
-
"cell_type": "code",
|
165 |
-
"execution_count": null,
|
166 |
-
"id": "9d891458",
|
167 |
-
"metadata": {},
|
168 |
-
"outputs": [],
|
169 |
-
"source": [
|
170 |
-
"pn.extension('texteditor', template=\"bootstrap\", sizing_mode='stretch_width')\n",
|
171 |
-
"pn.state.template.param.update(\n",
|
172 |
-
" main_max_width=\"690px\",\n",
|
173 |
-
" header_background=\"#F08080\",\n",
|
174 |
-
")"
|
175 |
-
]
|
176 |
-
},
|
177 |
-
{
|
178 |
-
"cell_type": "code",
|
179 |
-
"execution_count": 3,
|
180 |
-
"id": "fcd48f62",
|
181 |
-
"metadata": {},
|
182 |
-
"outputs": [],
|
183 |
-
"source": [
|
184 |
-
"file_input = pn.widgets.FileInput(width=300)\n",
|
185 |
-
"\n",
|
186 |
-
"openaikey = pn.widgets.PasswordInput(\n",
|
187 |
-
" value=\"\", placeholder=\"Enter your OpenAI API Key here...\", width=300\n",
|
188 |
-
")\n",
|
189 |
-
"prompt = pn.widgets.TextEditor(\n",
|
190 |
-
" value=\"\", placeholder=\"Enter your questions here...\", height=160, toolbar=False\n",
|
191 |
-
")\n",
|
192 |
-
"run_button = pn.widgets.Button(name=\"Run!\")\n",
|
193 |
-
"\n",
|
194 |
-
"select_k = pn.widgets.IntSlider(\n",
|
195 |
-
" name=\"Number of relevant chunks\", start=1, end=5, step=1, value=2\n",
|
196 |
-
")\n",
|
197 |
-
"select_chain_type = pn.widgets.RadioButtonGroup(\n",
|
198 |
-
" name='Chain type', \n",
|
199 |
-
" options=['stuff', 'map_reduce', \"refine\", \"map_rerank\"]\n",
|
200 |
-
")\n",
|
201 |
-
"\n",
|
202 |
-
"widgets = pn.Row(\n",
|
203 |
-
" pn.Column(prompt, run_button, margin=5),\n",
|
204 |
-
" pn.Card(\n",
|
205 |
-
" \"Chain type:\",\n",
|
206 |
-
" pn.Column(select_chain_type, select_k),\n",
|
207 |
-
" title=\"Advanced settings\", margin=10\n",
|
208 |
-
" ), width=600\n",
|
209 |
-
")"
|
210 |
-
]
|
211 |
-
},
|
212 |
-
{
|
213 |
-
"cell_type": "code",
|
214 |
-
"execution_count": 4,
|
215 |
-
"id": "dd7114ba",
|
216 |
-
"metadata": {},
|
217 |
-
"outputs": [],
|
218 |
-
"source": [
|
219 |
-
"def qa(file, query, chain_type, k):\n",
|
220 |
-
" # load document\n",
|
221 |
-
" loader = PyPDFLoader(file)\n",
|
222 |
-
" documents = loader.load()\n",
|
223 |
-
" # split the documents into chunks\n",
|
224 |
-
" text_splitter = CharacterTextSplitter(chunk_size=1000, chunk_overlap=0)\n",
|
225 |
-
" texts = text_splitter.split_documents(documents)\n",
|
226 |
-
" # select which embeddings we want to use\n",
|
227 |
-
" embeddings = OpenAIEmbeddings()\n",
|
228 |
-
" # create the vectorestore to use as the index\n",
|
229 |
-
" db = Chroma.from_documents(texts, embeddings)\n",
|
230 |
-
" # expose this index in a retriever interface\n",
|
231 |
-
" retriever = db.as_retriever(search_type=\"similarity\", search_kwargs={\"k\": k})\n",
|
232 |
-
" # create a chain to answer questions \n",
|
233 |
-
" qa = RetrievalQA.from_chain_type(\n",
|
234 |
-
" llm=OpenAI(), chain_type=chain_type, retriever=retriever, return_source_documents=True)\n",
|
235 |
-
" result = qa({\"query\": query})\n",
|
236 |
-
" print(result['result'])\n",
|
237 |
-
" return result"
|
238 |
-
]
|
239 |
-
},
|
240 |
-
{
|
241 |
-
"cell_type": "code",
|
242 |
-
"execution_count": 6,
|
243 |
-
"id": "8ef4ae70",
|
244 |
-
"metadata": {},
|
245 |
-
"outputs": [],
|
246 |
-
"source": [
|
247 |
-
"convos = [] # store all panel objects in a list\n",
|
248 |
-
"\n",
|
249 |
-
"def qa_result(_):\n",
|
250 |
-
" os.environ[\"OPENAI_API_KEY\"] = openaikey.value\n",
|
251 |
-
" \n",
|
252 |
-
" # save pdf file to a temp file \n",
|
253 |
-
" if file_input.value is not None:\n",
|
254 |
-
" file_input.save(\"/.cache/temp.pdf\")\n",
|
255 |
-
" \n",
|
256 |
-
" prompt_text = prompt.value\n",
|
257 |
-
" if prompt_text:\n",
|
258 |
-
" result = qa(file=\"/.cache/temp.pdf\", query=prompt_text, chain_type=select_chain_type.value, k=select_k.value)\n",
|
259 |
-
" convos.extend([\n",
|
260 |
-
" pn.Row(\n",
|
261 |
-
" pn.panel(\"\\U0001F60A\", width=10),\n",
|
262 |
-
" prompt_text,\n",
|
263 |
-
" width=600\n",
|
264 |
-
" ),\n",
|
265 |
-
" pn.Row(\n",
|
266 |
-
" pn.panel(\"\\U0001F916\", width=10),\n",
|
267 |
-
" pn.Column(\n",
|
268 |
-
" result[\"result\"],\n",
|
269 |
-
" \"Relevant source text:\",\n",
|
270 |
-
" pn.pane.Markdown('\\n--------------------------------------------------------------------\\n'.join(doc.page_content for doc in result[\"source_documents\"]))\n",
|
271 |
-
" )\n",
|
272 |
-
" )\n",
|
273 |
-
" ])\n",
|
274 |
-
" #return convos\n",
|
275 |
-
" return pn.Column(*convos, margin=15, width=575, min_height=400)"
|
276 |
-
]
|
277 |
-
},
|
278 |
-
{
|
279 |
-
"cell_type": "code",
|
280 |
-
"execution_count": 7,
|
281 |
-
"id": "6a682e65",
|
282 |
-
"metadata": {
|
283 |
-
"scrolled": true
|
284 |
-
},
|
285 |
-
"outputs": [],
|
286 |
-
"source": [
|
287 |
-
"qa_interactive = pn.panel(\n",
|
288 |
-
" pn.bind(qa_result, run_button),\n",
|
289 |
-
" loading_indicator=True,\n",
|
290 |
-
")"
|
291 |
-
]
|
292 |
-
},
|
293 |
-
{
|
294 |
-
"cell_type": "code",
|
295 |
-
"execution_count": 8,
|
296 |
-
"id": "4258f908",
|
297 |
-
"metadata": {},
|
298 |
-
"outputs": [],
|
299 |
-
"source": [
|
300 |
-
"output = pn.WidgetBox('*Output will show up here:*', qa_interactive, width=630, scroll=True)"
|
301 |
-
]
|
302 |
-
},
|
303 |
-
{
|
304 |
-
"cell_type": "code",
|
305 |
-
"execution_count": 9,
|
306 |
-
"id": "42a031d1",
|
307 |
-
"metadata": {
|
308 |
-
"scrolled": true
|
309 |
-
},
|
310 |
-
"outputs": [
|
311 |
-
{
|
312 |
-
"data": {},
|
313 |
-
"metadata": {},
|
314 |
-
"output_type": "display_data"
|
315 |
-
},
|
316 |
-
{
|
317 |
-
"data": {
|
318 |
-
"application/vnd.holoviews_exec.v0+json": "",
|
319 |
-
"text/html": [
|
320 |
-
"<div id='1005'>\n",
|
321 |
-
" <div class=\"bk-root\" id=\"c2b6d391-2418-4059-a838-b20218c1be11\" data-root-id=\"1005\"></div>\n",
|
322 |
-
"</div>\n",
|
323 |
-
"<script type=\"application/javascript\">(function(root) {\n",
|
324 |
-
" function embed_document(root) {\n",
|
325 |
-
" var docs_json = {\"d0252f16-7a5e-460a-82c3-6b7db2f9af2a\":{\"defs\":[{\"extends\":null,\"module\":null,\"name\":\"ReactiveHTML1\",\"overrides\":[],\"properties\":[]},{\"extends\":null,\"module\":null,\"name\":\"FlexBox1\",\"overrides\":[],\"properties\":[{\"default\":\"flex-start\",\"kind\":null,\"name\":\"align_content\"},{\"default\":\"flex-start\",\"kind\":null,\"name\":\"align_items\"},{\"default\":\"row\",\"kind\":null,\"name\":\"flex_direction\"},{\"default\":\"wrap\",\"kind\":null,\"name\":\"flex_wrap\"},{\"default\":\"flex-start\",\"kind\":null,\"name\":\"justify_content\"}]},{\"extends\":null,\"module\":null,\"name\":\"GridStack1\",\"overrides\":[],\"properties\":[{\"default\":\"warn\",\"kind\":null,\"name\":\"mode\"},{\"default\":null,\"kind\":null,\"name\":\"ncols\"},{\"default\":null,\"kind\":null,\"name\":\"nrows\"},{\"default\":true,\"kind\":null,\"name\":\"allow_resize\"},{\"default\":true,\"kind\":null,\"name\":\"allow_drag\"},{\"default\":[],\"kind\":null,\"name\":\"state\"}]},{\"extends\":null,\"module\":null,\"name\":\"click1\",\"overrides\":[],\"properties\":[{\"default\":\"\",\"kind\":null,\"name\":\"terminal_output\"},{\"default\":\"\",\"kind\":null,\"name\":\"debug_name\"},{\"default\":0,\"kind\":null,\"name\":\"clears\"}]},{\"extends\":null,\"module\":null,\"name\":\"NotificationAreaBase1\",\"overrides\":[],\"properties\":[{\"default\":\"bottom-right\",\"kind\":null,\"name\":\"position\"},{\"default\":0,\"kind\":null,\"name\":\"_clear\"}]},{\"extends\":null,\"module\":null,\"name\":\"NotificationArea1\",\"overrides\":[],\"properties\":[{\"default\":[],\"kind\":null,\"name\":\"notifications\"},{\"default\":\"bottom-right\",\"kind\":null,\"name\":\"position\"},{\"default\":0,\"kind\":null,\"name\":\"_clear\"},{\"default\":[{\"background\":\"#ffc107\",\"icon\":{\"className\":\"fas fa-exclamation-triangle\",\"color\":\"white\",\"tagName\":\"i\"},\"type\":\"warning\"},{\"background\":\"#007bff\",\"icon\":{\"className\":\"fas fa-info-circle\",\"color\":\"white\",\"tagName\":\"i\"},\"type\":\"info\"}],\"kind\":null,\"name\":\"types\"}]},{\"extends\":null,\"module\":null,\"name\":\"Notification\",\"overrides\":[],\"properties\":[{\"default\":null,\"kind\":null,\"name\":\"background\"},{\"default\":3000,\"kind\":null,\"name\":\"duration\"},{\"default\":null,\"kind\":null,\"name\":\"icon\"},{\"default\":\"\",\"kind\":null,\"name\":\"message\"},{\"default\":null,\"kind\":null,\"name\":\"notification_type\"},{\"default\":false,\"kind\":null,\"name\":\"_destroyed\"}]},{\"extends\":null,\"module\":null,\"name\":\"TemplateActions1\",\"overrides\":[],\"properties\":[{\"default\":0,\"kind\":null,\"name\":\"open_modal\"},{\"default\":0,\"kind\":null,\"name\":\"close_modal\"}]},{\"extends\":null,\"module\":null,\"name\":\"MaterialTemplateActions1\",\"overrides\":[],\"properties\":[{\"default\":0,\"kind\":null,\"name\":\"open_modal\"},{\"default\":0,\"kind\":null,\"name\":\"close_modal\"}]}],\"roots\":{\"references\":[{\"attributes\":{\"margin\":[5,10,5,10],\"min_width\":300,\"width\":300},\"id\":\"1008\",\"type\":\"FileInput\"},{\"attributes\":{\"children\":[{\"id\":\"1015\"},{\"id\":\"1018\"}],\"margin\":[0,0,0,0],\"min_width\":600,\"name\":\"Row00135\",\"width\":600},\"id\":\"1014\",\"type\":\"Row\"},{\"attributes\":{\"children\":[{\"id\":\"1013\"}],\"margin\":[0,0,0,0],\"name\":\"Row00143\"},\"id\":\"1012\",\"type\":\"Row\"},{\"attributes\":{\"css_classes\":[\"markdown\"],\"margin\":[5,5,5,5],\"name\":\"Markdown00150\",\"sizing_mode\":\"stretch_width\",\"text\":\"<h2>\\ud83d\\ude0a! Question Answering with your PDF file</h2>\\n<p>1) Upload a PDF. 2) Enter OpenAI API key. This costs $. Set up billing at OpenAl. 3) Type a question and click &ldquo;Run&rdquo;.</p>\"},\"id\":\"1006\",\"type\":\"panel.models.markup.HTML\"},{\"attributes\":{\"css_classes\":[\"card-title\"],\"margin\":[5,0,5,0],\"name\":\"HTML00133\",\"sizing_mode\":\"stretch_width\",\"text\":\"Advanced settings\"},\"id\":\"1020\",\"type\":\"panel.models.markup.HTML\"},{\"attributes\":{\"client_comm_id\":\"636fa13814d14cc7aa2be03345a882c8\",\"comm_id\":\"5d51c478032046488a5141321f68b245\",\"plot_id\":\"1005\"},\"id\":\"1026\",\"type\":\"panel.models.comm_manager.CommManager\"},{\"attributes\":{\"children\":[{\"id\":\"1022\"},{\"id\":\"1023\"},{\"id\":\"1024\"}],\"margin\":[0,0,0,0],\"name\":\"Column00130\",\"sizing_mode\":\"stretch_width\"},\"id\":\"1021\",\"type\":\"Column\"},{\"attributes\":{\"end\":5,\"margin\":[5,10,5,10],\"sizing_mode\":\"stretch_width\",\"start\":1,\"title\":\"Number of relevant chunks\",\"value\":2},\"id\":\"1024\",\"type\":\"Slider\"},{\"attributes\":{\"children\":[{\"id\":\"1016\"},{\"id\":\"1017\"}],\"margin\":[5,5,5,5],\"name\":\"Column00127\",\"sizing_mode\":\"stretch_width\"},\"id\":\"1015\",\"type\":\"Column\"},{\"attributes\":{\"args\":{\"bidirectional\":false,\"properties\":{\"event:button_click\":\"loading\"},\"source\":{\"id\":\"1017\"},\"target\":{\"id\":\"1012\"}},\"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', '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 \",\"tags\":[[4820498704,[null,\"event:button_click\"],[null,\"loading\"]]]},\"id\":\"1025\",\"type\":\"CustomJS\"},{\"attributes\":{\"children\":[{\"id\":\"1020\"}],\"css_classes\":[\"card-header-row\"],\"margin\":[0,0,0,0],\"name\":\"Row00131\",\"sizing_mode\":\"stretch_width\"},\"id\":\"1019\",\"type\":\"Row\"},{\"attributes\":{\"children\":[{\"id\":\"1006\"},{\"id\":\"1007\"},{\"id\":\"1010\"},{\"id\":\"1014\"}],\"margin\":[0,0,0,0],\"name\":\"Column00153\",\"sizing_mode\":\"stretch_width\"},\"id\":\"1005\",\"type\":\"Column\"},{\"attributes\":{\"children\":[{\"id\":\"1011\"},{\"id\":\"1012\"}],\"css_classes\":[\"panel-widget-box\",\"scrollable\"],\"margin\":[5,5,5,5],\"min_width\":630,\"name\":\"WidgetBox00149\",\"width\":630},\"id\":\"1010\",\"type\":\"Column\"},{\"attributes\":{\"css_classes\":[\"markdown\"],\"margin\":[5,5,5,5],\"name\":\"Markdown00147\",\"sizing_mode\":\"stretch_width\",\"text\":\"<p><em>Output will show up here:</em></p>\"},\"id\":\"1011\",\"type\":\"panel.models.markup.HTML\"},{\"attributes\":{\"icon\":null,\"js_event_callbacks\":{\"button_click\":[{\"id\":\"1025\"}]},\"label\":\"Run!\",\"margin\":[5,10,5,10],\"sizing_mode\":\"stretch_width\",\"subscribed_events\":[\"button_click\"]},\"id\":\"1017\",\"type\":\"Button\"},{\"attributes\":{\"margin\":[5,10,5,10],\"max_length\":5000,\"min_width\":300,\"placeholder\":\"Enter your OpenAI API Key here...\",\"width\":300},\"id\":\"1009\",\"type\":\"PasswordInput\"},{\"attributes\":{\"active\":0,\"labels\":[\"stuff\",\"map_reduce\",\"refine\",\"map_rerank\"],\"margin\":[5,10,5,10],\"sizing_mode\":\"stretch_width\"},\"id\":\"1023\",\"type\":\"RadioButtonGroup\"},{\"attributes\":{\"children\":[{\"id\":\"1008\"},{\"id\":\"1009\"}],\"margin\":[0,0,0,0],\"name\":\"Row00152\",\"sizing_mode\":\"stretch_width\"},\"id\":\"1007\",\"type\":\"Row\"},{\"attributes\":{\"height\":160,\"margin\":[5,10,5,10],\"name\":\"\",\"placeholder\":\"Enter your questions here...\",\"sizing_mode\":\"stretch_width\",\"toolbar\":false},\"id\":\"1016\",\"type\":\"panel.models.quill.QuillInput\"},{\"attributes\":{\"active_header_background\":\"\",\"button_css_classes\":[\"card-button\"],\"children\":[{\"id\":\"1019\"},{\"id\":\"1021\"}],\"collapsed\":false,\"css_classes\":[\"card\"],\"header_background\":\"\",\"header_color\":\"\",\"header_css_classes\":[\"card-header\"],\"margin\":[10,10,10,10],\"name\":\"Card00132\",\"sizing_mode\":\"stretch_width\"},\"id\":\"1018\",\"type\":\"panel.models.layout.Card\"},{\"attributes\":{\"css_classes\":[\"markdown\"],\"margin\":[5,5,5,5],\"name\":\"Markdown00128\",\"sizing_mode\":\"stretch_width\",\"text\":\"<p>Chain type:</p>\"},\"id\":\"1022\",\"type\":\"panel.models.markup.HTML\"},{\"attributes\":{\"margin\":[15,15,15,15],\"min_height\":400,\"min_width\":575,\"name\":\"Column00145\",\"width\":575},\"id\":\"1013\",\"type\":\"Column\"}],\"root_ids\":[\"1005\",\"1026\"]},\"title\":\"Bokeh Application\",\"version\":\"2.4.3\"}};\n",
|
326 |
-
" var render_items = [{\"docid\":\"d0252f16-7a5e-460a-82c3-6b7db2f9af2a\",\"root_ids\":[\"1005\"],\"roots\":{\"1005\":\"c2b6d391-2418-4059-a838-b20218c1be11\"}}];\n",
|
327 |
-
" root.Bokeh.embed.embed_items_notebook(docs_json, render_items);\n",
|
328 |
-
" for (const render_item of render_items) {\n",
|
329 |
-
" for (const root_id of render_item.root_ids) {\n",
|
330 |
-
"\tconst id_el = document.getElementById(root_id)\n",
|
331 |
-
"\tif (id_el.children.length && (id_el.children[0].className === 'bk-root')) {\n",
|
332 |
-
"\t const root_el = id_el.children[0]\n",
|
333 |
-
"\t root_el.id = root_el.id + '-rendered'\n",
|
334 |
-
"\t}\n",
|
335 |
-
" }\n",
|
336 |
-
" }\n",
|
337 |
-
" }\n",
|
338 |
-
" if (root.Bokeh !== undefined && root.Bokeh.Panel !== undefined) {\n",
|
339 |
-
" embed_document(root);\n",
|
340 |
-
" } else {\n",
|
341 |
-
" var attempts = 0;\n",
|
342 |
-
" var timer = setInterval(function(root) {\n",
|
343 |
-
" if (root.Bokeh !== undefined && root.Bokeh.Panel !== undefined) {\n",
|
344 |
-
" clearInterval(timer);\n",
|
345 |
-
" embed_document(root);\n",
|
346 |
-
" } else if (document.readyState == \"complete\") {\n",
|
347 |
-
" attempts++;\n",
|
348 |
-
" if (attempts > 200) {\n",
|
349 |
-
" clearInterval(timer);\n",
|
350 |
-
" console.log(\"Bokeh: ERROR: Unable to run BokehJS code because BokehJS library is missing\");\n",
|
351 |
-
" }\n",
|
352 |
-
" }\n",
|
353 |
-
" }, 25, root)\n",
|
354 |
-
" }\n",
|
355 |
-
"})(window);</script>"
|
356 |
-
],
|
357 |
-
"text/plain": [
|
358 |
-
"Column(sizing_mode='stretch_width')\n",
|
359 |
-
" [0] Markdown(str, sizing_mode='stretch_width')\n",
|
360 |
-
" [1] Row(sizing_mode='stretch_width')\n",
|
361 |
-
" [0] FileInput(width=300)\n",
|
362 |
-
" [1] PasswordInput(placeholder='Enter your OpenAI A..., width=300)\n",
|
363 |
-
" [2] WidgetBox(scroll=True, width=630)\n",
|
364 |
-
" [0] Markdown(str, sizing_mode='stretch_width')\n",
|
365 |
-
" [1] ParamFunction(function, _pane=Column, loading_indicator=True, sizing_mode='stretch_width')\n",
|
366 |
-
" [3] Row(width=600)\n",
|
367 |
-
" [0] Column(margin=5, sizing_mode='stretch_width')\n",
|
368 |
-
" [0] TextEditor(height=160, placeholder='Enter your questions h..., sizing_mode='stretch_width', toolbar=False)\n",
|
369 |
-
" [1] Button(name='Run!', sizing_mode='stretch_width')\n",
|
370 |
-
" [1] Card(margin=10, sizing_mode='stretch_width', title='Advanced settings')\n",
|
371 |
-
" [0] Column(sizing_mode='stretch_width')\n",
|
372 |
-
" [0] Markdown(str, sizing_mode='stretch_width')\n",
|
373 |
-
" [1] RadioButtonGroup(name='Chain type', options=['stuff', 'map_reduce', ...], sizing_mode='stretch_width', value='stuff')\n",
|
374 |
-
" [2] IntSlider(end=5, name='Number of relevant c..., sizing_mode='stretch_width', start=1, value=2)"
|
375 |
-
]
|
376 |
-
},
|
377 |
-
"execution_count": 9,
|
378 |
-
"metadata": {
|
379 |
-
"application/vnd.holoviews_exec.v0+json": {
|
380 |
-
"id": "1005"
|
381 |
-
}
|
382 |
-
},
|
383 |
-
"output_type": "execute_result"
|
384 |
-
}
|
385 |
-
],
|
386 |
-
"source": [
|
387 |
-
"# layout\n",
|
388 |
-
"pn.Column(\n",
|
389 |
-
" pn.pane.Markdown(\"\"\"\n",
|
390 |
-
" ## \\U0001F60A! Question Answering with your PDF file\n",
|
391 |
-
" \n",
|
392 |
-
" 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",
|
393 |
-
" \n",
|
394 |
-
" \"\"\"),\n",
|
395 |
-
" pn.Row(file_input,openaikey),\n",
|
396 |
-
" output,\n",
|
397 |
-
" widgets\n",
|
398 |
-
"\n",
|
399 |
-
").servable()"
|
400 |
-
]
|
401 |
-
}
|
402 |
-
],
|
403 |
-
"metadata": {
|
404 |
-
"kernelspec": {
|
405 |
-
"display_name": "Python 3 (ipykernel)",
|
406 |
-
"language": "python",
|
407 |
-
"name": "python3"
|
408 |
-
},
|
409 |
-
"language_info": {
|
410 |
-
"codemirror_mode": {
|
411 |
-
"name": "ipython",
|
412 |
-
"version": 3
|
413 |
-
},
|
414 |
-
"file_extension": ".py",
|
415 |
-
"mimetype": "text/x-python",
|
416 |
-
"name": "python",
|
417 |
-
"nbconvert_exporter": "python",
|
418 |
-
"pygments_lexer": "ipython3",
|
419 |
-
"version": "3.10.10"
|
420 |
-
}
|
421 |
-
},
|
422 |
-
"nbformat": 4,
|
423 |
-
"nbformat_minor": 5
|
424 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|