saritha commited on
Commit
84df10e
·
verified ·
1 Parent(s): 9105bd6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +3 -3
app.py CHANGED
@@ -8,6 +8,7 @@ from langchain_google_genai import ChatGoogleGenerativeAI
8
  import google.generativeai as genai
9
  from langchain.chains.question_answering import load_qa_chain # Import load_qa_chain
10
 
 
11
  async def initialize(file_path, question):
12
  genai.configure(api_key=os.getenv("GOOGLE_API_KEY"))
13
  model = genai.GenerativeModel('gemini-pro')
@@ -36,9 +37,8 @@ async def initialize(file_path, question):
36
  # Use ainvoke to get the result
37
  stuff_answer = await stuff_chain.ainvoke({"input_documents": pages, "question": question, "context": context})
38
 
39
- # Post-process the answer to remove any unnecessary text or system messages
40
- answer = stuff_answer.strip()
41
- answer = answer.split("Answer:")[1] if "Answer:" in answer else answer
42
 
43
  # Extract the page number where the context was found
44
  sources = []
 
8
  import google.generativeai as genai
9
  from langchain.chains.question_answering import load_qa_chain # Import load_qa_chain
10
 
11
+
12
  async def initialize(file_path, question):
13
  genai.configure(api_key=os.getenv("GOOGLE_API_KEY"))
14
  model = genai.GenerativeModel('gemini-pro')
 
37
  # Use ainvoke to get the result
38
  stuff_answer = await stuff_chain.ainvoke({"input_documents": pages, "question": question, "context": context})
39
 
40
+ # Access the correct key for the answer
41
+ answer = stuff_answer.get('output_text', '').strip()
 
42
 
43
  # Extract the page number where the context was found
44
  sources = []