Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -18,6 +18,7 @@ def load_pdf_and_generate_embeddings(pdf_doc, open_ai_key, relevant_pages):
|
|
| 18 |
#Load the pdf file
|
| 19 |
loader = OnlinePDFLoader(pdf_doc.name)
|
| 20 |
pages = loader.load_and_split()
|
|
|
|
| 21 |
|
| 22 |
#Create an instance of OpenAIEmbeddings, which is responsible for generating embeddings for text
|
| 23 |
embeddings = OpenAIEmbeddings()
|
|
@@ -35,10 +36,12 @@ def load_pdf_and_generate_embeddings(pdf_doc, open_ai_key, relevant_pages):
|
|
| 35 |
#In the scenario where none of the page numbers supplied exist in the PDF, we will revert to using the entire PDF.
|
| 36 |
if len(pages_to_be_loaded) ==0:
|
| 37 |
pages_to_be_loaded = pages.copy()
|
|
|
|
| 38 |
|
| 39 |
|
| 40 |
#To create a vector store, we use the Chroma class, which takes the documents (pages in our case) and the embeddings instance
|
| 41 |
vectordb = Chroma.from_documents(pages_to_be_loaded, embedding=embeddings)
|
|
|
|
| 42 |
|
| 43 |
#Finally, we create the bot using the RetrievalQA class
|
| 44 |
global pdf_qa
|
|
@@ -55,7 +58,7 @@ def load_pdf_and_generate_embeddings(pdf_doc, open_ai_key, relevant_pages):
|
|
| 55 |
|
| 56 |
chain_type_kwargs = {"prompt": PROMPT}
|
| 57 |
pdf_qa = RetrievalQA.from_chain_type(llm=ChatOpenAI(temperature=0, model_name="gpt-4"),chain_type="stuff", retriever=vectordb.as_retriever(search_kwargs={"k": 4}), chain_type_kwargs=chain_type_kwargs, return_source_documents=False)
|
| 58 |
-
|
| 59 |
return "Ready"
|
| 60 |
else:
|
| 61 |
return "Please provide an OpenAI gpt-4 API key"
|
|
|
|
| 18 |
#Load the pdf file
|
| 19 |
loader = OnlinePDFLoader(pdf_doc.name)
|
| 20 |
pages = loader.load_and_split()
|
| 21 |
+
print("PDF has been loaded and split")
|
| 22 |
|
| 23 |
#Create an instance of OpenAIEmbeddings, which is responsible for generating embeddings for text
|
| 24 |
embeddings = OpenAIEmbeddings()
|
|
|
|
| 36 |
#In the scenario where none of the page numbers supplied exist in the PDF, we will revert to using the entire PDF.
|
| 37 |
if len(pages_to_be_loaded) ==0:
|
| 38 |
pages_to_be_loaded = pages.copy()
|
| 39 |
+
print(len(pages_to_be_loaded))
|
| 40 |
|
| 41 |
|
| 42 |
#To create a vector store, we use the Chroma class, which takes the documents (pages in our case) and the embeddings instance
|
| 43 |
vectordb = Chroma.from_documents(pages_to_be_loaded, embedding=embeddings)
|
| 44 |
+
print("Vectordb has been created")
|
| 45 |
|
| 46 |
#Finally, we create the bot using the RetrievalQA class
|
| 47 |
global pdf_qa
|
|
|
|
| 58 |
|
| 59 |
chain_type_kwargs = {"prompt": PROMPT}
|
| 60 |
pdf_qa = RetrievalQA.from_chain_type(llm=ChatOpenAI(temperature=0, model_name="gpt-4"),chain_type="stuff", retriever=vectordb.as_retriever(search_kwargs={"k": 4}), chain_type_kwargs=chain_type_kwargs, return_source_documents=False)
|
| 61 |
+
print("GPT-4 is ready to take questions!")
|
| 62 |
return "Ready"
|
| 63 |
else:
|
| 64 |
return "Please provide an OpenAI gpt-4 API key"
|