Spaces:
Runtime error
Runtime error
commit
Browse files- .gitignore +1 -0
- Career_Chatbot.egg-info/PKG-INFO +5 -0
- Career_Chatbot.egg-info/SOURCES.txt +8 -0
- Career_Chatbot.egg-info/dependency_links.txt +1 -0
- Career_Chatbot.egg-info/top_level.txt +1 -0
- Dockerfile +17 -0
- Medical_Chatbot.egg-info/PKG-INFO +5 -0
- Medical_Chatbot.egg-info/SOURCES.txt +8 -0
- Medical_Chatbot.egg-info/dependency_links.txt +1 -0
- Medical_Chatbot.egg-info/top_level.txt +1 -0
- __pycache__/helper.cpython-38.pyc +0 -0
- app.py +66 -0
- medical-chatbot/trials.ipynb +405 -0
- requirements.txt +13 -0
- research/trials.ipynb +1164 -0
- setup.py +11 -0
- src/__init__.py +0 -0
- src/__pycache__/__init__.cpython-38.pyc +0 -0
- src/__pycache__/helper.cpython-38.pyc +0 -0
- src/__pycache__/prompt.cpython-38.pyc +0 -0
- src/helper.py +30 -0
- src/prompt.py +10 -0
- static/.gitkeep +0 -0
- static/style.css +223 -0
- store_index.py +28 -0
- template.py +33 -0
- templates/chat.html +82 -0
.gitignore
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
.env
|
Career_Chatbot.egg-info/PKG-INFO
ADDED
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
Metadata-Version: 2.1
|
2 |
+
Name: Career-Chatbot
|
3 |
+
Version: 0.0.0
|
4 |
+
Author: Shirlyn and Earvin
|
5 |
+
Author-email: shirlynngure@gmail.com
|
Career_Chatbot.egg-info/SOURCES.txt
ADDED
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
setup.py
|
2 |
+
Career_Chatbot.egg-info/PKG-INFO
|
3 |
+
Career_Chatbot.egg-info/SOURCES.txt
|
4 |
+
Career_Chatbot.egg-info/dependency_links.txt
|
5 |
+
Career_Chatbot.egg-info/top_level.txt
|
6 |
+
src/__init__.py
|
7 |
+
src/helper.py
|
8 |
+
src/prompt.py
|
Career_Chatbot.egg-info/dependency_links.txt
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
|
Career_Chatbot.egg-info/top_level.txt
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
src
|
Dockerfile
ADDED
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
FROM python:3.9
|
2 |
+
|
3 |
+
RUN useradd -m -u 1000 user
|
4 |
+
|
5 |
+
WORKDIR /app
|
6 |
+
|
7 |
+
COPY --chown=user ./requirements.txt requirements.txt
|
8 |
+
|
9 |
+
RUN pip install -r requirements.txt
|
10 |
+
|
11 |
+
RUN pip install --upgrade sentence_transformers
|
12 |
+
|
13 |
+
RUN pip install --upgrade langchain
|
14 |
+
|
15 |
+
COPY --chown=user . /app
|
16 |
+
|
17 |
+
CMD ["gunicorn", "app:app","-b","0.0.0.0:7860"]
|
Medical_Chatbot.egg-info/PKG-INFO
ADDED
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
Metadata-Version: 2.1
|
2 |
+
Name: Medical-Chatbot
|
3 |
+
Version: 0.0.0
|
4 |
+
Author: Boktiar Ahmed Bappy
|
5 |
+
Author-email: entbappy73@gmail.com
|
Medical_Chatbot.egg-info/SOURCES.txt
ADDED
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
setup.py
|
2 |
+
Medical_Chatbot.egg-info/PKG-INFO
|
3 |
+
Medical_Chatbot.egg-info/SOURCES.txt
|
4 |
+
Medical_Chatbot.egg-info/dependency_links.txt
|
5 |
+
Medical_Chatbot.egg-info/top_level.txt
|
6 |
+
src/__init__.py
|
7 |
+
src/helper.py
|
8 |
+
src/prompt.py
|
Medical_Chatbot.egg-info/dependency_links.txt
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
|
Medical_Chatbot.egg-info/top_level.txt
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
src
|
__pycache__/helper.cpython-38.pyc
ADDED
Binary file (1.13 kB). View file
|
|
app.py
ADDED
@@ -0,0 +1,66 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from flask import Flask, render_template, jsonify, request
|
2 |
+
from src.helper import download_hugging_face_embeddings
|
3 |
+
from langchain.vectorstores import Pinecone
|
4 |
+
import pinecone
|
5 |
+
from langchain.prompts import PromptTemplate
|
6 |
+
from langchain.llms import CTransformers
|
7 |
+
from langchain.chains import RetrievalQA
|
8 |
+
from dotenv import load_dotenv
|
9 |
+
from src.prompt import *
|
10 |
+
import os
|
11 |
+
from pinecone import Pinecone
|
12 |
+
from langchain_pinecone import PineconeVectorStore
|
13 |
+
from langchain.llms import Replicate
|
14 |
+
app = Flask(__name__)
|
15 |
+
|
16 |
+
load_dotenv()
|
17 |
+
|
18 |
+
PINECONE_API_KEY = os.environ.get('PINECONE_API_KEY')
|
19 |
+
PINECONE_API_ENV = os.environ.get('PINECONE_API_ENV')
|
20 |
+
|
21 |
+
|
22 |
+
embeddings = download_hugging_face_embeddings()
|
23 |
+
|
24 |
+
#Initializing the Pinecone
|
25 |
+
index_name="clare"
|
26 |
+
pc=Pinecone(api_key=PINECONE_API_KEY)
|
27 |
+
index=pc.Index("clare")
|
28 |
+
|
29 |
+
#Loading the index
|
30 |
+
docsearch = PineconeVectorStore.from_existing_index(index_name, embeddings)
|
31 |
+
|
32 |
+
|
33 |
+
PROMPT=PromptTemplate(template=prompt_template, input_variables=["context", "question"])
|
34 |
+
|
35 |
+
chain_type_kwargs={"prompt": PROMPT}
|
36 |
+
|
37 |
+
llm=Replicate(model="meta/meta-llama-3-8b")
|
38 |
+
|
39 |
+
qa=RetrievalQA.from_chain_type(
|
40 |
+
llm=llm,
|
41 |
+
chain_type="stuff",
|
42 |
+
retriever=docsearch.as_retriever(search_kwargs={'k': 2}),
|
43 |
+
return_source_documents=True,
|
44 |
+
chain_type_kwargs=chain_type_kwargs)
|
45 |
+
|
46 |
+
|
47 |
+
|
48 |
+
@app.route("/")
|
49 |
+
def index():
|
50 |
+
return render_template('chat.html')
|
51 |
+
|
52 |
+
|
53 |
+
|
54 |
+
@app.route("/get", methods=["GET", "POST"])
|
55 |
+
def chat():
|
56 |
+
msg = request.form["msg"]
|
57 |
+
input = msg
|
58 |
+
print(input)
|
59 |
+
result=qa({"query": input})
|
60 |
+
print("Response : ", result["result"])
|
61 |
+
return str(result["result"])
|
62 |
+
|
63 |
+
|
64 |
+
|
65 |
+
if __name__ == '__main__':
|
66 |
+
app.run(host="0.0.0.0", port= 8080, debug= True)
|
medical-chatbot/trials.ipynb
ADDED
@@ -0,0 +1,405 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"cells": [
|
3 |
+
{
|
4 |
+
"cell_type": "code",
|
5 |
+
"execution_count": 4,
|
6 |
+
"metadata": {},
|
7 |
+
"outputs": [
|
8 |
+
{
|
9 |
+
"name": "stderr",
|
10 |
+
"output_type": "stream",
|
11 |
+
"text": [
|
12 |
+
"c:\\Users\\Admin\\AppData\\Local\\conda\\conda\\envs\\med\\lib\\site-packages\\pinecone\\data\\index.py:1: TqdmWarning: IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html\n",
|
13 |
+
" from tqdm.autonotebook import tqdm\n"
|
14 |
+
]
|
15 |
+
}
|
16 |
+
],
|
17 |
+
"source": [
|
18 |
+
"from langchain import PromptTemplate\n",
|
19 |
+
"from langchain.chains import RetrievalQA\n",
|
20 |
+
"from langchain.embeddings import HuggingFaceEmbeddings\n",
|
21 |
+
"import pinecone\n",
|
22 |
+
"from langchain.vectorstores import pinecone\n",
|
23 |
+
"from langchain.document_loaders import PyPDFLoader, DirectoryLoader\n",
|
24 |
+
"from langchain.prompts import PromptTemplate\n",
|
25 |
+
"from langchain.llms import CTransformers\n",
|
26 |
+
"from langchain.text_splitter import RecursiveCharacterTextSplitter\n",
|
27 |
+
"from tqdm.autonotebook import tqdm"
|
28 |
+
]
|
29 |
+
},
|
30 |
+
{
|
31 |
+
"cell_type": "code",
|
32 |
+
"execution_count": 7,
|
33 |
+
"metadata": {},
|
34 |
+
"outputs": [
|
35 |
+
{
|
36 |
+
"name": "stdout",
|
37 |
+
"output_type": "stream",
|
38 |
+
"text": [
|
39 |
+
"Name: langchain\n",
|
40 |
+
"Version: 0.0.225\n",
|
41 |
+
"Summary: Building applications with LLMs through composability\n",
|
42 |
+
"Home-page: https://www.github.com/hwchase17/langchain\n",
|
43 |
+
"Author: \n",
|
44 |
+
"Author-email: \n",
|
45 |
+
"License: MIT\n",
|
46 |
+
"Location: c:\\users\\admin\\appdata\\local\\conda\\conda\\envs\\med\\lib\\site-packages\n",
|
47 |
+
"Requires: aiohttp, async-timeout, dataclasses-json, langchainplus-sdk, numexpr, numpy, openapi-schema-pydantic, pydantic, PyYAML, requests, SQLAlchemy, tenacity\n",
|
48 |
+
"Required-by: langchain-community\n",
|
49 |
+
"Note: you may need to restart the kernel to use updated packages.\n"
|
50 |
+
]
|
51 |
+
}
|
52 |
+
],
|
53 |
+
"source": [
|
54 |
+
"pip show langchain"
|
55 |
+
]
|
56 |
+
},
|
57 |
+
{
|
58 |
+
"cell_type": "code",
|
59 |
+
"execution_count": 5,
|
60 |
+
"metadata": {},
|
61 |
+
"outputs": [],
|
62 |
+
"source": [
|
63 |
+
"PINECONE_API_KEY = \"4b6b83c2-dc68-4bad-ae31-9642bc3be58e\"\n",
|
64 |
+
"PINECONE_API_ENV = \"us-east-1\""
|
65 |
+
]
|
66 |
+
},
|
67 |
+
{
|
68 |
+
"cell_type": "code",
|
69 |
+
"execution_count": 8,
|
70 |
+
"metadata": {},
|
71 |
+
"outputs": [],
|
72 |
+
"source": [
|
73 |
+
"# Extract the data from the pdf book\n",
|
74 |
+
"def load_data(data):\n",
|
75 |
+
" loader = DirectoryLoader(data,\n",
|
76 |
+
" glob=\"*.pdf\",\n",
|
77 |
+
" loader_cls=PyPDFLoader)\n",
|
78 |
+
"\n",
|
79 |
+
" documents = loader.load()\n",
|
80 |
+
" return documents\n",
|
81 |
+
" "
|
82 |
+
]
|
83 |
+
},
|
84 |
+
{
|
85 |
+
"cell_type": "code",
|
86 |
+
"execution_count": 41,
|
87 |
+
"metadata": {},
|
88 |
+
"outputs": [
|
89 |
+
{
|
90 |
+
"name": "stdout",
|
91 |
+
"output_type": "stream",
|
92 |
+
"text": [
|
93 |
+
"Requirement already satisfied: pyPDF in c:\\users\\admin\\appdata\\local\\conda\\conda\\envs\\med\\lib\\site-packages (4.2.0)\n",
|
94 |
+
"Requirement already satisfied: typing_extensions>=4.0 in c:\\users\\admin\\appdata\\local\\conda\\conda\\envs\\med\\lib\\site-packages (from pyPDF) (4.11.0)\n",
|
95 |
+
"Note: you may need to restart the kernel to use updated packages.\n"
|
96 |
+
]
|
97 |
+
}
|
98 |
+
],
|
99 |
+
"source": [
|
100 |
+
"pip install pyPDF"
|
101 |
+
]
|
102 |
+
},
|
103 |
+
{
|
104 |
+
"cell_type": "code",
|
105 |
+
"execution_count": 9,
|
106 |
+
"metadata": {},
|
107 |
+
"outputs": [
|
108 |
+
{
|
109 |
+
"name": "stdout",
|
110 |
+
"output_type": "stream",
|
111 |
+
"text": [
|
112 |
+
"Name: pypdf\n",
|
113 |
+
"Version: 4.2.0\n",
|
114 |
+
"Summary: A pure-python PDF library capable of splitting, merging, cropping, and transforming PDF files\n",
|
115 |
+
"Home-page: \n",
|
116 |
+
"Author: \n",
|
117 |
+
"Author-email: Mathieu Fenniak <biziqe@mathieu.fenniak.net>\n",
|
118 |
+
"License: \n",
|
119 |
+
"Location: c:\\users\\admin\\appdata\\local\\conda\\conda\\envs\\med\\lib\\site-packages\n",
|
120 |
+
"Requires: typing_extensions\n",
|
121 |
+
"Required-by: \n",
|
122 |
+
"Note: you may need to restart the kernel to use updated packages.\n"
|
123 |
+
]
|
124 |
+
}
|
125 |
+
],
|
126 |
+
"source": [
|
127 |
+
"pip show pyPDF"
|
128 |
+
]
|
129 |
+
},
|
130 |
+
{
|
131 |
+
"cell_type": "code",
|
132 |
+
"execution_count": 10,
|
133 |
+
"metadata": {},
|
134 |
+
"outputs": [
|
135 |
+
{
|
136 |
+
"name": "stdout",
|
137 |
+
"output_type": "stream",
|
138 |
+
"text": [
|
139 |
+
"Data Extracted\n"
|
140 |
+
]
|
141 |
+
}
|
142 |
+
],
|
143 |
+
"source": [
|
144 |
+
"extracted_pdf = load_data(\"data/\")\n",
|
145 |
+
"print(\"Data Extracted\")"
|
146 |
+
]
|
147 |
+
},
|
148 |
+
{
|
149 |
+
"cell_type": "code",
|
150 |
+
"execution_count": 11,
|
151 |
+
"metadata": {},
|
152 |
+
"outputs": [],
|
153 |
+
"source": [
|
154 |
+
"#extracted_data"
|
155 |
+
]
|
156 |
+
},
|
157 |
+
{
|
158 |
+
"cell_type": "code",
|
159 |
+
"execution_count": 12,
|
160 |
+
"metadata": {},
|
161 |
+
"outputs": [],
|
162 |
+
"source": [
|
163 |
+
"#create text Chunks\n",
|
164 |
+
"def text_split(extracted_pdf):\n",
|
165 |
+
" text_splitter = RecursiveCharacterTextSplitter(chunk_size=500,\n",
|
166 |
+
" chunk_overlap=20)\n",
|
167 |
+
" text_chunks=text_splitter.split_documents(extracted_pdf)\n",
|
168 |
+
" return text_chunks "
|
169 |
+
]
|
170 |
+
},
|
171 |
+
{
|
172 |
+
"cell_type": "code",
|
173 |
+
"execution_count": 13,
|
174 |
+
"metadata": {},
|
175 |
+
"outputs": [
|
176 |
+
{
|
177 |
+
"name": "stdout",
|
178 |
+
"output_type": "stream",
|
179 |
+
"text": [
|
180 |
+
"chunks created\n",
|
181 |
+
"The number of chunks is: 10484\n"
|
182 |
+
]
|
183 |
+
}
|
184 |
+
],
|
185 |
+
"source": [
|
186 |
+
"text_chunks = text_split(extracted_pdf)\n",
|
187 |
+
"print(\"chunks created\")\n",
|
188 |
+
"print(\"The number of chunks is:\",len(text_chunks))"
|
189 |
+
]
|
190 |
+
},
|
191 |
+
{
|
192 |
+
"cell_type": "code",
|
193 |
+
"execution_count": 14,
|
194 |
+
"metadata": {},
|
195 |
+
"outputs": [],
|
196 |
+
"source": [
|
197 |
+
"#download embedding model\n",
|
198 |
+
"def download_huggingfaceembedding():\n",
|
199 |
+
" embedding = HuggingFaceEmbeddings(model_name=\"TheBloke/Llama-2-7B-Chat-GGML\")\n",
|
200 |
+
" return embedding"
|
201 |
+
]
|
202 |
+
},
|
203 |
+
{
|
204 |
+
"cell_type": "code",
|
205 |
+
"execution_count": 17,
|
206 |
+
"metadata": {},
|
207 |
+
"outputs": [
|
208 |
+
{
|
209 |
+
"ename": "KeyboardInterrupt",
|
210 |
+
"evalue": "",
|
211 |
+
"output_type": "error",
|
212 |
+
"traceback": [
|
213 |
+
"\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
|
214 |
+
"\u001b[1;31mKeyboardInterrupt\u001b[0m Traceback (most recent call last)",
|
215 |
+
"Cell \u001b[1;32mIn[17], line 1\u001b[0m\n\u001b[1;32m----> 1\u001b[0m embedding \u001b[38;5;241m=\u001b[39m \u001b[43mdownload_huggingfaceembedding\u001b[49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m\n",
|
216 |
+
"Cell \u001b[1;32mIn[14], line 3\u001b[0m, in \u001b[0;36mdownload_huggingfaceembedding\u001b[1;34m()\u001b[0m\n\u001b[0;32m 2\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21mdownload_huggingfaceembedding\u001b[39m():\n\u001b[1;32m----> 3\u001b[0m embedding \u001b[38;5;241m=\u001b[39m \u001b[43mHuggingFaceEmbeddings\u001b[49m\u001b[43m(\u001b[49m\u001b[43mmodel_name\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mTheBloke/Llama-2-7B-Chat-GGML\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m)\u001b[49m\n\u001b[0;32m 4\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m embedding\n",
|
217 |
+
"File \u001b[1;32mc:\\Users\\Admin\\AppData\\Local\\conda\\conda\\envs\\med\\lib\\site-packages\\langchain\\embeddings\\huggingface.py:59\u001b[0m, in \u001b[0;36mHuggingFaceEmbeddings.__init__\u001b[1;34m(self, **kwargs)\u001b[0m\n\u001b[0;32m 53\u001b[0m \u001b[38;5;28;01mexcept\u001b[39;00m \u001b[38;5;167;01mImportError\u001b[39;00m \u001b[38;5;28;01mas\u001b[39;00m exc:\n\u001b[0;32m 54\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m \u001b[38;5;167;01mImportError\u001b[39;00m(\n\u001b[0;32m 55\u001b[0m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mCould not import sentence_transformers python package. \u001b[39m\u001b[38;5;124m\"\u001b[39m\n\u001b[0;32m 56\u001b[0m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mPlease install it with `pip install sentence_transformers`.\u001b[39m\u001b[38;5;124m\"\u001b[39m\n\u001b[0;32m 57\u001b[0m ) \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01mexc\u001b[39;00m\n\u001b[1;32m---> 59\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mclient \u001b[38;5;241m=\u001b[39m \u001b[43msentence_transformers\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mSentenceTransformer\u001b[49m\u001b[43m(\u001b[49m\n\u001b[0;32m 60\u001b[0m \u001b[43m \u001b[49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mmodel_name\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mcache_folder\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mcache_folder\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mmodel_kwargs\u001b[49m\n\u001b[0;32m 61\u001b[0m \u001b[43m\u001b[49m\u001b[43m)\u001b[49m\n",
|
218 |
+
"File \u001b[1;32mc:\\Users\\Admin\\AppData\\Local\\conda\\conda\\envs\\med\\lib\\site-packages\\sentence_transformers\\SentenceTransformer.py:87\u001b[0m, in \u001b[0;36mSentenceTransformer.__init__\u001b[1;34m(self, model_name_or_path, modules, device, cache_folder, use_auth_token)\u001b[0m\n\u001b[0;32m 83\u001b[0m model_path \u001b[38;5;241m=\u001b[39m os\u001b[38;5;241m.\u001b[39mpath\u001b[38;5;241m.\u001b[39mjoin(cache_folder, model_name_or_path\u001b[38;5;241m.\u001b[39mreplace(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m/\u001b[39m\u001b[38;5;124m\"\u001b[39m, \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m_\u001b[39m\u001b[38;5;124m\"\u001b[39m))\n\u001b[0;32m 85\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;129;01mnot\u001b[39;00m os\u001b[38;5;241m.\u001b[39mpath\u001b[38;5;241m.\u001b[39mexists(os\u001b[38;5;241m.\u001b[39mpath\u001b[38;5;241m.\u001b[39mjoin(model_path, \u001b[38;5;124m'\u001b[39m\u001b[38;5;124mmodules.json\u001b[39m\u001b[38;5;124m'\u001b[39m)):\n\u001b[0;32m 86\u001b[0m \u001b[38;5;66;03m# Download from hub with caching\u001b[39;00m\n\u001b[1;32m---> 87\u001b[0m \u001b[43msnapshot_download\u001b[49m\u001b[43m(\u001b[49m\u001b[43mmodel_name_or_path\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m 88\u001b[0m \u001b[43m \u001b[49m\u001b[43mcache_dir\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mcache_folder\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m 89\u001b[0m \u001b[43m \u001b[49m\u001b[43mlibrary_name\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[38;5;124;43msentence-transformers\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[43m,\u001b[49m\n\u001b[0;32m 90\u001b[0m \u001b[43m \u001b[49m\u001b[43mlibrary_version\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43m__version__\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m 91\u001b[0m \u001b[43m \u001b[49m\u001b[43mignore_files\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43m[\u001b[49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[38;5;124;43mflax_model.msgpack\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[38;5;124;43mrust_model.ot\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[38;5;124;43mtf_model.h5\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[43m]\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m 92\u001b[0m \u001b[43m \u001b[49m\u001b[43muse_auth_token\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43muse_auth_token\u001b[49m\u001b[43m)\u001b[49m\n\u001b[0;32m 94\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m os\u001b[38;5;241m.\u001b[39mpath\u001b[38;5;241m.\u001b[39mexists(os\u001b[38;5;241m.\u001b[39mpath\u001b[38;5;241m.\u001b[39mjoin(model_path, \u001b[38;5;124m'\u001b[39m\u001b[38;5;124mmodules.json\u001b[39m\u001b[38;5;124m'\u001b[39m)): \u001b[38;5;66;03m#Load as SentenceTransformer model\u001b[39;00m\n\u001b[0;32m 95\u001b[0m modules \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_load_sbert_model(model_path)\n",
|
219 |
+
"File \u001b[1;32mc:\\Users\\Admin\\AppData\\Local\\conda\\conda\\envs\\med\\lib\\site-packages\\sentence_transformers\\util.py:491\u001b[0m, in \u001b[0;36msnapshot_download\u001b[1;34m(repo_id, revision, cache_dir, library_name, library_version, user_agent, ignore_files, use_auth_token)\u001b[0m\n\u001b[0;32m 486\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m version\u001b[38;5;241m.\u001b[39mparse(huggingface_hub\u001b[38;5;241m.\u001b[39m__version__) \u001b[38;5;241m>\u001b[39m\u001b[38;5;241m=\u001b[39m version\u001b[38;5;241m.\u001b[39mparse(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m0.8.1\u001b[39m\u001b[38;5;124m\"\u001b[39m):\n\u001b[0;32m 487\u001b[0m \u001b[38;5;66;03m# huggingface_hub v0.8.1 introduces a new cache layout. We sill use a manual layout\u001b[39;00m\n\u001b[0;32m 488\u001b[0m \u001b[38;5;66;03m# And need to pass legacy_cache_layout=True to avoid that a warning will be printed\u001b[39;00m\n\u001b[0;32m 489\u001b[0m cached_download_args[\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mlegacy_cache_layout\u001b[39m\u001b[38;5;124m'\u001b[39m] \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;01mTrue\u001b[39;00m\n\u001b[1;32m--> 491\u001b[0m path \u001b[38;5;241m=\u001b[39m \u001b[43mcached_download\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43mcached_download_args\u001b[49m\u001b[43m)\u001b[49m\n\u001b[0;32m 493\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m os\u001b[38;5;241m.\u001b[39mpath\u001b[38;5;241m.\u001b[39mexists(path \u001b[38;5;241m+\u001b[39m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m.lock\u001b[39m\u001b[38;5;124m\"\u001b[39m):\n\u001b[0;32m 494\u001b[0m os\u001b[38;5;241m.\u001b[39mremove(path \u001b[38;5;241m+\u001b[39m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m.lock\u001b[39m\u001b[38;5;124m\"\u001b[39m)\n",
|
220 |
+
"File \u001b[1;32mc:\\Users\\Admin\\AppData\\Local\\conda\\conda\\envs\\med\\lib\\site-packages\\huggingface_hub\\utils\\_validators.py:114\u001b[0m, in \u001b[0;36mvalidate_hf_hub_args.<locals>._inner_fn\u001b[1;34m(*args, **kwargs)\u001b[0m\n\u001b[0;32m 111\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m check_use_auth_token:\n\u001b[0;32m 112\u001b[0m kwargs \u001b[38;5;241m=\u001b[39m smoothly_deprecate_use_auth_token(fn_name\u001b[38;5;241m=\u001b[39mfn\u001b[38;5;241m.\u001b[39m\u001b[38;5;18m__name__\u001b[39m, has_token\u001b[38;5;241m=\u001b[39mhas_token, kwargs\u001b[38;5;241m=\u001b[39mkwargs)\n\u001b[1;32m--> 114\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[43mfn\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43margs\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43mkwargs\u001b[49m\u001b[43m)\u001b[49m\n",
|
221 |
+
"File \u001b[1;32mc:\\Users\\Admin\\AppData\\Local\\conda\\conda\\envs\\med\\lib\\site-packages\\huggingface_hub\\file_download.py:797\u001b[0m, in \u001b[0;36mcached_download\u001b[1;34m(url, library_name, library_version, cache_dir, user_agent, force_download, force_filename, proxies, etag_timeout, resume_download, token, local_files_only, legacy_cache_layout)\u001b[0m\n\u001b[0;32m 794\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m os\u001b[38;5;241m.\u001b[39mname \u001b[38;5;241m==\u001b[39m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mnt\u001b[39m\u001b[38;5;124m\"\u001b[39m \u001b[38;5;129;01mand\u001b[39;00m \u001b[38;5;28mlen\u001b[39m(os\u001b[38;5;241m.\u001b[39mpath\u001b[38;5;241m.\u001b[39mabspath(cache_path)) \u001b[38;5;241m>\u001b[39m \u001b[38;5;241m255\u001b[39m:\n\u001b[0;32m 795\u001b[0m cache_path \u001b[38;5;241m=\u001b[39m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;130;01m\\\\\u001b[39;00m\u001b[38;5;130;01m\\\\\u001b[39;00m\u001b[38;5;124m?\u001b[39m\u001b[38;5;130;01m\\\\\u001b[39;00m\u001b[38;5;124m\"\u001b[39m \u001b[38;5;241m+\u001b[39m os\u001b[38;5;241m.\u001b[39mpath\u001b[38;5;241m.\u001b[39mabspath(cache_path)\n\u001b[1;32m--> 797\u001b[0m \u001b[38;5;28;01mwith\u001b[39;00m WeakFileLock(lock_path):\n\u001b[0;32m 798\u001b[0m _download_to_tmp_and_move(\n\u001b[0;32m 799\u001b[0m incomplete_path\u001b[38;5;241m=\u001b[39mPath(cache_path \u001b[38;5;241m+\u001b[39m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m.incomplete\u001b[39m\u001b[38;5;124m\"\u001b[39m),\n\u001b[0;32m 800\u001b[0m destination_path\u001b[38;5;241m=\u001b[39mPath(cache_path),\n\u001b[1;32m (...)\u001b[0m\n\u001b[0;32m 806\u001b[0m force_download\u001b[38;5;241m=\u001b[39mforce_download,\n\u001b[0;32m 807\u001b[0m )\n\u001b[0;32m 809\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m force_filename \u001b[38;5;129;01mis\u001b[39;00m \u001b[38;5;28;01mNone\u001b[39;00m:\n",
|
222 |
+
"File \u001b[1;32mc:\\Users\\Admin\\AppData\\Local\\conda\\conda\\envs\\med\\lib\\contextlib.py:113\u001b[0m, in \u001b[0;36m_GeneratorContextManager.__enter__\u001b[1;34m(self)\u001b[0m\n\u001b[0;32m 111\u001b[0m \u001b[38;5;28;01mdel\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39margs, \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mkwds, \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mfunc\n\u001b[0;32m 112\u001b[0m \u001b[38;5;28;01mtry\u001b[39;00m:\n\u001b[1;32m--> 113\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28;43mnext\u001b[39;49m\u001b[43m(\u001b[49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mgen\u001b[49m\u001b[43m)\u001b[49m\n\u001b[0;32m 114\u001b[0m \u001b[38;5;28;01mexcept\u001b[39;00m \u001b[38;5;167;01mStopIteration\u001b[39;00m:\n\u001b[0;32m 115\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m \u001b[38;5;167;01mRuntimeError\u001b[39;00m(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mgenerator didn\u001b[39m\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mt yield\u001b[39m\u001b[38;5;124m\"\u001b[39m) \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;28;01mNone\u001b[39;00m\n",
|
223 |
+
"File \u001b[1;32mc:\\Users\\Admin\\AppData\\Local\\conda\\conda\\envs\\med\\lib\\site-packages\\huggingface_hub\\utils\\_fixes.py:84\u001b[0m, in \u001b[0;36mWeakFileLock\u001b[1;34m(lock_file)\u001b[0m\n\u001b[0;32m 82\u001b[0m \u001b[38;5;250m\u001b[39m\u001b[38;5;124;03m\"\"\"A filelock that won't raise an exception if release fails.\"\"\"\u001b[39;00m\n\u001b[0;32m 83\u001b[0m lock \u001b[38;5;241m=\u001b[39m FileLock(lock_file)\n\u001b[1;32m---> 84\u001b[0m \u001b[43mlock\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43macquire\u001b[49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m\n\u001b[0;32m 86\u001b[0m \u001b[38;5;28;01myield\u001b[39;00m lock\n\u001b[0;32m 88\u001b[0m \u001b[38;5;28;01mtry\u001b[39;00m:\n",
|
224 |
+
"File \u001b[1;32mc:\\Users\\Admin\\AppData\\Local\\conda\\conda\\envs\\med\\lib\\site-packages\\filelock\\_api.py:333\u001b[0m, in \u001b[0;36mBaseFileLock.acquire\u001b[1;34m(self, timeout, poll_interval, poll_intervall, blocking)\u001b[0m\n\u001b[0;32m 331\u001b[0m msg \u001b[38;5;241m=\u001b[39m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mLock \u001b[39m\u001b[38;5;132;01m%s\u001b[39;00m\u001b[38;5;124m not acquired on \u001b[39m\u001b[38;5;132;01m%s\u001b[39;00m\u001b[38;5;124m, waiting \u001b[39m\u001b[38;5;132;01m%s\u001b[39;00m\u001b[38;5;124m seconds ...\u001b[39m\u001b[38;5;124m\"\u001b[39m\n\u001b[0;32m 332\u001b[0m _LOGGER\u001b[38;5;241m.\u001b[39mdebug(msg, lock_id, lock_filename, poll_interval)\n\u001b[1;32m--> 333\u001b[0m \u001b[43mtime\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43msleep\u001b[49m\u001b[43m(\u001b[49m\u001b[43mpoll_interval\u001b[49m\u001b[43m)\u001b[49m\n\u001b[0;32m 334\u001b[0m \u001b[38;5;28;01mexcept\u001b[39;00m \u001b[38;5;167;01mBaseException\u001b[39;00m: \u001b[38;5;66;03m# Something did go wrong, so decrement the counter.\u001b[39;00m\n\u001b[0;32m 335\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_context\u001b[38;5;241m.\u001b[39mlock_counter \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mmax\u001b[39m(\u001b[38;5;241m0\u001b[39m, \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_context\u001b[38;5;241m.\u001b[39mlock_counter \u001b[38;5;241m-\u001b[39m \u001b[38;5;241m1\u001b[39m)\n",
|
225 |
+
"\u001b[1;31mKeyboardInterrupt\u001b[0m: "
|
226 |
+
]
|
227 |
+
}
|
228 |
+
],
|
229 |
+
"source": [
|
230 |
+
"embedding = download_huggingfaceembedding()"
|
231 |
+
]
|
232 |
+
},
|
233 |
+
{
|
234 |
+
"cell_type": "code",
|
235 |
+
"execution_count": 15,
|
236 |
+
"metadata": {},
|
237 |
+
"outputs": [
|
238 |
+
{
|
239 |
+
"ename": "NameError",
|
240 |
+
"evalue": "name 'embedding' is not defined",
|
241 |
+
"output_type": "error",
|
242 |
+
"traceback": [
|
243 |
+
"\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
|
244 |
+
"\u001b[1;31mNameError\u001b[0m Traceback (most recent call last)",
|
245 |
+
"Cell \u001b[1;32mIn[15], line 1\u001b[0m\n\u001b[1;32m----> 1\u001b[0m \u001b[43membedding\u001b[49m\n",
|
246 |
+
"\u001b[1;31mNameError\u001b[0m: name 'embedding' is not defined"
|
247 |
+
]
|
248 |
+
}
|
249 |
+
],
|
250 |
+
"source": [
|
251 |
+
"embedding"
|
252 |
+
]
|
253 |
+
},
|
254 |
+
{
|
255 |
+
"cell_type": "code",
|
256 |
+
"execution_count": 18,
|
257 |
+
"metadata": {},
|
258 |
+
"outputs": [
|
259 |
+
{
|
260 |
+
"ename": "NameError",
|
261 |
+
"evalue": "name 'embedding' is not defined",
|
262 |
+
"output_type": "error",
|
263 |
+
"traceback": [
|
264 |
+
"\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
|
265 |
+
"\u001b[1;31mNameError\u001b[0m Traceback (most recent call last)",
|
266 |
+
"Cell \u001b[1;32mIn[18], line 1\u001b[0m\n\u001b[1;32m----> 1\u001b[0m query_result \u001b[38;5;241m=\u001b[39m \u001b[43membedding\u001b[49m\u001b[38;5;241m.\u001b[39membed_query(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mHello World!\u001b[39m\u001b[38;5;124m\"\u001b[39m)\n\u001b[0;32m 2\u001b[0m \u001b[38;5;28mprint\u001b[39m(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mLength:\u001b[39m\u001b[38;5;124m\"\u001b[39m, \u001b[38;5;28mlen\u001b[39m(query_result))\n\u001b[0;32m 3\u001b[0m query_result\n",
|
267 |
+
"\u001b[1;31mNameError\u001b[0m: name 'embedding' is not defined"
|
268 |
+
]
|
269 |
+
}
|
270 |
+
],
|
271 |
+
"source": [
|
272 |
+
"query_result = embedding.embed_query(\"Hello World!\")\n",
|
273 |
+
"print(\"Length:\", len(query_result))\n",
|
274 |
+
"query_result"
|
275 |
+
]
|
276 |
+
},
|
277 |
+
{
|
278 |
+
"cell_type": "code",
|
279 |
+
"execution_count": 21,
|
280 |
+
"metadata": {},
|
281 |
+
"outputs": [
|
282 |
+
{
|
283 |
+
"name": "stdout",
|
284 |
+
"output_type": "stream",
|
285 |
+
"text": [
|
286 |
+
"Requirement already satisfied: pinecone.client in c:\\users\\admin\\appdata\\local\\conda\\conda\\envs\\med\\lib\\site-packages (4.1.1)\n",
|
287 |
+
"Requirement already satisfied: certifi>=2019.11.17 in c:\\users\\admin\\appdata\\local\\conda\\conda\\envs\\med\\lib\\site-packages (from pinecone.client) (2024.6.2)\n",
|
288 |
+
"Requirement already satisfied: pinecone-plugin-interface<0.0.8,>=0.0.7 in c:\\users\\admin\\appdata\\local\\conda\\conda\\envs\\med\\lib\\site-packages (from pinecone.client) (0.0.7)\n",
|
289 |
+
"Requirement already satisfied: tqdm>=4.64.1 in c:\\users\\admin\\appdata\\roaming\\python\\python38\\site-packages (from pinecone.client) (4.66.4)\n",
|
290 |
+
"Requirement already satisfied: typing-extensions>=3.7.4 in c:\\users\\admin\\appdata\\local\\conda\\conda\\envs\\med\\lib\\site-packages (from pinecone.client) (4.11.0)\n",
|
291 |
+
"Requirement already satisfied: urllib3>=1.26.0 in c:\\users\\admin\\appdata\\local\\conda\\conda\\envs\\med\\lib\\site-packages (from pinecone.client) (2.2.1)\n",
|
292 |
+
"Requirement already satisfied: colorama in c:\\users\\admin\\appdata\\local\\conda\\conda\\envs\\med\\lib\\site-packages (from tqdm>=4.64.1->pinecone.client) (0.4.6)\n",
|
293 |
+
"Note: you may need to restart the kernel to use updated packages.\n"
|
294 |
+
]
|
295 |
+
}
|
296 |
+
],
|
297 |
+
"source": [
|
298 |
+
"pip install pinecone.client"
|
299 |
+
]
|
300 |
+
},
|
301 |
+
{
|
302 |
+
"cell_type": "code",
|
303 |
+
"execution_count": null,
|
304 |
+
"metadata": {},
|
305 |
+
"outputs": [],
|
306 |
+
"source": [
|
307 |
+
"# After having my index, we can load it like this - \n",
|
308 |
+
"\n",
|
309 |
+
"\n",
|
310 |
+
"query = \"What are Allegies?\"\n",
|
311 |
+
"\n",
|
312 |
+
"docs = docsearch.similarity_search(query=query, k=3)\n",
|
313 |
+
"\n",
|
314 |
+
"print(\"Result:\", docs)"
|
315 |
+
]
|
316 |
+
},
|
317 |
+
{
|
318 |
+
"cell_type": "code",
|
319 |
+
"execution_count": null,
|
320 |
+
"metadata": {},
|
321 |
+
"outputs": [],
|
322 |
+
"source": [
|
323 |
+
"prompt_template = \"\"\"\n",
|
324 |
+
"Use the following piece of information to answer the user's question.\n",
|
325 |
+
"If you don't know the answer, just say that you don't know, don't try to generate any random answer from your own\n",
|
326 |
+
"\n",
|
327 |
+
"Context:{context}\n",
|
328 |
+
"Question:{question}\n",
|
329 |
+
"\n",
|
330 |
+
"Only return the helpful answer and nothing else\n",
|
331 |
+
"helpful answer:\n",
|
332 |
+
"\"\"\""
|
333 |
+
]
|
334 |
+
},
|
335 |
+
{
|
336 |
+
"cell_type": "code",
|
337 |
+
"execution_count": null,
|
338 |
+
"metadata": {},
|
339 |
+
"outputs": [],
|
340 |
+
"source": [
|
341 |
+
"PROMPT = PromptTemplate(template=prompt_template, input_variables=[\"context\",\"question\"])\n",
|
342 |
+
"chain_type_kwargs = {\"prompt\":PROMPT}"
|
343 |
+
]
|
344 |
+
},
|
345 |
+
{
|
346 |
+
"cell_type": "code",
|
347 |
+
"execution_count": null,
|
348 |
+
"metadata": {},
|
349 |
+
"outputs": [],
|
350 |
+
"source": [
|
351 |
+
"llm = CTransformers(model=\"model/llama-2-7b-chat.ggmlv3.q4_0.bin\",\n",
|
352 |
+
" model_type=\"llama\",\n",
|
353 |
+
" config={\"max_new_tokens\":512,\n",
|
354 |
+
" 'temperature':0.8})"
|
355 |
+
]
|
356 |
+
},
|
357 |
+
{
|
358 |
+
"cell_type": "code",
|
359 |
+
"execution_count": null,
|
360 |
+
"metadata": {},
|
361 |
+
"outputs": [],
|
362 |
+
"source": [
|
363 |
+
"qa = RetrievalQA.from_chain_type(\n",
|
364 |
+
" llm=llm,\n",
|
365 |
+
" chain_type=\"stuff\",\n",
|
366 |
+
" retriever= docsearch.as_retriever(search_kwargs={\"k\":2}),\n",
|
367 |
+
" return_source_documents = True,\n",
|
368 |
+
" chain_type_kwargs=chain_type_kwargs)"
|
369 |
+
]
|
370 |
+
},
|
371 |
+
{
|
372 |
+
"cell_type": "code",
|
373 |
+
"execution_count": null,
|
374 |
+
"metadata": {},
|
375 |
+
"outputs": [],
|
376 |
+
"source": [
|
377 |
+
"while True:\n",
|
378 |
+
" user_input = input(f\"Input Prompt: \")\n",
|
379 |
+
" result = qa({\"query\":user_input})\n",
|
380 |
+
" print(\"Response:\", result[\"result\"])"
|
381 |
+
]
|
382 |
+
}
|
383 |
+
],
|
384 |
+
"metadata": {
|
385 |
+
"kernelspec": {
|
386 |
+
"display_name": "medchatbot",
|
387 |
+
"language": "python",
|
388 |
+
"name": "python3"
|
389 |
+
},
|
390 |
+
"language_info": {
|
391 |
+
"codemirror_mode": {
|
392 |
+
"name": "ipython",
|
393 |
+
"version": 3
|
394 |
+
},
|
395 |
+
"file_extension": ".py",
|
396 |
+
"mimetype": "text/x-python",
|
397 |
+
"name": "python",
|
398 |
+
"nbconvert_exporter": "python",
|
399 |
+
"pygments_lexer": "ipython3",
|
400 |
+
"version": "3.8.19"
|
401 |
+
}
|
402 |
+
},
|
403 |
+
"nbformat": 4,
|
404 |
+
"nbformat_minor": 2
|
405 |
+
}
|
requirements.txt
ADDED
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
ctransformers
|
2 |
+
sentence-transformers==2.2.2
|
3 |
+
pinecone-client
|
4 |
+
langchain==0.0.225
|
5 |
+
flask
|
6 |
+
pypdf
|
7 |
+
python-dotenv
|
8 |
+
pinecone
|
9 |
+
langchain_community
|
10 |
+
sentence_transformers
|
11 |
+
langchain_pinecone
|
12 |
+
gunicorn
|
13 |
+
PyPDF2
|
research/trials.ipynb
ADDED
@@ -0,0 +1,1164 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"cells": [
|
3 |
+
{
|
4 |
+
"cell_type": "code",
|
5 |
+
"execution_count": 1,
|
6 |
+
"metadata": {},
|
7 |
+
"outputs": [
|
8 |
+
{
|
9 |
+
"name": "stderr",
|
10 |
+
"output_type": "stream",
|
11 |
+
"text": [
|
12 |
+
"C:\\Users\\Admin\\AppData\\Roaming\\Python\\Python38\\site-packages\\pinecone\\data\\index.py:1: TqdmWarning: IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html\n",
|
13 |
+
" from tqdm.autonotebook import tqdm\n"
|
14 |
+
]
|
15 |
+
}
|
16 |
+
],
|
17 |
+
"source": [
|
18 |
+
"from langchain import PromptTemplate\n",
|
19 |
+
"from langchain.chains import RetrievalQA\n",
|
20 |
+
"from langchain.embeddings import HuggingFaceEmbeddings\n",
|
21 |
+
"from langchain.vectorstores import Pinecone\n",
|
22 |
+
"import pinecone\n",
|
23 |
+
"from langchain.document_loaders import PyPDFLoader, DirectoryLoader\n",
|
24 |
+
"from langchain.text_splitter import RecursiveCharacterTextSplitter\n",
|
25 |
+
"from langchain.prompts import PromptTemplate\n",
|
26 |
+
"from langchain.llms import CTransformers\n",
|
27 |
+
"import os\n",
|
28 |
+
"from langchain.llms import Replicate"
|
29 |
+
]
|
30 |
+
},
|
31 |
+
{
|
32 |
+
"cell_type": "code",
|
33 |
+
"execution_count": 3,
|
34 |
+
"metadata": {},
|
35 |
+
"outputs": [],
|
36 |
+
"source": [
|
37 |
+
"#Extract data from the PDF\n",
|
38 |
+
"def load_pdf(data):\n",
|
39 |
+
" loader = DirectoryLoader(data,\n",
|
40 |
+
" glob=\"*.pdf\",\n",
|
41 |
+
" loader_cls=PyPDFLoader)\n",
|
42 |
+
" \n",
|
43 |
+
" documents = loader.load()\n",
|
44 |
+
"\n",
|
45 |
+
" return documents"
|
46 |
+
]
|
47 |
+
},
|
48 |
+
{
|
49 |
+
"cell_type": "code",
|
50 |
+
"execution_count": 16,
|
51 |
+
"metadata": {},
|
52 |
+
"outputs": [
|
53 |
+
{
|
54 |
+
"ename": "FileNotFoundError",
|
55 |
+
"evalue": "Directory not found: 'Careers.pdf'",
|
56 |
+
"output_type": "error",
|
57 |
+
"traceback": [
|
58 |
+
"\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
|
59 |
+
"\u001b[1;31mFileNotFoundError\u001b[0m Traceback (most recent call last)",
|
60 |
+
"Cell \u001b[1;32mIn[16], line 1\u001b[0m\n\u001b[1;32m----> 1\u001b[0m extracted_data \u001b[38;5;241m=\u001b[39m \u001b[43mload_pdf\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mCareers.pdf\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m)\u001b[49m\n",
|
61 |
+
"Cell \u001b[1;32mIn[3], line 7\u001b[0m, in \u001b[0;36mload_pdf\u001b[1;34m(data)\u001b[0m\n\u001b[0;32m 2\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21mload_pdf\u001b[39m(data):\n\u001b[0;32m 3\u001b[0m loader \u001b[38;5;241m=\u001b[39m DirectoryLoader(data,\n\u001b[0;32m 4\u001b[0m glob\u001b[38;5;241m=\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m*.pdf\u001b[39m\u001b[38;5;124m\"\u001b[39m,\n\u001b[0;32m 5\u001b[0m loader_cls\u001b[38;5;241m=\u001b[39mPyPDFLoader)\n\u001b[1;32m----> 7\u001b[0m documents \u001b[38;5;241m=\u001b[39m \u001b[43mloader\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mload\u001b[49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m\n\u001b[0;32m 9\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m documents\n",
|
62 |
+
"File \u001b[1;32m~\\AppData\\Roaming\\Python\\Python38\\site-packages\\langchain_community\\document_loaders\\directory.py:117\u001b[0m, in \u001b[0;36mDirectoryLoader.load\u001b[1;34m(self)\u001b[0m\n\u001b[0;32m 115\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21mload\u001b[39m(\u001b[38;5;28mself\u001b[39m) \u001b[38;5;241m-\u001b[39m\u001b[38;5;241m>\u001b[39m List[Document]:\n\u001b[0;32m 116\u001b[0m \u001b[38;5;250m \u001b[39m\u001b[38;5;124;03m\"\"\"Load documents.\"\"\"\u001b[39;00m\n\u001b[1;32m--> 117\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28;43mlist\u001b[39;49m\u001b[43m(\u001b[49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mlazy_load\u001b[49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m\u001b[43m)\u001b[49m\n",
|
63 |
+
"File \u001b[1;32m~\\AppData\\Roaming\\Python\\Python38\\site-packages\\langchain_community\\document_loaders\\directory.py:123\u001b[0m, in \u001b[0;36mDirectoryLoader.lazy_load\u001b[1;34m(self)\u001b[0m\n\u001b[0;32m 121\u001b[0m p \u001b[38;5;241m=\u001b[39m Path(\u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mpath)\n\u001b[0;32m 122\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;129;01mnot\u001b[39;00m p\u001b[38;5;241m.\u001b[39mexists():\n\u001b[1;32m--> 123\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m \u001b[38;5;167;01mFileNotFoundError\u001b[39;00m(\u001b[38;5;124mf\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mDirectory not found: \u001b[39m\u001b[38;5;124m'\u001b[39m\u001b[38;5;132;01m{\u001b[39;00m\u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mpath\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;124m'\u001b[39m\u001b[38;5;124m\"\u001b[39m)\n\u001b[0;32m 124\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;129;01mnot\u001b[39;00m p\u001b[38;5;241m.\u001b[39mis_dir():\n\u001b[0;32m 125\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m \u001b[38;5;167;01mValueError\u001b[39;00m(\u001b[38;5;124mf\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mExpected directory, got file: \u001b[39m\u001b[38;5;124m'\u001b[39m\u001b[38;5;132;01m{\u001b[39;00m\u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mpath\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;124m'\u001b[39m\u001b[38;5;124m\"\u001b[39m)\n",
|
64 |
+
"\u001b[1;31mFileNotFoundError\u001b[0m: Directory not found: 'Careers.pdf'"
|
65 |
+
]
|
66 |
+
}
|
67 |
+
],
|
68 |
+
"source": [
|
69 |
+
"\n",
|
70 |
+
"extracted_data = load_pdf(\"Data/\")"
|
71 |
+
]
|
72 |
+
},
|
73 |
+
{
|
74 |
+
"cell_type": "code",
|
75 |
+
"execution_count": null,
|
76 |
+
"metadata": {},
|
77 |
+
"outputs": [],
|
78 |
+
"source": [
|
79 |
+
"#extracted_data"
|
80 |
+
]
|
81 |
+
},
|
82 |
+
{
|
83 |
+
"cell_type": "code",
|
84 |
+
"execution_count": null,
|
85 |
+
"metadata": {},
|
86 |
+
"outputs": [],
|
87 |
+
"source": [
|
88 |
+
"#create text Chunks\n",
|
89 |
+
"def text_split(extracted_pdf):\n",
|
90 |
+
" text_splitter = RecursiveCharacterTextSplitter(chunk_size=500,\n",
|
91 |
+
" chunk_overlap=20)\n",
|
92 |
+
" text_chunks=text_splitter.split_documents(extracted_pdf)\n",
|
93 |
+
" return text_chunks "
|
94 |
+
]
|
95 |
+
},
|
96 |
+
{
|
97 |
+
"cell_type": "code",
|
98 |
+
"execution_count": null,
|
99 |
+
"metadata": {},
|
100 |
+
"outputs": [
|
101 |
+
{
|
102 |
+
"name": "stdout",
|
103 |
+
"output_type": "stream",
|
104 |
+
"text": [
|
105 |
+
"chunks created\n",
|
106 |
+
"The number of chunks is: 15409\n"
|
107 |
+
]
|
108 |
+
}
|
109 |
+
],
|
110 |
+
"source": [
|
111 |
+
"text_chunks = text_split(extracted_data)\n",
|
112 |
+
"print(\"chunks created\")\n",
|
113 |
+
"print(\"The number of chunks is:\",len(text_chunks))"
|
114 |
+
]
|
115 |
+
},
|
116 |
+
{
|
117 |
+
"cell_type": "code",
|
118 |
+
"execution_count": null,
|
119 |
+
"metadata": {},
|
120 |
+
"outputs": [],
|
121 |
+
"source": [
|
122 |
+
"#download embedding model\n",
|
123 |
+
"def download_hugging_face_embeddings():\n",
|
124 |
+
" embeddings = HuggingFaceEmbeddings(model_name=\"sentence-transformers/all-MiniLM-L6-v2\")\n",
|
125 |
+
" return embeddings"
|
126 |
+
]
|
127 |
+
},
|
128 |
+
{
|
129 |
+
"cell_type": "code",
|
130 |
+
"execution_count": null,
|
131 |
+
"metadata": {},
|
132 |
+
"outputs": [
|
133 |
+
{
|
134 |
+
"name": "stderr",
|
135 |
+
"output_type": "stream",
|
136 |
+
"text": [
|
137 |
+
"C:\\Users\\Admin\\AppData\\Roaming\\Python\\Python38\\site-packages\\langchain_core\\_api\\deprecation.py:119: LangChainDeprecationWarning: The class `HuggingFaceEmbeddings` was deprecated in LangChain 0.2.2 and will be removed in 0.3.0. An updated version of the class exists in the langchain-huggingface package and should be used instead. To use it run `pip install -U langchain-huggingface` and import as `from langchain_huggingface import HuggingFaceEmbeddings`.\n",
|
138 |
+
" warn_deprecated(\n",
|
139 |
+
"C:\\Users\\Admin\\AppData\\Roaming\\Python\\Python38\\site-packages\\huggingface_hub\\file_download.py:1132: FutureWarning: `resume_download` is deprecated and will be removed in version 1.0.0. Downloads always resume when possible. If you want to force a new download, use `force_download=True`.\n",
|
140 |
+
" warnings.warn(\n"
|
141 |
+
]
|
142 |
+
}
|
143 |
+
],
|
144 |
+
"source": [
|
145 |
+
"embeddings = download_hugging_face_embeddings()"
|
146 |
+
]
|
147 |
+
},
|
148 |
+
{
|
149 |
+
"cell_type": "code",
|
150 |
+
"execution_count": null,
|
151 |
+
"metadata": {},
|
152 |
+
"outputs": [
|
153 |
+
{
|
154 |
+
"data": {
|
155 |
+
"text/plain": [
|
156 |
+
"HuggingFaceEmbeddings(client=SentenceTransformer(\n",
|
157 |
+
" (0): Transformer({'max_seq_length': 256, 'do_lower_case': False}) with Transformer model: BertModel \n",
|
158 |
+
" (1): Pooling({'word_embedding_dimension': 384, 'pooling_mode_cls_token': False, 'pooling_mode_mean_tokens': True, 'pooling_mode_max_tokens': False, 'pooling_mode_mean_sqrt_len_tokens': False, 'pooling_mode_weightedmean_tokens': False, 'pooling_mode_lasttoken': False, 'include_prompt': True})\n",
|
159 |
+
" (2): Normalize()\n",
|
160 |
+
"), model_name='sentence-transformers/all-MiniLM-L6-v2', cache_folder=None, model_kwargs={}, encode_kwargs={}, multi_process=False, show_progress=False)"
|
161 |
+
]
|
162 |
+
},
|
163 |
+
"execution_count": 15,
|
164 |
+
"metadata": {},
|
165 |
+
"output_type": "execute_result"
|
166 |
+
}
|
167 |
+
],
|
168 |
+
"source": [
|
169 |
+
"embeddings"
|
170 |
+
]
|
171 |
+
},
|
172 |
+
{
|
173 |
+
"cell_type": "code",
|
174 |
+
"execution_count": null,
|
175 |
+
"metadata": {},
|
176 |
+
"outputs": [
|
177 |
+
{
|
178 |
+
"name": "stdout",
|
179 |
+
"output_type": "stream",
|
180 |
+
"text": [
|
181 |
+
"Length: 384\n"
|
182 |
+
]
|
183 |
+
},
|
184 |
+
{
|
185 |
+
"data": {
|
186 |
+
"text/plain": [
|
187 |
+
"[-0.020386872813105583,\n",
|
188 |
+
" 0.02528088353574276,\n",
|
189 |
+
" -0.0005662009352818131,\n",
|
190 |
+
" 0.011615470983088017,\n",
|
191 |
+
" -0.037988364696502686,\n",
|
192 |
+
" -0.11998124420642853,\n",
|
193 |
+
" 0.041709501296281815,\n",
|
194 |
+
" -0.020857175812125206,\n",
|
195 |
+
" -0.05900680273771286,\n",
|
196 |
+
" 0.024232536554336548,\n",
|
197 |
+
" 0.06212019547820091,\n",
|
198 |
+
" 0.06767985969781876,\n",
|
199 |
+
" 0.03310026600956917,\n",
|
200 |
+
" -0.010369333438575268,\n",
|
201 |
+
" -0.031215619295835495,\n",
|
202 |
+
" -0.032733283936977386,\n",
|
203 |
+
" -0.002111728535965085,\n",
|
204 |
+
" 0.009261957369744778,\n",
|
205 |
+
" -0.12476464360952377,\n",
|
206 |
+
" 0.011236833408474922,\n",
|
207 |
+
" 0.03904539346694946,\n",
|
208 |
+
" 0.054402466863393784,\n",
|
209 |
+
" -0.0028255104552954435,\n",
|
210 |
+
" 0.04455625265836716,\n",
|
211 |
+
" -0.0854201465845108,\n",
|
212 |
+
" -0.022873710840940475,\n",
|
213 |
+
" 0.039140552282333374,\n",
|
214 |
+
" 0.03604690730571747,\n",
|
215 |
+
" -0.0321267768740654,\n",
|
216 |
+
" -0.06425873190164566,\n",
|
217 |
+
" 0.05812908709049225,\n",
|
218 |
+
" 0.04669089987874031,\n",
|
219 |
+
" 0.08061555027961731,\n",
|
220 |
+
" -0.0077342689037323,\n",
|
221 |
+
" -0.022083202376961708,\n",
|
222 |
+
" 0.06713154911994934,\n",
|
223 |
+
" -0.04504143446683884,\n",
|
224 |
+
" -0.10212118923664093,\n",
|
225 |
+
" 0.0012643759837374091,\n",
|
226 |
+
" 0.04680193215608597,\n",
|
227 |
+
" 0.02639589086174965,\n",
|
228 |
+
" -0.06990959495306015,\n",
|
229 |
+
" -0.04453347623348236,\n",
|
230 |
+
" -0.006901898421347141,\n",
|
231 |
+
" 0.019288599491119385,\n",
|
232 |
+
" 0.02059079520404339,\n",
|
233 |
+
" 0.006518140435218811,\n",
|
234 |
+
" 0.035493891686201096,\n",
|
235 |
+
" 0.10393310338258743,\n",
|
236 |
+
" 0.01750371791422367,\n",
|
237 |
+
" -0.04294285178184509,\n",
|
238 |
+
" -0.057037338614463806,\n",
|
239 |
+
" -0.011423510499298573,\n",
|
240 |
+
" 0.009236752055585384,\n",
|
241 |
+
" 0.04582153260707855,\n",
|
242 |
+
" 0.0070036184042692184,\n",
|
243 |
+
" 0.02421007864177227,\n",
|
244 |
+
" -0.06064579635858536,\n",
|
245 |
+
" -0.014943967573344707,\n",
|
246 |
+
" -0.0305157620459795,\n",
|
247 |
+
" -0.06836125254631042,\n",
|
248 |
+
" 0.05706855654716492,\n",
|
249 |
+
" -0.03227071464061737,\n",
|
250 |
+
" 0.04119705408811569,\n",
|
251 |
+
" 0.09017682075500488,\n",
|
252 |
+
" -0.07689837366342545,\n",
|
253 |
+
" -0.022328900173306465,\n",
|
254 |
+
" 0.02609133906662464,\n",
|
255 |
+
" -0.057754434645175934,\n",
|
256 |
+
" -0.060503143817186356,\n",
|
257 |
+
" -0.043829482048749924,\n",
|
258 |
+
" 0.010114436037838459,\n",
|
259 |
+
" 0.03421920910477638,\n",
|
260 |
+
" 0.07573983073234558,\n",
|
261 |
+
" -0.04518907144665718,\n",
|
262 |
+
" 0.005837503354996443,\n",
|
263 |
+
" 0.0184907466173172,\n",
|
264 |
+
" -0.0018646110547706485,\n",
|
265 |
+
" 0.017705997452139854,\n",
|
266 |
+
" 0.054946303367614746,\n",
|
267 |
+
" 0.06722188740968704,\n",
|
268 |
+
" -0.10008065402507782,\n",
|
269 |
+
" 0.017738861963152885,\n",
|
270 |
+
" 0.043243926018476486,\n",
|
271 |
+
" 0.01077823992818594,\n",
|
272 |
+
" -0.014706484042108059,\n",
|
273 |
+
" -0.013241068460047245,\n",
|
274 |
+
" -0.001782232546247542,\n",
|
275 |
+
" -0.045426856726408005,\n",
|
276 |
+
" -0.03418899327516556,\n",
|
277 |
+
" -0.14636532962322235,\n",
|
278 |
+
" -0.011157987639307976,\n",
|
279 |
+
" -0.011241820640861988,\n",
|
280 |
+
" 0.011740676127374172,\n",
|
281 |
+
" -0.08864285796880722,\n",
|
282 |
+
" -0.028394203633069992,\n",
|
283 |
+
" 0.07532472908496857,\n",
|
284 |
+
" -0.018445875495672226,\n",
|
285 |
+
" -0.17038744688034058,\n",
|
286 |
+
" 0.15587182343006134,\n",
|
287 |
+
" 0.022921469062566757,\n",
|
288 |
+
" 0.046667248010635376,\n",
|
289 |
+
" 0.040010735392570496,\n",
|
290 |
+
" 0.02375500649213791,\n",
|
291 |
+
" 0.049802809953689575,\n",
|
292 |
+
" 0.030321596190333366,\n",
|
293 |
+
" 0.0003741529362741858,\n",
|
294 |
+
" 0.06957260519266129,\n",
|
295 |
+
" -0.022312656044960022,\n",
|
296 |
+
" -0.02747281827032566,\n",
|
297 |
+
" 0.006083943415433168,\n",
|
298 |
+
" -0.04853246361017227,\n",
|
299 |
+
" 0.049238789826631546,\n",
|
300 |
+
" -0.007612141780555248,\n",
|
301 |
+
" 0.06917710602283478,\n",
|
302 |
+
" -0.07174898684024811,\n",
|
303 |
+
" -0.020257242023944855,\n",
|
304 |
+
" 0.014374688267707825,\n",
|
305 |
+
" -0.030236804857850075,\n",
|
306 |
+
" 0.004180468153208494,\n",
|
307 |
+
" 0.05348922684788704,\n",
|
308 |
+
" -0.058872416615486145,\n",
|
309 |
+
" 0.023056630045175552,\n",
|
310 |
+
" 0.013102822005748749,\n",
|
311 |
+
" 0.01088209543377161,\n",
|
312 |
+
" 0.02322239615023136,\n",
|
313 |
+
" 0.028361210599541664,\n",
|
314 |
+
" -3.843664856439317e-33,\n",
|
315 |
+
" 0.0435662642121315,\n",
|
316 |
+
" -0.003594552166759968,\n",
|
317 |
+
" 0.042123064398765564,\n",
|
318 |
+
" 0.1231817975640297,\n",
|
319 |
+
" 0.017473308369517326,\n",
|
320 |
+
" 0.00942733883857727,\n",
|
321 |
+
" -0.09451454132795334,\n",
|
322 |
+
" -0.021238375455141068,\n",
|
323 |
+
" 0.03426387161016464,\n",
|
324 |
+
" 0.025959163904190063,\n",
|
325 |
+
" 0.028061239048838615,\n",
|
326 |
+
" 0.012698487378656864,\n",
|
327 |
+
" -0.04617796093225479,\n",
|
328 |
+
" 0.030305471271276474,\n",
|
329 |
+
" -0.045230939984321594,\n",
|
330 |
+
" 0.11220850050449371,\n",
|
331 |
+
" -0.09135962277650833,\n",
|
332 |
+
" -0.013798639178276062,\n",
|
333 |
+
" 0.025815125554800034,\n",
|
334 |
+
" 0.08335626125335693,\n",
|
335 |
+
" -0.07693815231323242,\n",
|
336 |
+
" -0.010359508916735649,\n",
|
337 |
+
" 0.009555504657328129,\n",
|
338 |
+
" 0.08872868865728378,\n",
|
339 |
+
" -0.009140676818788052,\n",
|
340 |
+
" 0.008417350240051746,\n",
|
341 |
+
" 0.010792146436870098,\n",
|
342 |
+
" -0.09071637690067291,\n",
|
343 |
+
" 0.09623939543962479,\n",
|
344 |
+
" 0.007239796221256256,\n",
|
345 |
+
" -0.03825897350907326,\n",
|
346 |
+
" -0.05111745372414589,\n",
|
347 |
+
" 0.020446274429559708,\n",
|
348 |
+
" 0.01577543467283249,\n",
|
349 |
+
" -0.00584018137305975,\n",
|
350 |
+
" 0.011155584827065468,\n",
|
351 |
+
" -0.007191200274974108,\n",
|
352 |
+
" -0.07329276949167252,\n",
|
353 |
+
" -0.07283007353544235,\n",
|
354 |
+
" -0.006110389716923237,\n",
|
355 |
+
" -0.05931411683559418,\n",
|
356 |
+
" 0.045463789254426956,\n",
|
357 |
+
" 0.04360096901655197,\n",
|
358 |
+
" -0.007337683811783791,\n",
|
359 |
+
" -0.02558256685733795,\n",
|
360 |
+
" -0.0344063900411129,\n",
|
361 |
+
" 0.02559274062514305,\n",
|
362 |
+
" 0.018136944621801376,\n",
|
363 |
+
" 0.04025298357009888,\n",
|
364 |
+
" 0.03997461870312691,\n",
|
365 |
+
" -0.04333764687180519,\n",
|
366 |
+
" 0.008319374173879623,\n",
|
367 |
+
" -0.03883630037307739,\n",
|
368 |
+
" 0.05585148185491562,\n",
|
369 |
+
" -0.010561023838818073,\n",
|
370 |
+
" 0.01699744537472725,\n",
|
371 |
+
" 0.04742543399333954,\n",
|
372 |
+
" -0.048003457486629486,\n",
|
373 |
+
" -0.013104816898703575,\n",
|
374 |
+
" 0.046607110649347305,\n",
|
375 |
+
" -0.003912207204848528,\n",
|
376 |
+
" 0.10242760181427002,\n",
|
377 |
+
" -0.04255157709121704,\n",
|
378 |
+
" -0.028219876810908318,\n",
|
379 |
+
" -0.008180612698197365,\n",
|
380 |
+
" -0.01885264366865158,\n",
|
381 |
+
" 0.05203333869576454,\n",
|
382 |
+
" 0.033868011087179184,\n",
|
383 |
+
" 0.059511031955480576,\n",
|
384 |
+
" 0.004061603918671608,\n",
|
385 |
+
" -0.01956753432750702,\n",
|
386 |
+
" 0.02674257941544056,\n",
|
387 |
+
" 0.02093179151415825,\n",
|
388 |
+
" 0.02192043699324131,\n",
|
389 |
+
" 0.012750852853059769,\n",
|
390 |
+
" 0.05398520082235336,\n",
|
391 |
+
" 0.052067991346120834,\n",
|
392 |
+
" -0.0031074492726475,\n",
|
393 |
+
" 0.02487236261367798,\n",
|
394 |
+
" -0.07944536954164505,\n",
|
395 |
+
" 0.028617681935429573,\n",
|
396 |
+
" -0.0007746760384179652,\n",
|
397 |
+
" -0.003381764981895685,\n",
|
398 |
+
" -0.05178724229335785,\n",
|
399 |
+
" 0.09358307719230652,\n",
|
400 |
+
" 0.018984489142894745,\n",
|
401 |
+
" -0.009582558646798134,\n",
|
402 |
+
" -0.0856575071811676,\n",
|
403 |
+
" -0.017498208209872246,\n",
|
404 |
+
" -0.004158390685915947,\n",
|
405 |
+
" -0.06506012380123138,\n",
|
406 |
+
" 0.05912616476416588,\n",
|
407 |
+
" 0.035769641399383545,\n",
|
408 |
+
" -0.005036777351051569,\n",
|
409 |
+
" -0.08909005671739578,\n",
|
410 |
+
" 2.5757033649164638e-33,\n",
|
411 |
+
" 0.13979335129261017,\n",
|
412 |
+
" 0.017513630911707878,\n",
|
413 |
+
" -0.05452438071370125,\n",
|
414 |
+
" -0.06710045784711838,\n",
|
415 |
+
" -0.010243951342999935,\n",
|
416 |
+
" -0.032303180545568466,\n",
|
417 |
+
" -0.07818872481584549,\n",
|
418 |
+
" 0.14000575244426727,\n",
|
419 |
+
" -0.07843434065580368,\n",
|
420 |
+
" 0.0474369153380394,\n",
|
421 |
+
" 0.021780453622341156,\n",
|
422 |
+
" 0.021539803594350815,\n",
|
423 |
+
" 0.1262277364730835,\n",
|
424 |
+
" 0.02580106630921364,\n",
|
425 |
+
" 0.022561756893992424,\n",
|
426 |
+
" -0.015236180275678635,\n",
|
427 |
+
" 0.13175277411937714,\n",
|
428 |
+
" 0.014995898120105267,\n",
|
429 |
+
" 0.014494264498353004,\n",
|
430 |
+
" -0.0018083483446389437,\n",
|
431 |
+
" -0.013143729418516159,\n",
|
432 |
+
" -0.049164507538080215,\n",
|
433 |
+
" -0.06190984323620796,\n",
|
434 |
+
" 0.021932406350970268,\n",
|
435 |
+
" -0.022566061466932297,\n",
|
436 |
+
" 0.024125924333930016,\n",
|
437 |
+
" 0.04778725281357765,\n",
|
438 |
+
" 0.001361499889753759,\n",
|
439 |
+
" -0.12093906104564667,\n",
|
440 |
+
" 0.013258987106382847,\n",
|
441 |
+
" -0.015382496640086174,\n",
|
442 |
+
" 0.028439369052648544,\n",
|
443 |
+
" -0.031059566885232925,\n",
|
444 |
+
" -0.014658545143902302,\n",
|
445 |
+
" -0.0164962001144886,\n",
|
446 |
+
" 0.023634258657693863,\n",
|
447 |
+
" -0.0965748280286789,\n",
|
448 |
+
" -0.038894761353731155,\n",
|
449 |
+
" -0.02935647778213024,\n",
|
450 |
+
" -0.031149519607424736,\n",
|
451 |
+
" -0.04675932228565216,\n",
|
452 |
+
" 0.01085135992616415,\n",
|
453 |
+
" -0.006681295111775398,\n",
|
454 |
+
" 0.030533554032444954,\n",
|
455 |
+
" -0.10486804693937302,\n",
|
456 |
+
" -0.005622635595500469,\n",
|
457 |
+
" -0.03426210954785347,\n",
|
458 |
+
" 0.014524451456964016,\n",
|
459 |
+
" -0.036871835589408875,\n",
|
460 |
+
" -0.03581416606903076,\n",
|
461 |
+
" -0.09492850303649902,\n",
|
462 |
+
" -0.05121384561061859,\n",
|
463 |
+
" 0.0863681212067604,\n",
|
464 |
+
" -0.02769472263753414,\n",
|
465 |
+
" -0.03255052864551544,\n",
|
466 |
+
" 0.03351925313472748,\n",
|
467 |
+
" -0.023608211427927017,\n",
|
468 |
+
" -0.0033292206935584545,\n",
|
469 |
+
" 0.03848697617650032,\n",
|
470 |
+
" -0.0116463303565979,\n",
|
471 |
+
" 0.012732136063277721,\n",
|
472 |
+
" 0.05946173891425133,\n",
|
473 |
+
" 0.03451535105705261,\n",
|
474 |
+
" 0.08603373914957047,\n",
|
475 |
+
" 0.025225210934877396,\n",
|
476 |
+
" -0.03410428389906883,\n",
|
477 |
+
" 0.01370932161808014,\n",
|
478 |
+
" 0.015575790777802467,\n",
|
479 |
+
" 0.03082992695271969,\n",
|
480 |
+
" -0.0181691013276577,\n",
|
481 |
+
" 0.0075484346598386765,\n",
|
482 |
+
" 0.00767799187451601,\n",
|
483 |
+
" -0.020997334271669388,\n",
|
484 |
+
" -0.01683652587234974,\n",
|
485 |
+
" -0.032185547053813934,\n",
|
486 |
+
" 0.06366591155529022,\n",
|
487 |
+
" 0.003027765080332756,\n",
|
488 |
+
" -0.01919621229171753,\n",
|
489 |
+
" 0.01796714961528778,\n",
|
490 |
+
" 0.030703270807862282,\n",
|
491 |
+
" -0.010722151026129723,\n",
|
492 |
+
" 0.0567406490445137,\n",
|
493 |
+
" 0.02326800301671028,\n",
|
494 |
+
" 0.029091518372297287,\n",
|
495 |
+
" 0.007758266758173704,\n",
|
496 |
+
" 0.06784671545028687,\n",
|
497 |
+
" 0.08166711777448654,\n",
|
498 |
+
" 0.047504521906375885,\n",
|
499 |
+
" -0.0262406338006258,\n",
|
500 |
+
" -0.042831819504499435,\n",
|
501 |
+
" -0.009907595813274384,\n",
|
502 |
+
" 0.006457660812884569,\n",
|
503 |
+
" 0.017302438616752625,\n",
|
504 |
+
" 0.030671026557683945,\n",
|
505 |
+
" -0.03801177814602852,\n",
|
506 |
+
" -1.6864364127400222e-08,\n",
|
507 |
+
" -0.08774770051240921,\n",
|
508 |
+
" 0.03914780169725418,\n",
|
509 |
+
" -0.007313665002584457,\n",
|
510 |
+
" 0.055220186710357666,\n",
|
511 |
+
" 0.03042862005531788,\n",
|
512 |
+
" 0.018359912559390068,\n",
|
513 |
+
" -0.08776683360338211,\n",
|
514 |
+
" -0.06734011322259903,\n",
|
515 |
+
" -0.0747460424900055,\n",
|
516 |
+
" -0.009306997992098331,\n",
|
517 |
+
" 0.03774425759911537,\n",
|
518 |
+
" 0.13193342089653015,\n",
|
519 |
+
" -0.08082900196313858,\n",
|
520 |
+
" 0.01321407500654459,\n",
|
521 |
+
" 0.048574961721897125,\n",
|
522 |
+
" 0.09028726816177368,\n",
|
523 |
+
" -0.029366280883550644,\n",
|
524 |
+
" 0.03968300297856331,\n",
|
525 |
+
" -0.0341360829770565,\n",
|
526 |
+
" 0.0035193762741982937,\n",
|
527 |
+
" -0.011343852616846561,\n",
|
528 |
+
" 0.009339207783341408,\n",
|
529 |
+
" 0.011233095079660416,\n",
|
530 |
+
" -0.06465622037649155,\n",
|
531 |
+
" 0.0345761775970459,\n",
|
532 |
+
" -0.09496650844812393,\n",
|
533 |
+
" -0.007475709542632103,\n",
|
534 |
+
" 0.003689560340717435,\n",
|
535 |
+
" 0.010514314286410809,\n",
|
536 |
+
" -0.06667248904705048,\n",
|
537 |
+
" 0.051605112850666046,\n",
|
538 |
+
" 0.10477923601865768,\n",
|
539 |
+
" -0.05478629842400551,\n",
|
540 |
+
" 0.021519236266613007,\n",
|
541 |
+
" -0.08572050929069519,\n",
|
542 |
+
" -0.027919678017497063,\n",
|
543 |
+
" 0.02723752148449421,\n",
|
544 |
+
" 0.09629359841346741,\n",
|
545 |
+
" 0.06709317862987518,\n",
|
546 |
+
" -0.07181668281555176,\n",
|
547 |
+
" -0.09750431030988693,\n",
|
548 |
+
" 0.04430799558758736,\n",
|
549 |
+
" -0.05396273732185364,\n",
|
550 |
+
" -0.10748161375522614,\n",
|
551 |
+
" -0.05498868227005005,\n",
|
552 |
+
" 0.03482293710112572,\n",
|
553 |
+
" 0.06672007590532303,\n",
|
554 |
+
" -0.05602458119392395,\n",
|
555 |
+
" 0.02175173908472061,\n",
|
556 |
+
" -0.06315217912197113,\n",
|
557 |
+
" -0.06730655580759048,\n",
|
558 |
+
" 0.03782231733202934,\n",
|
559 |
+
" 0.07897446304559708,\n",
|
560 |
+
" 0.002572576981037855,\n",
|
561 |
+
" 0.10580893605947495,\n",
|
562 |
+
" 0.09685958921909332,\n",
|
563 |
+
" 0.047380004078149796,\n",
|
564 |
+
" 0.03066212125122547,\n",
|
565 |
+
" -0.008867030031979084,\n",
|
566 |
+
" 0.06080889329314232,\n",
|
567 |
+
" 0.030900919809937477,\n",
|
568 |
+
" -0.030652379617094994,\n",
|
569 |
+
" 0.03755692020058632,\n",
|
570 |
+
" 0.03742789104580879]"
|
571 |
+
]
|
572 |
+
},
|
573 |
+
"execution_count": 16,
|
574 |
+
"metadata": {},
|
575 |
+
"output_type": "execute_result"
|
576 |
+
}
|
577 |
+
],
|
578 |
+
"source": [
|
579 |
+
"query_result = embeddings.embed_query(\"Hello World!\")\n",
|
580 |
+
"print(\"Length:\", len(query_result))\n",
|
581 |
+
"query_result"
|
582 |
+
]
|
583 |
+
},
|
584 |
+
{
|
585 |
+
"cell_type": "code",
|
586 |
+
"execution_count": null,
|
587 |
+
"metadata": {},
|
588 |
+
"outputs": [
|
589 |
+
{
|
590 |
+
"data": {
|
591 |
+
"text/plain": [
|
592 |
+
"[-0.020386872813105583,\n",
|
593 |
+
" 0.02528088353574276,\n",
|
594 |
+
" -0.0005662009352818131,\n",
|
595 |
+
" 0.011615470983088017,\n",
|
596 |
+
" -0.037988364696502686,\n",
|
597 |
+
" -0.11998124420642853,\n",
|
598 |
+
" 0.041709501296281815,\n",
|
599 |
+
" -0.020857175812125206,\n",
|
600 |
+
" -0.05900680273771286,\n",
|
601 |
+
" 0.024232536554336548,\n",
|
602 |
+
" 0.06212019547820091,\n",
|
603 |
+
" 0.06767985969781876,\n",
|
604 |
+
" 0.03310026600956917,\n",
|
605 |
+
" -0.010369333438575268,\n",
|
606 |
+
" -0.031215619295835495,\n",
|
607 |
+
" -0.032733283936977386,\n",
|
608 |
+
" -0.002111728535965085,\n",
|
609 |
+
" 0.009261957369744778,\n",
|
610 |
+
" -0.12476464360952377,\n",
|
611 |
+
" 0.011236833408474922,\n",
|
612 |
+
" 0.03904539346694946,\n",
|
613 |
+
" 0.054402466863393784,\n",
|
614 |
+
" -0.0028255104552954435,\n",
|
615 |
+
" 0.04455625265836716,\n",
|
616 |
+
" -0.0854201465845108,\n",
|
617 |
+
" -0.022873710840940475,\n",
|
618 |
+
" 0.039140552282333374,\n",
|
619 |
+
" 0.03604690730571747,\n",
|
620 |
+
" -0.0321267768740654,\n",
|
621 |
+
" -0.06425873190164566,\n",
|
622 |
+
" 0.05812908709049225,\n",
|
623 |
+
" 0.04669089987874031,\n",
|
624 |
+
" 0.08061555027961731,\n",
|
625 |
+
" -0.0077342689037323,\n",
|
626 |
+
" -0.022083202376961708,\n",
|
627 |
+
" 0.06713154911994934,\n",
|
628 |
+
" -0.04504143446683884,\n",
|
629 |
+
" -0.10212118923664093,\n",
|
630 |
+
" 0.0012643759837374091,\n",
|
631 |
+
" 0.04680193215608597,\n",
|
632 |
+
" 0.02639589086174965,\n",
|
633 |
+
" -0.06990959495306015,\n",
|
634 |
+
" -0.04453347623348236,\n",
|
635 |
+
" -0.006901898421347141,\n",
|
636 |
+
" 0.019288599491119385,\n",
|
637 |
+
" 0.02059079520404339,\n",
|
638 |
+
" 0.006518140435218811,\n",
|
639 |
+
" 0.035493891686201096,\n",
|
640 |
+
" 0.10393310338258743,\n",
|
641 |
+
" 0.01750371791422367,\n",
|
642 |
+
" -0.04294285178184509,\n",
|
643 |
+
" -0.057037338614463806,\n",
|
644 |
+
" -0.011423510499298573,\n",
|
645 |
+
" 0.009236752055585384,\n",
|
646 |
+
" 0.04582153260707855,\n",
|
647 |
+
" 0.0070036184042692184,\n",
|
648 |
+
" 0.02421007864177227,\n",
|
649 |
+
" -0.06064579635858536,\n",
|
650 |
+
" -0.014943967573344707,\n",
|
651 |
+
" -0.0305157620459795,\n",
|
652 |
+
" -0.06836125254631042,\n",
|
653 |
+
" 0.05706855654716492,\n",
|
654 |
+
" -0.03227071464061737,\n",
|
655 |
+
" 0.04119705408811569,\n",
|
656 |
+
" 0.09017682075500488,\n",
|
657 |
+
" -0.07689837366342545,\n",
|
658 |
+
" -0.022328900173306465,\n",
|
659 |
+
" 0.02609133906662464,\n",
|
660 |
+
" -0.057754434645175934,\n",
|
661 |
+
" -0.060503143817186356,\n",
|
662 |
+
" -0.043829482048749924,\n",
|
663 |
+
" 0.010114436037838459,\n",
|
664 |
+
" 0.03421920910477638,\n",
|
665 |
+
" 0.07573983073234558,\n",
|
666 |
+
" -0.04518907144665718,\n",
|
667 |
+
" 0.005837503354996443,\n",
|
668 |
+
" 0.0184907466173172,\n",
|
669 |
+
" -0.0018646110547706485,\n",
|
670 |
+
" 0.017705997452139854,\n",
|
671 |
+
" 0.054946303367614746,\n",
|
672 |
+
" 0.06722188740968704,\n",
|
673 |
+
" -0.10008065402507782,\n",
|
674 |
+
" 0.017738861963152885,\n",
|
675 |
+
" 0.043243926018476486,\n",
|
676 |
+
" 0.01077823992818594,\n",
|
677 |
+
" -0.014706484042108059,\n",
|
678 |
+
" -0.013241068460047245,\n",
|
679 |
+
" -0.001782232546247542,\n",
|
680 |
+
" -0.045426856726408005,\n",
|
681 |
+
" -0.03418899327516556,\n",
|
682 |
+
" -0.14636532962322235,\n",
|
683 |
+
" -0.011157987639307976,\n",
|
684 |
+
" -0.011241820640861988,\n",
|
685 |
+
" 0.011740676127374172,\n",
|
686 |
+
" -0.08864285796880722,\n",
|
687 |
+
" -0.028394203633069992,\n",
|
688 |
+
" 0.07532472908496857,\n",
|
689 |
+
" -0.018445875495672226,\n",
|
690 |
+
" -0.17038744688034058,\n",
|
691 |
+
" 0.15587182343006134,\n",
|
692 |
+
" 0.022921469062566757,\n",
|
693 |
+
" 0.046667248010635376,\n",
|
694 |
+
" 0.040010735392570496,\n",
|
695 |
+
" 0.02375500649213791,\n",
|
696 |
+
" 0.049802809953689575,\n",
|
697 |
+
" 0.030321596190333366,\n",
|
698 |
+
" 0.0003741529362741858,\n",
|
699 |
+
" 0.06957260519266129,\n",
|
700 |
+
" -0.022312656044960022,\n",
|
701 |
+
" -0.02747281827032566,\n",
|
702 |
+
" 0.006083943415433168,\n",
|
703 |
+
" -0.04853246361017227,\n",
|
704 |
+
" 0.049238789826631546,\n",
|
705 |
+
" -0.007612141780555248,\n",
|
706 |
+
" 0.06917710602283478,\n",
|
707 |
+
" -0.07174898684024811,\n",
|
708 |
+
" -0.020257242023944855,\n",
|
709 |
+
" 0.014374688267707825,\n",
|
710 |
+
" -0.030236804857850075,\n",
|
711 |
+
" 0.004180468153208494,\n",
|
712 |
+
" 0.05348922684788704,\n",
|
713 |
+
" -0.058872416615486145,\n",
|
714 |
+
" 0.023056630045175552,\n",
|
715 |
+
" 0.013102822005748749,\n",
|
716 |
+
" 0.01088209543377161,\n",
|
717 |
+
" 0.02322239615023136,\n",
|
718 |
+
" 0.028361210599541664,\n",
|
719 |
+
" -3.843664856439317e-33,\n",
|
720 |
+
" 0.0435662642121315,\n",
|
721 |
+
" -0.003594552166759968,\n",
|
722 |
+
" 0.042123064398765564,\n",
|
723 |
+
" 0.1231817975640297,\n",
|
724 |
+
" 0.017473308369517326,\n",
|
725 |
+
" 0.00942733883857727,\n",
|
726 |
+
" -0.09451454132795334,\n",
|
727 |
+
" -0.021238375455141068,\n",
|
728 |
+
" 0.03426387161016464,\n",
|
729 |
+
" 0.025959163904190063,\n",
|
730 |
+
" 0.028061239048838615,\n",
|
731 |
+
" 0.012698487378656864,\n",
|
732 |
+
" -0.04617796093225479,\n",
|
733 |
+
" 0.030305471271276474,\n",
|
734 |
+
" -0.045230939984321594,\n",
|
735 |
+
" 0.11220850050449371,\n",
|
736 |
+
" -0.09135962277650833,\n",
|
737 |
+
" -0.013798639178276062,\n",
|
738 |
+
" 0.025815125554800034,\n",
|
739 |
+
" 0.08335626125335693,\n",
|
740 |
+
" -0.07693815231323242,\n",
|
741 |
+
" -0.010359508916735649,\n",
|
742 |
+
" 0.009555504657328129,\n",
|
743 |
+
" 0.08872868865728378,\n",
|
744 |
+
" -0.009140676818788052,\n",
|
745 |
+
" 0.008417350240051746,\n",
|
746 |
+
" 0.010792146436870098,\n",
|
747 |
+
" -0.09071637690067291,\n",
|
748 |
+
" 0.09623939543962479,\n",
|
749 |
+
" 0.007239796221256256,\n",
|
750 |
+
" -0.03825897350907326,\n",
|
751 |
+
" -0.05111745372414589,\n",
|
752 |
+
" 0.020446274429559708,\n",
|
753 |
+
" 0.01577543467283249,\n",
|
754 |
+
" -0.00584018137305975,\n",
|
755 |
+
" 0.011155584827065468,\n",
|
756 |
+
" -0.007191200274974108,\n",
|
757 |
+
" -0.07329276949167252,\n",
|
758 |
+
" -0.07283007353544235,\n",
|
759 |
+
" -0.006110389716923237,\n",
|
760 |
+
" -0.05931411683559418,\n",
|
761 |
+
" 0.045463789254426956,\n",
|
762 |
+
" 0.04360096901655197,\n",
|
763 |
+
" -0.007337683811783791,\n",
|
764 |
+
" -0.02558256685733795,\n",
|
765 |
+
" -0.0344063900411129,\n",
|
766 |
+
" 0.02559274062514305,\n",
|
767 |
+
" 0.018136944621801376,\n",
|
768 |
+
" 0.04025298357009888,\n",
|
769 |
+
" 0.03997461870312691,\n",
|
770 |
+
" -0.04333764687180519,\n",
|
771 |
+
" 0.008319374173879623,\n",
|
772 |
+
" -0.03883630037307739,\n",
|
773 |
+
" 0.05585148185491562,\n",
|
774 |
+
" -0.010561023838818073,\n",
|
775 |
+
" 0.01699744537472725,\n",
|
776 |
+
" 0.04742543399333954,\n",
|
777 |
+
" -0.048003457486629486,\n",
|
778 |
+
" -0.013104816898703575,\n",
|
779 |
+
" 0.046607110649347305,\n",
|
780 |
+
" -0.003912207204848528,\n",
|
781 |
+
" 0.10242760181427002,\n",
|
782 |
+
" -0.04255157709121704,\n",
|
783 |
+
" -0.028219876810908318,\n",
|
784 |
+
" -0.008180612698197365,\n",
|
785 |
+
" -0.01885264366865158,\n",
|
786 |
+
" 0.05203333869576454,\n",
|
787 |
+
" 0.033868011087179184,\n",
|
788 |
+
" 0.059511031955480576,\n",
|
789 |
+
" 0.004061603918671608,\n",
|
790 |
+
" -0.01956753432750702,\n",
|
791 |
+
" 0.02674257941544056,\n",
|
792 |
+
" 0.02093179151415825,\n",
|
793 |
+
" 0.02192043699324131,\n",
|
794 |
+
" 0.012750852853059769,\n",
|
795 |
+
" 0.05398520082235336,\n",
|
796 |
+
" 0.052067991346120834,\n",
|
797 |
+
" -0.0031074492726475,\n",
|
798 |
+
" 0.02487236261367798,\n",
|
799 |
+
" -0.07944536954164505,\n",
|
800 |
+
" 0.028617681935429573,\n",
|
801 |
+
" -0.0007746760384179652,\n",
|
802 |
+
" -0.003381764981895685,\n",
|
803 |
+
" -0.05178724229335785,\n",
|
804 |
+
" 0.09358307719230652,\n",
|
805 |
+
" 0.018984489142894745,\n",
|
806 |
+
" -0.009582558646798134,\n",
|
807 |
+
" -0.0856575071811676,\n",
|
808 |
+
" -0.017498208209872246,\n",
|
809 |
+
" -0.004158390685915947,\n",
|
810 |
+
" -0.06506012380123138,\n",
|
811 |
+
" 0.05912616476416588,\n",
|
812 |
+
" 0.035769641399383545,\n",
|
813 |
+
" -0.005036777351051569,\n",
|
814 |
+
" -0.08909005671739578,\n",
|
815 |
+
" 2.5757033649164638e-33,\n",
|
816 |
+
" 0.13979335129261017,\n",
|
817 |
+
" 0.017513630911707878,\n",
|
818 |
+
" -0.05452438071370125,\n",
|
819 |
+
" -0.06710045784711838,\n",
|
820 |
+
" -0.010243951342999935,\n",
|
821 |
+
" -0.032303180545568466,\n",
|
822 |
+
" -0.07818872481584549,\n",
|
823 |
+
" 0.14000575244426727,\n",
|
824 |
+
" -0.07843434065580368,\n",
|
825 |
+
" 0.0474369153380394,\n",
|
826 |
+
" 0.021780453622341156,\n",
|
827 |
+
" 0.021539803594350815,\n",
|
828 |
+
" 0.1262277364730835,\n",
|
829 |
+
" 0.02580106630921364,\n",
|
830 |
+
" 0.022561756893992424,\n",
|
831 |
+
" -0.015236180275678635,\n",
|
832 |
+
" 0.13175277411937714,\n",
|
833 |
+
" 0.014995898120105267,\n",
|
834 |
+
" 0.014494264498353004,\n",
|
835 |
+
" -0.0018083483446389437,\n",
|
836 |
+
" -0.013143729418516159,\n",
|
837 |
+
" -0.049164507538080215,\n",
|
838 |
+
" -0.06190984323620796,\n",
|
839 |
+
" 0.021932406350970268,\n",
|
840 |
+
" -0.022566061466932297,\n",
|
841 |
+
" 0.024125924333930016,\n",
|
842 |
+
" 0.04778725281357765,\n",
|
843 |
+
" 0.001361499889753759,\n",
|
844 |
+
" -0.12093906104564667,\n",
|
845 |
+
" 0.013258987106382847,\n",
|
846 |
+
" -0.015382496640086174,\n",
|
847 |
+
" 0.028439369052648544,\n",
|
848 |
+
" -0.031059566885232925,\n",
|
849 |
+
" -0.014658545143902302,\n",
|
850 |
+
" -0.0164962001144886,\n",
|
851 |
+
" 0.023634258657693863,\n",
|
852 |
+
" -0.0965748280286789,\n",
|
853 |
+
" -0.038894761353731155,\n",
|
854 |
+
" -0.02935647778213024,\n",
|
855 |
+
" -0.031149519607424736,\n",
|
856 |
+
" -0.04675932228565216,\n",
|
857 |
+
" 0.01085135992616415,\n",
|
858 |
+
" -0.006681295111775398,\n",
|
859 |
+
" 0.030533554032444954,\n",
|
860 |
+
" -0.10486804693937302,\n",
|
861 |
+
" -0.005622635595500469,\n",
|
862 |
+
" -0.03426210954785347,\n",
|
863 |
+
" 0.014524451456964016,\n",
|
864 |
+
" -0.036871835589408875,\n",
|
865 |
+
" -0.03581416606903076,\n",
|
866 |
+
" -0.09492850303649902,\n",
|
867 |
+
" -0.05121384561061859,\n",
|
868 |
+
" 0.0863681212067604,\n",
|
869 |
+
" -0.02769472263753414,\n",
|
870 |
+
" -0.03255052864551544,\n",
|
871 |
+
" 0.03351925313472748,\n",
|
872 |
+
" -0.023608211427927017,\n",
|
873 |
+
" -0.0033292206935584545,\n",
|
874 |
+
" 0.03848697617650032,\n",
|
875 |
+
" -0.0116463303565979,\n",
|
876 |
+
" 0.012732136063277721,\n",
|
877 |
+
" 0.05946173891425133,\n",
|
878 |
+
" 0.03451535105705261,\n",
|
879 |
+
" 0.08603373914957047,\n",
|
880 |
+
" 0.025225210934877396,\n",
|
881 |
+
" -0.03410428389906883,\n",
|
882 |
+
" 0.01370932161808014,\n",
|
883 |
+
" 0.015575790777802467,\n",
|
884 |
+
" 0.03082992695271969,\n",
|
885 |
+
" -0.0181691013276577,\n",
|
886 |
+
" 0.0075484346598386765,\n",
|
887 |
+
" 0.00767799187451601,\n",
|
888 |
+
" -0.020997334271669388,\n",
|
889 |
+
" -0.01683652587234974,\n",
|
890 |
+
" -0.032185547053813934,\n",
|
891 |
+
" 0.06366591155529022,\n",
|
892 |
+
" 0.003027765080332756,\n",
|
893 |
+
" -0.01919621229171753,\n",
|
894 |
+
" 0.01796714961528778,\n",
|
895 |
+
" 0.030703270807862282,\n",
|
896 |
+
" -0.010722151026129723,\n",
|
897 |
+
" 0.0567406490445137,\n",
|
898 |
+
" 0.02326800301671028,\n",
|
899 |
+
" 0.029091518372297287,\n",
|
900 |
+
" 0.007758266758173704,\n",
|
901 |
+
" 0.06784671545028687,\n",
|
902 |
+
" 0.08166711777448654,\n",
|
903 |
+
" 0.047504521906375885,\n",
|
904 |
+
" -0.0262406338006258,\n",
|
905 |
+
" -0.042831819504499435,\n",
|
906 |
+
" -0.009907595813274384,\n",
|
907 |
+
" 0.006457660812884569,\n",
|
908 |
+
" 0.017302438616752625,\n",
|
909 |
+
" 0.030671026557683945,\n",
|
910 |
+
" -0.03801177814602852,\n",
|
911 |
+
" -1.6864364127400222e-08,\n",
|
912 |
+
" -0.08774770051240921,\n",
|
913 |
+
" 0.03914780169725418,\n",
|
914 |
+
" -0.007313665002584457,\n",
|
915 |
+
" 0.055220186710357666,\n",
|
916 |
+
" 0.03042862005531788,\n",
|
917 |
+
" 0.018359912559390068,\n",
|
918 |
+
" -0.08776683360338211,\n",
|
919 |
+
" -0.06734011322259903,\n",
|
920 |
+
" -0.0747460424900055,\n",
|
921 |
+
" -0.009306997992098331,\n",
|
922 |
+
" 0.03774425759911537,\n",
|
923 |
+
" 0.13193342089653015,\n",
|
924 |
+
" -0.08082900196313858,\n",
|
925 |
+
" 0.01321407500654459,\n",
|
926 |
+
" 0.048574961721897125,\n",
|
927 |
+
" 0.09028726816177368,\n",
|
928 |
+
" -0.029366280883550644,\n",
|
929 |
+
" 0.03968300297856331,\n",
|
930 |
+
" -0.0341360829770565,\n",
|
931 |
+
" 0.0035193762741982937,\n",
|
932 |
+
" -0.011343852616846561,\n",
|
933 |
+
" 0.009339207783341408,\n",
|
934 |
+
" 0.011233095079660416,\n",
|
935 |
+
" -0.06465622037649155,\n",
|
936 |
+
" 0.0345761775970459,\n",
|
937 |
+
" -0.09496650844812393,\n",
|
938 |
+
" -0.007475709542632103,\n",
|
939 |
+
" 0.003689560340717435,\n",
|
940 |
+
" 0.010514314286410809,\n",
|
941 |
+
" -0.06667248904705048,\n",
|
942 |
+
" 0.051605112850666046,\n",
|
943 |
+
" 0.10477923601865768,\n",
|
944 |
+
" -0.05478629842400551,\n",
|
945 |
+
" 0.021519236266613007,\n",
|
946 |
+
" -0.08572050929069519,\n",
|
947 |
+
" -0.027919678017497063,\n",
|
948 |
+
" 0.02723752148449421,\n",
|
949 |
+
" 0.09629359841346741,\n",
|
950 |
+
" 0.06709317862987518,\n",
|
951 |
+
" -0.07181668281555176,\n",
|
952 |
+
" -0.09750431030988693,\n",
|
953 |
+
" 0.04430799558758736,\n",
|
954 |
+
" -0.05396273732185364,\n",
|
955 |
+
" -0.10748161375522614,\n",
|
956 |
+
" -0.05498868227005005,\n",
|
957 |
+
" 0.03482293710112572,\n",
|
958 |
+
" 0.06672007590532303,\n",
|
959 |
+
" -0.05602458119392395,\n",
|
960 |
+
" 0.02175173908472061,\n",
|
961 |
+
" -0.06315217912197113,\n",
|
962 |
+
" -0.06730655580759048,\n",
|
963 |
+
" 0.03782231733202934,\n",
|
964 |
+
" 0.07897446304559708,\n",
|
965 |
+
" 0.002572576981037855,\n",
|
966 |
+
" 0.10580893605947495,\n",
|
967 |
+
" 0.09685958921909332,\n",
|
968 |
+
" 0.047380004078149796,\n",
|
969 |
+
" 0.03066212125122547,\n",
|
970 |
+
" -0.008867030031979084,\n",
|
971 |
+
" 0.06080889329314232,\n",
|
972 |
+
" 0.030900919809937477,\n",
|
973 |
+
" -0.030652379617094994,\n",
|
974 |
+
" 0.03755692020058632,\n",
|
975 |
+
" 0.03742789104580879]"
|
976 |
+
]
|
977 |
+
},
|
978 |
+
"execution_count": 25,
|
979 |
+
"metadata": {},
|
980 |
+
"output_type": "execute_result"
|
981 |
+
}
|
982 |
+
],
|
983 |
+
"source": [
|
984 |
+
"#query_result"
|
985 |
+
]
|
986 |
+
},
|
987 |
+
{
|
988 |
+
"cell_type": "code",
|
989 |
+
"execution_count": null,
|
990 |
+
"metadata": {},
|
991 |
+
"outputs": [],
|
992 |
+
"source": [
|
993 |
+
"import os\n",
|
994 |
+
"from pinecone import Pinecone\n",
|
995 |
+
"#Initializing the Pinecone\n",
|
996 |
+
"index_name=\"clare\"\n",
|
997 |
+
"pc=Pinecone(api_key=PINECONE_API_KEY)\n",
|
998 |
+
"index=pc.Index(\"clare\")\n"
|
999 |
+
]
|
1000 |
+
},
|
1001 |
+
{
|
1002 |
+
"cell_type": "code",
|
1003 |
+
"execution_count": null,
|
1004 |
+
"metadata": {},
|
1005 |
+
"outputs": [
|
1006 |
+
{
|
1007 |
+
"name": "stdout",
|
1008 |
+
"output_type": "stream",
|
1009 |
+
"text": [
|
1010 |
+
"Result: [Document(page_content='a'), Document(page_content='a'), Document(page_content='r')]\n"
|
1011 |
+
]
|
1012 |
+
}
|
1013 |
+
],
|
1014 |
+
"source": [
|
1015 |
+
"# After having my index, we can load it like this - \n",
|
1016 |
+
"from langchain_pinecone import PineconeVectorStore\n",
|
1017 |
+
"docsearch = PineconeVectorStore.from_existing_index(index_name, embeddings)\n",
|
1018 |
+
"\n",
|
1019 |
+
"query = \"What is a career?\"\n",
|
1020 |
+
"\n",
|
1021 |
+
"docs = docsearch.similarity_search(query=query, k=3)\n",
|
1022 |
+
"\n",
|
1023 |
+
"print(\"Result:\", docs)"
|
1024 |
+
]
|
1025 |
+
},
|
1026 |
+
{
|
1027 |
+
"cell_type": "code",
|
1028 |
+
"execution_count": null,
|
1029 |
+
"metadata": {},
|
1030 |
+
"outputs": [],
|
1031 |
+
"source": [
|
1032 |
+
"prompt_template = \"\"\"\n",
|
1033 |
+
"Use the following piece of information to answer the user's question.\n",
|
1034 |
+
"If you don't know the answer, just say that you don't know, don't try to generate any random answer from your own\n",
|
1035 |
+
"\n",
|
1036 |
+
"Context:{context}\n",
|
1037 |
+
"Question:{question}\n",
|
1038 |
+
"\n",
|
1039 |
+
"Only return the helpful answer and nothing else\n",
|
1040 |
+
"helpful answer:\n",
|
1041 |
+
"\"\"\""
|
1042 |
+
]
|
1043 |
+
},
|
1044 |
+
{
|
1045 |
+
"cell_type": "code",
|
1046 |
+
"execution_count": null,
|
1047 |
+
"metadata": {},
|
1048 |
+
"outputs": [],
|
1049 |
+
"source": [
|
1050 |
+
"PROMPT = PromptTemplate(template=prompt_template, input_variables=[\"context\",\"question\"])\n",
|
1051 |
+
"chain_type_kwargs = {\"prompt\":PROMPT}"
|
1052 |
+
]
|
1053 |
+
},
|
1054 |
+
{
|
1055 |
+
"cell_type": "code",
|
1056 |
+
"execution_count": null,
|
1057 |
+
"metadata": {},
|
1058 |
+
"outputs": [],
|
1059 |
+
"source": [
|
1060 |
+
"qa = RetrievalQA.from_chain_type(\n",
|
1061 |
+
" llm=llm,\n",
|
1062 |
+
" chain_type=\"stuff\",\n",
|
1063 |
+
" retriever= docsearch.as_retriever(search_kwargs={\"k\":2}),\n",
|
1064 |
+
" return_source_documents = True,\n",
|
1065 |
+
" chain_type_kwargs=chain_type_kwargs)"
|
1066 |
+
]
|
1067 |
+
},
|
1068 |
+
{
|
1069 |
+
"cell_type": "code",
|
1070 |
+
"execution_count": null,
|
1071 |
+
"metadata": {},
|
1072 |
+
"outputs": [
|
1073 |
+
{
|
1074 |
+
"name": "stdout",
|
1075 |
+
"output_type": "stream",
|
1076 |
+
"text": [
|
1077 |
+
"Collecting replicate\n",
|
1078 |
+
" Using cached replicate-0.26.0-py3-none-any.whl.metadata (24 kB)\n",
|
1079 |
+
"Requirement already satisfied: httpx<1,>=0.21.0 in c:\\users\\admin\\appdata\\roaming\\python\\python38\\site-packages (from replicate) (0.27.0)\n",
|
1080 |
+
"Requirement already satisfied: packaging in c:\\users\\admin\\appdata\\roaming\\python\\python38\\site-packages (from replicate) (23.2)\n",
|
1081 |
+
"Requirement already satisfied: pydantic>1.10.7 in c:\\users\\admin\\appdata\\roaming\\python\\python38\\site-packages (from replicate) (2.7.4)\n",
|
1082 |
+
"Requirement already satisfied: typing-extensions>=4.5.0 in c:\\programdata\\anaconda3\\envs\\myenv\\lib\\site-packages (from replicate) (4.11.0)\n",
|
1083 |
+
"Requirement already satisfied: anyio in c:\\users\\admin\\appdata\\roaming\\python\\python38\\site-packages (from httpx<1,>=0.21.0->replicate) (4.4.0)\n",
|
1084 |
+
"Requirement already satisfied: certifi in c:\\users\\admin\\appdata\\roaming\\python\\python38\\site-packages (from httpx<1,>=0.21.0->replicate) (2024.6.2)\n",
|
1085 |
+
"Requirement already satisfied: httpcore==1.* in c:\\users\\admin\\appdata\\roaming\\python\\python38\\site-packages (from httpx<1,>=0.21.0->replicate) (1.0.5)\n",
|
1086 |
+
"Requirement already satisfied: idna in c:\\users\\admin\\appdata\\roaming\\python\\python38\\site-packages (from httpx<1,>=0.21.0->replicate) (3.7)\n",
|
1087 |
+
"Requirement already satisfied: sniffio in c:\\users\\admin\\appdata\\roaming\\python\\python38\\site-packages (from httpx<1,>=0.21.0->replicate) (1.3.1)\n",
|
1088 |
+
"Requirement already satisfied: h11<0.15,>=0.13 in c:\\users\\admin\\appdata\\roaming\\python\\python38\\site-packages (from httpcore==1.*->httpx<1,>=0.21.0->replicate) (0.14.0)\n",
|
1089 |
+
"Requirement already satisfied: annotated-types>=0.4.0 in c:\\users\\admin\\appdata\\roaming\\python\\python38\\site-packages (from pydantic>1.10.7->replicate) (0.7.0)\n",
|
1090 |
+
"Requirement already satisfied: pydantic-core==2.18.4 in c:\\users\\admin\\appdata\\roaming\\python\\python38\\site-packages (from pydantic>1.10.7->replicate) (2.18.4)\n",
|
1091 |
+
"Requirement already satisfied: exceptiongroup>=1.0.2 in c:\\users\\admin\\appdata\\roaming\\python\\python38\\site-packages (from anyio->httpx<1,>=0.21.0->replicate) (1.2.1)\n",
|
1092 |
+
"Using cached replicate-0.26.0-py3-none-any.whl (40 kB)\n",
|
1093 |
+
"Installing collected packages: replicate\n",
|
1094 |
+
"Successfully installed replicate-0.26.0\n",
|
1095 |
+
"Note: you may need to restart the kernel to use updated packages.\n"
|
1096 |
+
]
|
1097 |
+
}
|
1098 |
+
],
|
1099 |
+
"source": [
|
1100 |
+
"pip install replicate"
|
1101 |
+
]
|
1102 |
+
},
|
1103 |
+
{
|
1104 |
+
"cell_type": "code",
|
1105 |
+
"execution_count": null,
|
1106 |
+
"metadata": {},
|
1107 |
+
"outputs": [],
|
1108 |
+
"source": [
|
1109 |
+
"import replicate"
|
1110 |
+
]
|
1111 |
+
},
|
1112 |
+
{
|
1113 |
+
"cell_type": "code",
|
1114 |
+
"execution_count": null,
|
1115 |
+
"metadata": {},
|
1116 |
+
"outputs": [
|
1117 |
+
{
|
1118 |
+
"name": "stdout",
|
1119 |
+
"output_type": "stream",
|
1120 |
+
"text": [
|
1121 |
+
"Response: A career refers to a sequence of work-related experiences and roles that a person takes up in their life. It can include various positions, jobs, or professions that a person has held over time. A career can also include various skills, education, and training that a person has acquired to achieve their goals. A career is often associated with personal growth, development, and fulfillment. It can also be influenced by factors such as job satisfaction, work-life balance, and career advancement opportunities. more\n",
|
1122 |
+
"career: a sequence of work-related experiences and roles that a person takes up in their life. more\n",
|
1123 |
+
"a career is a sequence of work\n",
|
1124 |
+
"Response: The requirements of medicine are:\n",
|
1125 |
+
"1. Potency: The medicine should have the required potency to produce the desired therapeutic effect.\n",
|
1126 |
+
"2. Safety: The medicine should be safe for use and should not cause any harm to the patient.\n",
|
1127 |
+
"3. Efficacy: The medicine should be able to produce the desired therapeutic effect in a reasonable amount of time.\n",
|
1128 |
+
"4. Stability: The medicine should be stable and should not degrade over time.\n",
|
1129 |
+
"5. Bioavailability: The medicine should be bioavailable and should be able to be absorbed by the body.\n",
|
1130 |
+
"6. Shelf life: The medicine should have a reasonable shelf life and should not expire too quickly.\n",
|
1131 |
+
"\n"
|
1132 |
+
]
|
1133 |
+
}
|
1134 |
+
],
|
1135 |
+
"source": [
|
1136 |
+
"while True:\n",
|
1137 |
+
" user_input = input(f\"Input Prompt: \")\n",
|
1138 |
+
" result = qa({\"query\":user_input})\n",
|
1139 |
+
" print(\"Response:\", result[\"result\"])"
|
1140 |
+
]
|
1141 |
+
}
|
1142 |
+
],
|
1143 |
+
"metadata": {
|
1144 |
+
"kernelspec": {
|
1145 |
+
"display_name": "medchatbot",
|
1146 |
+
"language": "python",
|
1147 |
+
"name": "python3"
|
1148 |
+
},
|
1149 |
+
"language_info": {
|
1150 |
+
"codemirror_mode": {
|
1151 |
+
"name": "ipython",
|
1152 |
+
"version": 3
|
1153 |
+
},
|
1154 |
+
"file_extension": ".py",
|
1155 |
+
"mimetype": "text/x-python",
|
1156 |
+
"name": "python",
|
1157 |
+
"nbconvert_exporter": "python",
|
1158 |
+
"pygments_lexer": "ipython3",
|
1159 |
+
"version": "3.8.19"
|
1160 |
+
}
|
1161 |
+
},
|
1162 |
+
"nbformat": 4,
|
1163 |
+
"nbformat_minor": 2
|
1164 |
+
}
|
setup.py
ADDED
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from setuptools import find_packages, setup
|
2 |
+
|
3 |
+
setup(
|
4 |
+
name = 'Career Chatbot',
|
5 |
+
version= '0.0.0',
|
6 |
+
author= 'Shirlyn and Earvin',
|
7 |
+
author_email= 'shirlynngure@gmail.com',
|
8 |
+
packages= find_packages(),
|
9 |
+
install_requires = []
|
10 |
+
|
11 |
+
)
|
src/__init__.py
ADDED
File without changes
|
src/__pycache__/__init__.cpython-38.pyc
ADDED
Binary file (134 Bytes). View file
|
|
src/__pycache__/helper.cpython-38.pyc
ADDED
Binary file (993 Bytes). View file
|
|
src/__pycache__/prompt.cpython-38.pyc
ADDED
Binary file (432 Bytes). View file
|
|
src/helper.py
ADDED
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from langchain.document_loaders import PyPDFLoader, DirectoryLoader
|
2 |
+
from langchain.text_splitter import RecursiveCharacterTextSplitter
|
3 |
+
from langchain.embeddings import HuggingFaceEmbeddings
|
4 |
+
|
5 |
+
|
6 |
+
#Extract data from the PDF
|
7 |
+
def load_pdf(data):
|
8 |
+
loader = DirectoryLoader(data,
|
9 |
+
glob="*.pdf",
|
10 |
+
loader_cls=PyPDFLoader)
|
11 |
+
|
12 |
+
documents = loader.load()
|
13 |
+
|
14 |
+
return documents
|
15 |
+
|
16 |
+
|
17 |
+
|
18 |
+
#Create text chunks
|
19 |
+
def text_split(extracted_data):
|
20 |
+
text_splitter = RecursiveCharacterTextSplitter(chunk_size = 500, chunk_overlap = 20)
|
21 |
+
text_chunks = text_splitter.split_documents(extracted_data)
|
22 |
+
|
23 |
+
return text_chunks
|
24 |
+
|
25 |
+
|
26 |
+
|
27 |
+
#download embedding model
|
28 |
+
def download_hugging_face_embeddings():
|
29 |
+
embeddings = HuggingFaceEmbeddings(model_name="sentence-transformers/all-MiniLM-L6-v2")
|
30 |
+
return embeddings
|
src/prompt.py
ADDED
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
prompt_template="""
|
2 |
+
Use the following pieces of information to answer the user's question.
|
3 |
+
If you don't know the answer, just say that you don't know, don't try to make up an answer.
|
4 |
+
|
5 |
+
Context: {context}
|
6 |
+
Question: {question}
|
7 |
+
|
8 |
+
Only return the helpful answer below and nothing else.
|
9 |
+
Helpful answer:
|
10 |
+
"""
|
static/.gitkeep
ADDED
File without changes
|
static/style.css
ADDED
@@ -0,0 +1,223 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
body,html{
|
2 |
+
height: 100%;
|
3 |
+
margin: 0;
|
4 |
+
background: rgb(44, 47, 59);
|
5 |
+
background: -webkit-linear-gradient(to right, rgb(40, 59, 34), rgb(54, 60, 70), rgb(32, 32, 43));
|
6 |
+
background: linear-gradient(to right, rgb(38, 51, 61), rgb(50, 55, 65), rgb(33, 33, 78));
|
7 |
+
}
|
8 |
+
|
9 |
+
.chat{
|
10 |
+
margin-top: auto;
|
11 |
+
margin-bottom: auto;
|
12 |
+
}
|
13 |
+
.card{
|
14 |
+
height: 500px;
|
15 |
+
border-radius: 15px !important;
|
16 |
+
background-color: rgba(0,0,0,0.4) !important;
|
17 |
+
}
|
18 |
+
.contacts_body{
|
19 |
+
padding: 0.75rem 0 !important;
|
20 |
+
overflow-y: auto;
|
21 |
+
white-space: nowrap;
|
22 |
+
}
|
23 |
+
.msg_card_body{
|
24 |
+
overflow-y: auto;
|
25 |
+
}
|
26 |
+
.card-header{
|
27 |
+
border-radius: 15px 15px 0 0 !important;
|
28 |
+
border-bottom: 0 !important;
|
29 |
+
}
|
30 |
+
.card-footer{
|
31 |
+
border-radius: 0 0 15px 15px !important;
|
32 |
+
border-top: 0 !important;
|
33 |
+
}
|
34 |
+
.container{
|
35 |
+
align-content: center;
|
36 |
+
}
|
37 |
+
.search{
|
38 |
+
border-radius: 15px 0 0 15px !important;
|
39 |
+
background-color: rgba(0,0,0,0.3) !important;
|
40 |
+
border:0 !important;
|
41 |
+
color:white !important;
|
42 |
+
}
|
43 |
+
.search:focus{
|
44 |
+
box-shadow:none !important;
|
45 |
+
outline:0px !important;
|
46 |
+
}
|
47 |
+
.type_msg{
|
48 |
+
background-color: rgba(0,0,0,0.3) !important;
|
49 |
+
border:0 !important;
|
50 |
+
color:white !important;
|
51 |
+
height: 60px !important;
|
52 |
+
overflow-y: auto;
|
53 |
+
}
|
54 |
+
.type_msg:focus{
|
55 |
+
box-shadow:none !important;
|
56 |
+
outline:0px !important;
|
57 |
+
}
|
58 |
+
.attach_btn{
|
59 |
+
border-radius: 15px 0 0 15px !important;
|
60 |
+
background-color: rgba(0,0,0,0.3) !important;
|
61 |
+
border:0 !important;
|
62 |
+
color: white !important;
|
63 |
+
cursor: pointer;
|
64 |
+
}
|
65 |
+
.send_btn{
|
66 |
+
border-radius: 0 15px 15px 0 !important;
|
67 |
+
background-color: rgba(0,0,0,0.3) !important;
|
68 |
+
border:0 !important;
|
69 |
+
color: white !important;
|
70 |
+
cursor: pointer;
|
71 |
+
}
|
72 |
+
.search_btn{
|
73 |
+
border-radius: 0 15px 15px 0 !important;
|
74 |
+
background-color: rgba(0,0,0,0.3) !important;
|
75 |
+
border:0 !important;
|
76 |
+
color: white !important;
|
77 |
+
cursor: pointer;
|
78 |
+
}
|
79 |
+
.contacts{
|
80 |
+
list-style: none;
|
81 |
+
padding: 0;
|
82 |
+
}
|
83 |
+
.contacts li{
|
84 |
+
width: 100% !important;
|
85 |
+
padding: 5px 10px;
|
86 |
+
margin-bottom: 15px !important;
|
87 |
+
}
|
88 |
+
.active{
|
89 |
+
background-color: rgba(0,0,0,0.3);
|
90 |
+
}
|
91 |
+
.user_img{
|
92 |
+
height: 70px;
|
93 |
+
width: 70px;
|
94 |
+
border:1.5px solid #f5f6fa;
|
95 |
+
|
96 |
+
}
|
97 |
+
.user_img_msg{
|
98 |
+
height: 40px;
|
99 |
+
width: 40px;
|
100 |
+
border:1.5px solid #f5f6fa;
|
101 |
+
|
102 |
+
}
|
103 |
+
.img_cont{
|
104 |
+
position: relative;
|
105 |
+
height: 70px;
|
106 |
+
width: 70px;
|
107 |
+
}
|
108 |
+
.img_cont_msg{
|
109 |
+
height: 40px;
|
110 |
+
width: 40px;
|
111 |
+
}
|
112 |
+
.online_icon{
|
113 |
+
position: absolute;
|
114 |
+
height: 15px;
|
115 |
+
width:15px;
|
116 |
+
background-color: #4cd137;
|
117 |
+
border-radius: 50%;
|
118 |
+
bottom: 0.2em;
|
119 |
+
right: 0.4em;
|
120 |
+
border:1.5px solid white;
|
121 |
+
}
|
122 |
+
.offline{
|
123 |
+
background-color: #c23616 !important;
|
124 |
+
}
|
125 |
+
.user_info{
|
126 |
+
margin-top: auto;
|
127 |
+
margin-bottom: auto;
|
128 |
+
margin-left: 15px;
|
129 |
+
}
|
130 |
+
.user_info span{
|
131 |
+
font-size: 20px;
|
132 |
+
color: white;
|
133 |
+
}
|
134 |
+
.user_info p{
|
135 |
+
font-size: 10px;
|
136 |
+
color: rgba(255,255,255,0.6);
|
137 |
+
}
|
138 |
+
.video_cam{
|
139 |
+
margin-left: 50px;
|
140 |
+
margin-top: 5px;
|
141 |
+
}
|
142 |
+
.video_cam span{
|
143 |
+
color: white;
|
144 |
+
font-size: 20px;
|
145 |
+
cursor: pointer;
|
146 |
+
margin-right: 20px;
|
147 |
+
}
|
148 |
+
.msg_cotainer{
|
149 |
+
margin-top: auto;
|
150 |
+
margin-bottom: auto;
|
151 |
+
margin-left: 10px;
|
152 |
+
border-radius: 25px;
|
153 |
+
background-color: rgb(82, 172, 255);
|
154 |
+
padding: 10px;
|
155 |
+
position: relative;
|
156 |
+
}
|
157 |
+
.msg_cotainer_send{
|
158 |
+
margin-top: auto;
|
159 |
+
margin-bottom: auto;
|
160 |
+
margin-right: 10px;
|
161 |
+
border-radius: 25px;
|
162 |
+
background-color: #58cc71;
|
163 |
+
padding: 10px;
|
164 |
+
position: relative;
|
165 |
+
}
|
166 |
+
.msg_time{
|
167 |
+
position: absolute;
|
168 |
+
left: 0;
|
169 |
+
bottom: -15px;
|
170 |
+
color: rgba(255,255,255,0.5);
|
171 |
+
font-size: 10px;
|
172 |
+
}
|
173 |
+
.msg_time_send{
|
174 |
+
position: absolute;
|
175 |
+
right:0;
|
176 |
+
bottom: -15px;
|
177 |
+
color: rgba(255,255,255,0.5);
|
178 |
+
font-size: 10px;
|
179 |
+
}
|
180 |
+
.msg_head{
|
181 |
+
position: relative;
|
182 |
+
}
|
183 |
+
#action_menu_btn{
|
184 |
+
position: absolute;
|
185 |
+
right: 10px;
|
186 |
+
top: 10px;
|
187 |
+
color: white;
|
188 |
+
cursor: pointer;
|
189 |
+
font-size: 20px;
|
190 |
+
}
|
191 |
+
.action_menu{
|
192 |
+
z-index: 1;
|
193 |
+
position: absolute;
|
194 |
+
padding: 15px 0;
|
195 |
+
background-color: rgba(0,0,0,0.5);
|
196 |
+
color: white;
|
197 |
+
border-radius: 15px;
|
198 |
+
top: 30px;
|
199 |
+
right: 15px;
|
200 |
+
display: none;
|
201 |
+
}
|
202 |
+
.action_menu ul{
|
203 |
+
list-style: none;
|
204 |
+
padding: 0;
|
205 |
+
margin: 0;
|
206 |
+
}
|
207 |
+
.action_menu ul li{
|
208 |
+
width: 100%;
|
209 |
+
padding: 10px 15px;
|
210 |
+
margin-bottom: 5px;
|
211 |
+
}
|
212 |
+
.action_menu ul li i{
|
213 |
+
padding-right: 10px;
|
214 |
+
}
|
215 |
+
.action_menu ul li:hover{
|
216 |
+
cursor: pointer;
|
217 |
+
background-color: rgba(0,0,0,0.2);
|
218 |
+
}
|
219 |
+
@media(max-width: 576px){
|
220 |
+
.contacts_card{
|
221 |
+
margin-bottom: 15px !important;
|
222 |
+
}
|
223 |
+
}
|
store_index.py
ADDED
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from src.helper import load_pdf, text_split, download_hugging_face_embeddings
|
2 |
+
from langchain.vectorstores import Pinecone
|
3 |
+
import pinecone
|
4 |
+
from pinecone import Pinecone
|
5 |
+
from dotenv import load_dotenv
|
6 |
+
import os
|
7 |
+
from langchain_pinecone import PineconeVectorStore
|
8 |
+
|
9 |
+
load_dotenv()
|
10 |
+
|
11 |
+
PINECONE_API_KEY = os.environ.get('PINECONE_API_KEY')
|
12 |
+
PINECONE_API_ENV = os.environ.get('PINECONE_API_ENV')
|
13 |
+
|
14 |
+
# print(PINECONE_API_KEY)
|
15 |
+
# print(PINECONE_API_ENV)
|
16 |
+
|
17 |
+
extracted_data = load_pdf("data/")
|
18 |
+
text_chunks = text_split(extracted_data)
|
19 |
+
embeddings = download_hugging_face_embeddings()
|
20 |
+
|
21 |
+
|
22 |
+
#Initializing the Pinecone
|
23 |
+
index_name="clare"
|
24 |
+
pc=Pinecone(api_key=PINECONE_API_KEY)
|
25 |
+
index=pc.Index("clare")
|
26 |
+
|
27 |
+
#Creating Embeddings for Each of The Text Chunks & storing
|
28 |
+
docsearch = PineconeVectorStore.from_existing_index(index_name, embeddings)
|
template.py
ADDED
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
from pathlib import Path
|
3 |
+
import logging
|
4 |
+
|
5 |
+
logging.basicConfig(level=logging.INFO, format='[%(asctime)s]:%(message)s:')
|
6 |
+
|
7 |
+
list_of_files = [
|
8 |
+
"src/__init__.py",
|
9 |
+
"src/helper.py",
|
10 |
+
"src/prompt.py",
|
11 |
+
".env",
|
12 |
+
"setup.py",
|
13 |
+
"research/trials.ipynb",
|
14 |
+
"app.py",
|
15 |
+
"store_index.py",
|
16 |
+
"static/.gitkeep",
|
17 |
+
"templates/chat.html"
|
18 |
+
|
19 |
+
]
|
20 |
+
|
21 |
+
|
22 |
+
for filepath in list_of_files:
|
23 |
+
filepath=Path(filepath)
|
24 |
+
filedir,filename =os.path.split(filepath)
|
25 |
+
if filedir !="":
|
26 |
+
os.makedirs(filedir,exist_ok=True)
|
27 |
+
logging.info(f"Creating directory;{filedir}for the file {filename}")
|
28 |
+
if (not os.path.exists(filepath)) or (os.path.getsize(filename)==0):
|
29 |
+
with open(filepath,'w') as f:
|
30 |
+
pass
|
31 |
+
logging.info(f"Creating empty file:{filepath}")
|
32 |
+
else:
|
33 |
+
logging.info(f"{filename}is already created")
|
templates/chat.html
ADDED
@@ -0,0 +1,82 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
|
2 |
+
<link href="//maxcdn.bootstrapcdn.com/bootstrap/4.1.1/css/bootstrap.min.css" rel="stylesheet" id="bootstrap-css">
|
3 |
+
<script src="//maxcdn.bootstrapcdn.com/bootstrap/4.1.1/js/bootstrap.min.js"></script>
|
4 |
+
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
|
5 |
+
|
6 |
+
<!DOCTYPE html>
|
7 |
+
<html>
|
8 |
+
<head>
|
9 |
+
<title>Chatbot</title>
|
10 |
+
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">
|
11 |
+
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.5.0/css/all.css" integrity="sha384-B4dIYHKNBt8Bc12p+WXckhzcICo0wtJAoU8YZTY5qE0Id1GSseTk6S+L3BlXeVIU" crossorigin="anonymous">
|
12 |
+
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
|
13 |
+
<link rel="stylesheet" type="text/css" href="{{ url_for('static', filename='style.css')}}"/>
|
14 |
+
</head>
|
15 |
+
|
16 |
+
|
17 |
+
<body>
|
18 |
+
<div class="container-fluid h-100">
|
19 |
+
<div class="row justify-content-center h-100">
|
20 |
+
<div class="col-md-8 col-xl-6 chat">
|
21 |
+
<div class="card">
|
22 |
+
<div class="card-header msg_head">
|
23 |
+
<div class="d-flex bd-highlight">
|
24 |
+
<div class="img_cont">
|
25 |
+
<!-- <img src="https://i.ibb.co/fSNP7Rz/icons8-chatgpt-512.png" class="rounded-circle user_img"> -->
|
26 |
+
<img src="https://www.prdistribution.com/spirit/uploads/pressreleases/2019/newsreleases/d83341deb75c4c4f6b113f27b1e42cd8-chatbot-florence-already-helps-thousands-of-patients-to-remember-their-medication.png" class="rounded-circle user_img">
|
27 |
+
<span class="online_icon"></span>
|
28 |
+
</div>
|
29 |
+
<div class="user_info">
|
30 |
+
<span>Career Chatbot</span>
|
31 |
+
<p>Ask me anything!</p>
|
32 |
+
</div>
|
33 |
+
</div>
|
34 |
+
</div>
|
35 |
+
<div id="messageFormeight" class="card-body msg_card_body">
|
36 |
+
|
37 |
+
|
38 |
+
</div>
|
39 |
+
<div class="card-footer">
|
40 |
+
<form id="messageArea" class="input-group">
|
41 |
+
<input type="text" id="text" name="msg" placeholder="Type your message..." autocomplete="off" class="form-control type_msg" required/>
|
42 |
+
<div class="input-group-append">
|
43 |
+
<button type="submit" id="send" class="input-group-text send_btn"><i class="fas fa-location-arrow"></i></button>
|
44 |
+
</div>
|
45 |
+
</form>
|
46 |
+
</div>
|
47 |
+
</div>
|
48 |
+
</div>
|
49 |
+
</div>
|
50 |
+
</div>
|
51 |
+
|
52 |
+
<script>
|
53 |
+
$(document).ready(function() {
|
54 |
+
$("#messageArea").on("submit", function(event) {
|
55 |
+
const date = new Date();
|
56 |
+
const hour = date.getHours();
|
57 |
+
const minute = date.getMinutes();
|
58 |
+
const str_time = hour+":"+minute;
|
59 |
+
var rawText = $("#text").val();
|
60 |
+
|
61 |
+
var userHtml = '<div class="d-flex justify-content-end mb-4"><div class="msg_cotainer_send">' + rawText + '<span class="msg_time_send">'+ str_time + '</span></div><div class="img_cont_msg"><img src="https://i.ibb.co/d5b84Xw/Untitled-design.png" class="rounded-circle user_img_msg"></div></div>';
|
62 |
+
|
63 |
+
$("#text").val("");
|
64 |
+
$("#messageFormeight").append(userHtml);
|
65 |
+
|
66 |
+
$.ajax({
|
67 |
+
data: {
|
68 |
+
msg: rawText,
|
69 |
+
},
|
70 |
+
type: "POST",
|
71 |
+
url: "/get",
|
72 |
+
}).done(function(data) {
|
73 |
+
var botHtml = '<div class="d-flex justify-content-start mb-4"><div class="img_cont_msg"><img src="https://www.prdistribution.com/spirit/uploads/pressreleases/2019/newsreleases/d83341deb75c4c4f6b113f27b1e42cd8-chatbot-florence-already-helps-thousands-of-patients-to-remember-their-medication.png" class="rounded-circle user_img_msg"></div><div class="msg_cotainer">' + data + '<span class="msg_time">' + str_time + '</span></div></div>';
|
74 |
+
$("#messageFormeight").append($.parseHTML(botHtml));
|
75 |
+
});
|
76 |
+
event.preventDefault();
|
77 |
+
});
|
78 |
+
});
|
79 |
+
</script>
|
80 |
+
|
81 |
+
</body>
|
82 |
+
</html>
|