Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -2,7 +2,7 @@
|
|
2 |
|
3 |
import streamlit as st
|
4 |
from dotenv import load_dotenv
|
5 |
-
import pickle
|
6 |
from PyPDF2 import PdfReader
|
7 |
from langchain.text_splitter import RecursiveCharacterTextSplitter
|
8 |
from langchain.embeddings.openai import OpenAIEmbeddings
|
@@ -11,7 +11,10 @@ from langchain.llms import OpenAI
|
|
11 |
from langchain.chains.question_answering import load_qa_chain
|
12 |
from langchain.callbacks import get_openai_callback
|
13 |
import os
|
14 |
-
load_dotenv()
|
|
|
|
|
|
|
15 |
|
16 |
## Reading the PDF
|
17 |
|
@@ -41,7 +44,7 @@ if pdf is not None:
|
|
41 |
## Create Embeddings of each chunk of data and store them in the Vector DB
|
42 |
|
43 |
store_name = pdf.name[:-4] # extract the pdf name
|
44 |
-
embeddings = OpenAIEmbeddings(openai_api_key =
|
45 |
|
46 |
if os.path.exists(f"{store_name}"): # if already the vector db is present then load it
|
47 |
#path = f"{store_name}\index.pkl"
|
@@ -63,7 +66,7 @@ if pdf is not None:
|
|
63 |
if query:
|
64 |
docs = VectorStore.similarity_search(query=query, k=3)
|
65 |
|
66 |
-
llm = OpenAI()
|
67 |
chain = load_qa_chain(llm=llm, chain_type="stuff")
|
68 |
with get_openai_callback() as cb:
|
69 |
response = chain.run(input_documents=docs, question=query)
|
|
|
2 |
|
3 |
import streamlit as st
|
4 |
from dotenv import load_dotenv
|
5 |
+
#import pickle
|
6 |
from PyPDF2 import PdfReader
|
7 |
from langchain.text_splitter import RecursiveCharacterTextSplitter
|
8 |
from langchain.embeddings.openai import OpenAIEmbeddings
|
|
|
11 |
from langchain.chains.question_answering import load_qa_chain
|
12 |
from langchain.callbacks import get_openai_callback
|
13 |
import os
|
14 |
+
#load_dotenv()
|
15 |
+
|
16 |
+
|
17 |
+
api_key = os.getenv("OpenAI_API_KEY")
|
18 |
|
19 |
## Reading the PDF
|
20 |
|
|
|
44 |
## Create Embeddings of each chunk of data and store them in the Vector DB
|
45 |
|
46 |
store_name = pdf.name[:-4] # extract the pdf name
|
47 |
+
embeddings = OpenAIEmbeddings(openai_api_key = api_key) # using OpenAI to create embeddings
|
48 |
|
49 |
if os.path.exists(f"{store_name}"): # if already the vector db is present then load it
|
50 |
#path = f"{store_name}\index.pkl"
|
|
|
66 |
if query:
|
67 |
docs = VectorStore.similarity_search(query=query, k=3)
|
68 |
|
69 |
+
llm = OpenAI(openai_api_key = api_key)
|
70 |
chain = load_qa_chain(llm=llm, chain_type="stuff")
|
71 |
with get_openai_callback() as cb:
|
72 |
response = chain.run(input_documents=docs, question=query)
|