Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -17,20 +17,20 @@ def load_pdf(file):
|
|
17 |
|
18 |
# Summarization function using GPT-4
|
19 |
def summarize_pdf(file, openai_api_key):
|
20 |
-
# Set the API key dynamically
|
21 |
openai.api_key = openai_api_key
|
22 |
|
23 |
# Load and process the PDF
|
24 |
documents = load_pdf(file)
|
25 |
|
26 |
# Create embeddings for the documents
|
27 |
-
embeddings = OpenAIEmbeddings()
|
28 |
|
29 |
# Use LangChain's FAISS Vector Store to store and search the embeddings
|
30 |
vector_store = FAISS.from_documents(documents, embeddings)
|
31 |
|
32 |
# Create a RetrievalQA chain for summarization
|
33 |
-
llm = ChatOpenAI(model="gpt-
|
34 |
qa_chain = RetrievalQA.from_chain_type(
|
35 |
llm=llm,
|
36 |
chain_type="stuff",
|
@@ -43,14 +43,14 @@ def summarize_pdf(file, openai_api_key):
|
|
43 |
|
44 |
# Function to handle user queries and provide answers from the document
|
45 |
def query_pdf(file, user_query, openai_api_key):
|
46 |
-
# Set the API key dynamically
|
47 |
openai.api_key = openai_api_key
|
48 |
|
49 |
# Load and process the PDF
|
50 |
documents = load_pdf(file)
|
51 |
|
52 |
# Create embeddings for the documents
|
53 |
-
embeddings = OpenAIEmbeddings()
|
54 |
|
55 |
# Use LangChain's FAISS Vector Store to store and search the embeddings
|
56 |
vector_store = FAISS.from_documents(documents, embeddings)
|
|
|
17 |
|
18 |
# Summarization function using GPT-4
|
19 |
def summarize_pdf(file, openai_api_key):
|
20 |
+
# Set the OpenAI API key dynamically
|
21 |
openai.api_key = openai_api_key
|
22 |
|
23 |
# Load and process the PDF
|
24 |
documents = load_pdf(file)
|
25 |
|
26 |
# Create embeddings for the documents
|
27 |
+
embeddings = OpenAIEmbeddings(openai_api_key=openai_api_key)
|
28 |
|
29 |
# Use LangChain's FAISS Vector Store to store and search the embeddings
|
30 |
vector_store = FAISS.from_documents(documents, embeddings)
|
31 |
|
32 |
# Create a RetrievalQA chain for summarization
|
33 |
+
llm = ChatOpenAI(model="gpt-4") # Using GPT-4 as the LLM
|
34 |
qa_chain = RetrievalQA.from_chain_type(
|
35 |
llm=llm,
|
36 |
chain_type="stuff",
|
|
|
43 |
|
44 |
# Function to handle user queries and provide answers from the document
|
45 |
def query_pdf(file, user_query, openai_api_key):
|
46 |
+
# Set the OpenAI API key dynamically
|
47 |
openai.api_key = openai_api_key
|
48 |
|
49 |
# Load and process the PDF
|
50 |
documents = load_pdf(file)
|
51 |
|
52 |
# Create embeddings for the documents
|
53 |
+
embeddings = OpenAIEmbeddings(openai_api_key=openai_api_key)
|
54 |
|
55 |
# Use LangChain's FAISS Vector Store to store and search the embeddings
|
56 |
vector_store = FAISS.from_documents(documents, embeddings)
|