Update app.py
Browse files
app.py
CHANGED
@@ -16,7 +16,7 @@ def read_doc(directory):
|
|
16 |
documents=file_loader.load()
|
17 |
return documents
|
18 |
|
19 |
-
doc=read_doc('documents/')
|
20 |
len(doc)
|
21 |
|
22 |
## Divide the docs into chunks
|
@@ -26,7 +26,7 @@ def chunk_data(docs,chunk_size=800,chunk_overlap=50):
|
|
26 |
doc=text_splitter.split_documents(docs)
|
27 |
return docs
|
28 |
|
29 |
-
documents=chunk_data(docs=doc)
|
30 |
len(documents)
|
31 |
|
32 |
embeddings=OpenAIEmbeddings(api_key=os.environ['OPENAI_API_KEY'])
|
@@ -36,10 +36,10 @@ vectors=embeddings.embed_query("How are you?")
|
|
36 |
len(vectors)
|
37 |
|
38 |
pinecone.init(
|
39 |
-
api_key="
|
40 |
environment="gcp-starter"
|
41 |
)
|
42 |
-
index_name="
|
43 |
|
44 |
index=Pinecone.from_documents(doc,embeddings,index_name=index_name)
|
45 |
|
@@ -62,6 +62,6 @@ def retrieve_answers(query):
|
|
62 |
return response
|
63 |
|
64 |
|
65 |
-
our_query = "
|
66 |
answer = retrieve_answers(our_query)
|
67 |
print(answer)
|
|
|
16 |
documents=file_loader.load()
|
17 |
return documents
|
18 |
|
19 |
+
doc=read_doc('documents/') #PDF directory
|
20 |
len(doc)
|
21 |
|
22 |
## Divide the docs into chunks
|
|
|
26 |
doc=text_splitter.split_documents(docs)
|
27 |
return docs
|
28 |
|
29 |
+
documents=chunk_data(docs=doc) #Fnct that divides the PDF into chuncks
|
30 |
len(documents)
|
31 |
|
32 |
embeddings=OpenAIEmbeddings(api_key=os.environ['OPENAI_API_KEY'])
|
|
|
36 |
len(vectors)
|
37 |
|
38 |
pinecone.init(
|
39 |
+
api_key="3cdc872c-aecc-4b11-93d6-b5243930ac3a",
|
40 |
environment="gcp-starter"
|
41 |
)
|
42 |
+
index_name="knowledgebase"
|
43 |
|
44 |
index=Pinecone.from_documents(doc,embeddings,index_name=index_name)
|
45 |
|
|
|
62 |
return response
|
63 |
|
64 |
|
65 |
+
our_query = "What is my name?"
|
66 |
answer = retrieve_answers(our_query)
|
67 |
print(answer)
|