Huzaifa367 commited on
Commit
b2a700f
·
verified ·
1 Parent(s): 26a8665

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -0
app.py CHANGED
@@ -50,11 +50,13 @@ def get_conversational_chain():
50
  return chain
51
 
52
  def user_input(user_question, api_key):
 
53
  embeddings = HuggingFaceInferenceAPIEmbeddings(api_key=api_key, model_name="sentence-transformers/all-MiniLM-l6-v2")
54
  new_db = FAISS.load_local("faiss_index", embeddings, allow_dangerous_deserialization=True)
55
  docs = new_db.similarity_search(user_question)
56
  chain = get_conversational_chain()
57
  response = chain({"input_documents": docs, "question": user_question}, return_only_outputs=True)
 
58
  st.write("Replies:")
59
  if isinstance(response["output_text"], str):
60
  response_list = [response["output_text"]]
@@ -89,12 +91,16 @@ def main():
89
  text_chunks = get_text_chunks(raw_text)
90
  get_vector_store(text_chunks, api_key)
91
  st.success("Processing Complete")
 
92
  if pdf_docs and st.success("Processing Complete"):
93
  with col1:
94
  raw_text = get_pdf_text(pdf_docs)
95
  user_question = st.text_input("Ask a question from the Docs")
96
  if user_question:
97
  user_input(user_question, api_key)
 
 
 
98
 
99
  # Display extracted text and handle user interaction if raw_text is not None
100
  if raw_text is not None:
 
50
  return chain
51
 
52
  def user_input(user_question, api_key):
53
+ st.spinner("Processing...")
54
  embeddings = HuggingFaceInferenceAPIEmbeddings(api_key=api_key, model_name="sentence-transformers/all-MiniLM-l6-v2")
55
  new_db = FAISS.load_local("faiss_index", embeddings, allow_dangerous_deserialization=True)
56
  docs = new_db.similarity_search(user_question)
57
  chain = get_conversational_chain()
58
  response = chain({"input_documents": docs, "question": user_question}, return_only_outputs=True)
59
+ st.success("Processing Complete")
60
  st.write("Replies:")
61
  if isinstance(response["output_text"], str):
62
  response_list = [response["output_text"]]
 
91
  text_chunks = get_text_chunks(raw_text)
92
  get_vector_store(text_chunks, api_key)
93
  st.success("Processing Complete")
94
+
95
  if pdf_docs and st.success("Processing Complete"):
96
  with col1:
97
  raw_text = get_pdf_text(pdf_docs)
98
  user_question = st.text_input("Ask a question from the Docs")
99
  if user_question:
100
  user_input(user_question, api_key)
101
+ else:
102
+ with col1:
103
+ st.write("Please upload a document first to ask questions.")
104
 
105
  # Display extracted text and handle user interaction if raw_text is not None
106
  if raw_text is not None: