avimittal30 commited on
Commit
904f39b
·
1 Parent(s): a7aaec4

pushing fixes

Browse files
Files changed (1) hide show
  1. app.py +6 -6
app.py CHANGED
@@ -26,7 +26,7 @@ This application allows you to upload a PDF file, ask questions about its conten
26
 
27
  # File upload section
28
  st.header("1. Upload PDF")
29
- uploaded_file = st.file_uploader("Choose a PDF file", type="pdf")
30
 
31
  # Initialize session state variables
32
  if 'pdf_processed' not in st.session_state:
@@ -82,10 +82,10 @@ if uploaded_file is not None and not st.session_state.pdf_processed:
82
 
83
  # Query section
84
  st.header("2. Ask a Question")
85
- query = st.text_input("Enter your question about the PDF content:")
86
 
87
  # Add a button to submit the query
88
- if st.button("Get Answer") and query and st.session_state.pdf_processed:
89
  with st.spinner("Retrieving relevant information and generating answer..."):
90
  try:
91
  # Generate embedding for the query
@@ -114,7 +114,7 @@ if st.button("Get Answer") and query and st.session_state.pdf_processed:
114
  st.write(answer)
115
 
116
  # Display the retrieved documents
117
- with st.expander("View Retrieved Documents"):
118
  for i, (doc, score) in enumerate(zip(documents, similarity_scores)):
119
  st.markdown(f"**Document {i+1}** (Relevance: {score:.4f})")
120
  st.text(doc[:500] + "..." if len(doc) > 500 else doc)
@@ -125,7 +125,7 @@ if st.button("Get Answer") and query and st.session_state.pdf_processed:
125
  logger.exception("Error during query processing")
126
 
127
  # Add a reset button
128
- if st.button("Reset and Upload New PDF"):
129
  # Clean up temporary files
130
  if st.session_state.pdf_path and os.path.exists(st.session_state.pdf_path):
131
  os.unlink(st.session_state.pdf_path)
@@ -141,4 +141,4 @@ if st.button("Reset and Upload New PDF"):
141
 
142
  # Footer
143
  st.markdown("---")
144
- st.markdown("Built with Streamlit, FAISS, and Ollama")
 
26
 
27
  # File upload section
28
  st.header("1. Upload PDF")
29
+ uploaded_file = st.file_uploader("Choose a PDF file", type="pdf", key="pdf_uploader")
30
 
31
  # Initialize session state variables
32
  if 'pdf_processed' not in st.session_state:
 
82
 
83
  # Query section
84
  st.header("2. Ask a Question")
85
+ query = st.text_input("Enter your question about the PDF content:", key="query_input")
86
 
87
  # Add a button to submit the query
88
+ if st.button("Get Answer", key="get_answer_button") and query and st.session_state.pdf_processed:
89
  with st.spinner("Retrieving relevant information and generating answer..."):
90
  try:
91
  # Generate embedding for the query
 
114
  st.write(answer)
115
 
116
  # Display the retrieved documents
117
+ with st.expander("View Retrieved Documents", expanded=False):
118
  for i, (doc, score) in enumerate(zip(documents, similarity_scores)):
119
  st.markdown(f"**Document {i+1}** (Relevance: {score:.4f})")
120
  st.text(doc[:500] + "..." if len(doc) > 500 else doc)
 
125
  logger.exception("Error during query processing")
126
 
127
  # Add a reset button
128
+ if st.button("Reset and Upload New PDF", key="reset_button"):
129
  # Clean up temporary files
130
  if st.session_state.pdf_path and os.path.exists(st.session_state.pdf_path):
131
  os.unlink(st.session_state.pdf_path)
 
141
 
142
  # Footer
143
  st.markdown("---")
144
+ st.markdown("Built with Streamlit, FAISS, and Hugging Face API")