Musharraf11 commited on
Commit
da6b73f
1 Parent(s): 19c8380

Update chatbot.py

Browse files
Files changed (1) hide show
  1. chatbot.py +13 -20
chatbot.py CHANGED
@@ -39,9 +39,7 @@ def chatbot():
39
  def get_vector_store(text_chunks):
40
  embedding_function = GoogleGenerativeAIEmbeddings(model="models/embedding-001")
41
  vector_store = FAISS.from_texts(text_chunks, embedding=embedding_function)
42
- # Save FAISS index in the current directory without using faiss_index sub-directory
43
  vector_store.save_local("faiss_index")
44
- return vector_store
45
 
46
  def get_conversational_chain():
47
  prompt_template = """
@@ -59,7 +57,6 @@ def chatbot():
59
 
60
  def user_input(user_question):
61
  embeddings = GoogleGenerativeAIEmbeddings(model="models/embedding-001")
62
- # Load FAISS index from the current directory without using faiss_index sub-directory
63
  new_db = FAISS.load_local("faiss_index", embeddings, allow_dangerous_deserialization=True)
64
  docs = new_db.similarity_search(user_question)
65
  chain = get_conversational_chain()
@@ -77,19 +74,19 @@ def chatbot():
77
  if "messages" not in st.session_state:
78
  st.session_state.messages = []
79
 
80
- # Uncomment if you want to add your own-custom pdf:
81
- # with st.form(key="uploader_form"):
82
- # pdf_docs = st.file_uploader("Upload your PDF Files", accept_multiple_files=True)
83
- # submit_button = st.form_submit_button(label="Submit & Process")
84
- # if submit_button:
85
- # if pdf_docs:
86
- # with st.spinner("Processing..."):
87
- # raw_text = get_pdf_text(pdf_docs)
88
- # text_chunks = get_text_chunks(raw_text)
89
- # get_vector_store(text_chunks)
90
- # st.success("Processing completed successfully.")
91
- # else:
92
- # st.warning("Please upload at least one PDF file.")
93
 
94
  # Display chat messages from history on app rerun
95
  for message in st.session_state.messages:
@@ -112,7 +109,3 @@ def chatbot():
112
 
113
  # Add assistant response to chat history
114
  st.session_state.messages.append({"role": "assistant", "content": response})
115
-
116
- # Example usage if running as a script
117
- if __name__ == "__main__":
118
- chatbot()
 
39
  def get_vector_store(text_chunks):
40
  embedding_function = GoogleGenerativeAIEmbeddings(model="models/embedding-001")
41
  vector_store = FAISS.from_texts(text_chunks, embedding=embedding_function)
 
42
  vector_store.save_local("faiss_index")
 
43
 
44
  def get_conversational_chain():
45
  prompt_template = """
 
57
 
58
  def user_input(user_question):
59
  embeddings = GoogleGenerativeAIEmbeddings(model="models/embedding-001")
 
60
  new_db = FAISS.load_local("faiss_index", embeddings, allow_dangerous_deserialization=True)
61
  docs = new_db.similarity_search(user_question)
62
  chain = get_conversational_chain()
 
74
  if "messages" not in st.session_state:
75
  st.session_state.messages = []
76
 
77
+ # Uncomment if you want to add your own-custom pdf:
78
+ with st.form(key="uploader_form"):
79
+ pdf_docs = st.file_uploader("Upload your PDF Files", accept_multiple_files=True)
80
+ submit_button = st.form_submit_button(label="Submit & Process")
81
+ if submit_button:
82
+ if pdf_docs:
83
+ with st.spinner("Processing..."):
84
+ raw_text = get_pdf_text(pdf_docs)
85
+ text_chunks = get_text_chunks(raw_text)
86
+ get_vector_store(text_chunks)
87
+ st.success("Processing completed successfully.")
88
+ else:
89
+ st.warning("Please upload at least one PDF file.")
90
 
91
  # Display chat messages from history on app rerun
92
  for message in st.session_state.messages:
 
109
 
110
  # Add assistant response to chat history
111
  st.session_state.messages.append({"role": "assistant", "content": response})