Rajut commited on
Commit
1cc269c
·
verified ·
1 Parent(s): 7e6c22b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -6
app.py CHANGED
@@ -58,17 +58,25 @@ def get_conversational_chain():
58
 
59
 
60
  def user_input(user_question):
61
- embeddings = GoogleGenerativeAIEmbeddings(model = "models/embedding-001")
62
-
63
- new_db = FAISS.load_local("faiss_index", embeddings)
 
 
 
 
 
 
 
 
64
  docs = new_db.similarity_search(user_question)
65
 
66
  chain = get_conversational_chain()
67
 
68
-
69
  response = chain(
70
- {"input_documents":docs, "question": user_question}
71
- , return_only_outputs=True)
 
72
 
73
  print(response)
74
  st.write("Reply: ", response["output_text"])
 
58
 
59
 
60
  def user_input(user_question):
61
+ embeddings = GoogleGenerativeAIEmbeddings(model="models/embedding-001")
62
+
63
+ # Load the FAISS index with safe deserialization
64
+ new_db = FAISS.load_local("faiss_index", embeddings, allow_dangerous_deserialization=False)
65
+ if not new_db:
66
+ # If the index doesn't exist, create it
67
+ raw_text = get_pdf_text(pdf_docs)
68
+ text_chunks = get_text_chunks(raw_text)
69
+ get_vector_store(text_chunks)
70
+ new_db = FAISS.load_local("faiss_index", embeddings)
71
+
72
  docs = new_db.similarity_search(user_question)
73
 
74
  chain = get_conversational_chain()
75
 
 
76
  response = chain(
77
+ {"input_documents": docs, "question": user_question},
78
+ return_only_outputs=True
79
+ )
80
 
81
  print(response)
82
  st.write("Reply: ", response["output_text"])