masadonline commited on
Commit
f31fbc6
Β·
verified Β·
1 Parent(s): 6409405

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -5
app.py CHANGED
@@ -27,8 +27,6 @@ if not pdf_paths:
27
  st.warning("πŸ“ Please place some PDF files in the `docs/` folder.")
28
  st.stop()
29
 
30
- #st.info(f"πŸ“„ Loaded {len(pdf_paths)} document(s) from `docs/`")
31
-
32
  # Load and split all PDFs
33
  documents = []
34
  for path in pdf_paths:
@@ -54,10 +52,12 @@ qa_chain = RetrievalQA.from_chain_type(
54
  return_source_documents=True
55
  )
56
 
57
- # Ask question
58
- user_question = st.text_input("πŸ’¬ Ask your question about SME documents:")
59
 
60
- if user_question:
 
 
61
  with st.spinner("πŸ€” Thinking..."):
62
  result = qa_chain({"query": user_question})
63
  st.success("βœ… Answer:")
@@ -66,3 +66,8 @@ if user_question:
66
  with st.expander("πŸ“„ Source Snippets"):
67
  for i, doc in enumerate(result["source_documents"]):
68
  st.markdown(f"**Source {i+1}:**\n{doc.page_content[:300]}...")
 
 
 
 
 
 
27
  st.warning("πŸ“ Please place some PDF files in the `docs/` folder.")
28
  st.stop()
29
 
 
 
30
  # Load and split all PDFs
31
  documents = []
32
  for path in pdf_paths:
 
52
  return_source_documents=True
53
  )
54
 
55
+ # User input
56
+ user_question = st.text_input("πŸ’¬ Ask your question about SME documents:", key="user_question")
57
 
58
+ # Button to trigger response
59
+ if st.button("Ask") or user_question and st.session_state.get("user_question_submitted", False) is False:
60
+ st.session_state["user_question_submitted"] = True
61
  with st.spinner("πŸ€” Thinking..."):
62
  result = qa_chain({"query": user_question})
63
  st.success("βœ… Answer:")
 
66
  with st.expander("πŸ“„ Source Snippets"):
67
  for i, doc in enumerate(result["source_documents"]):
68
  st.markdown(f"**Source {i+1}:**\n{doc.page_content[:300]}...")
69
+
70
+ # Reset the submit flag if input changes
71
+ if user_question != st.session_state.get("last_input", ""):
72
+ st.session_state["user_question_submitted"] = False
73
+ st.session_state["last_input"] = user_question