fguryel commited on
Commit
fc24b73
Β·
1 Parent(s): ac20173

fixed answer issue

Browse files
Files changed (2) hide show
  1. app.py +20 -20
  2. chroma_db/chroma.sqlite3 +1 -1
app.py CHANGED
@@ -271,19 +271,18 @@ ANSWER:"""
271
  st.error("OpenAI client not initialized. Please provide a valid API key.")
272
  return None, []
273
 
274
- # Step 1: Retrieve relevant chunks
275
- with st.spinner("πŸ” Searching relevant documentation..."):
 
276
  retrieved_chunks = self.retrieve_relevant_chunks(user_question, n_chunks)
277
-
278
- if not retrieved_chunks:
279
- return "I couldn't find relevant information in the Scikit-learn documentation to answer your question. Please try rephrasing your question or ask about a different topic.", []
280
-
281
- # Step 2: Create augmented prompt
282
- with st.spinner("πŸ“ Preparing context..."):
283
  rag_prompt = self.create_rag_prompt(user_question, retrieved_chunks)
284
-
285
- # Step 3: Generate answer
286
- with st.spinner("πŸ€– Generating answer..."):
287
  answer = self.generate_answer(rag_prompt, model)
288
 
289
  # Extract source URLs
@@ -394,8 +393,13 @@ def main():
394
  with col1:
395
  st.header("πŸ’¬ Ask Your Question")
396
 
397
- # Question input
398
- default_question = st.session_state.get('selected_question', '')
 
 
 
 
 
399
  user_question = st.text_input(
400
  "Enter your question about Scikit-learn:",
401
  value=default_question,
@@ -403,10 +407,6 @@ def main():
403
  key="question_input"
404
  )
405
 
406
- # Clear selected question after using it
407
- if 'selected_question' in st.session_state:
408
- del st.session_state['selected_question']
409
-
410
  # Submit button
411
  submit_button = st.button("πŸš€ Get Answer", type="primary")
412
 
@@ -428,8 +428,8 @@ def main():
428
  'sources': sources
429
  })
430
 
431
- # Clear input
432
- st.rerun()
433
 
434
  # Display chat history
435
  if st.session_state.chat_history:
@@ -464,7 +464,7 @@ def main():
464
 
465
  for question in example_questions:
466
  if st.button(question, key=f"example_{hash(question)}"):
467
- # Use a different approach to set the question
468
  st.session_state['selected_question'] = question
469
  st.rerun()
470
 
 
271
  st.error("OpenAI client not initialized. Please provide a valid API key.")
272
  return None, []
273
 
274
+ # Use a single spinner for the entire process to prevent flickering
275
+ with st.spinner("πŸ€– Generating answer..."):
276
+ # Step 1: Retrieve relevant chunks
277
  retrieved_chunks = self.retrieve_relevant_chunks(user_question, n_chunks)
278
+
279
+ if not retrieved_chunks:
280
+ return "I couldn't find relevant information in the Scikit-learn documentation to answer your question. Please try rephrasing your question or ask about a different topic.", []
281
+
282
+ # Step 2: Create augmented prompt
 
283
  rag_prompt = self.create_rag_prompt(user_question, retrieved_chunks)
284
+
285
+ # Step 3: Generate answer
 
286
  answer = self.generate_answer(rag_prompt, model)
287
 
288
  # Extract source URLs
 
393
  with col1:
394
  st.header("πŸ’¬ Ask Your Question")
395
 
396
+ # Question input with better state management
397
+ default_question = ''
398
+ if 'selected_question' in st.session_state:
399
+ default_question = st.session_state['selected_question']
400
+ # Clear after getting the value to prevent re-triggering
401
+ del st.session_state['selected_question']
402
+
403
  user_question = st.text_input(
404
  "Enter your question about Scikit-learn:",
405
  value=default_question,
 
407
  key="question_input"
408
  )
409
 
 
 
 
 
410
  # Submit button
411
  submit_button = st.button("πŸš€ Get Answer", type="primary")
412
 
 
428
  'sources': sources
429
  })
430
 
431
+ # Success message instead of rerun to prevent flickering
432
+ st.success("βœ… Answer generated successfully! Check the chat history below.")
433
 
434
  # Display chat history
435
  if st.session_state.chat_history:
 
464
 
465
  for question in example_questions:
466
  if st.button(question, key=f"example_{hash(question)}"):
467
+ # Set the question and rerun only once
468
  st.session_state['selected_question'] = question
469
  st.rerun()
470
 
chroma_db/chroma.sqlite3 CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:7da052d90807d731532e1195c8fbd4478b133ff07654b8ed5798dfd2d30b7a90
3
  size 13279232
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:29dd849ea2bda952a956fc1ae9039fcc202dd536fba5f36beb87b2da0bb04c99
3
  size 13279232