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

Fix: Make example questions clickable and populate input field

Browse files

- Fixed example question buttons to properly populate the text input field
- Improved session state management for question input
- Clear input field after successful answer generation
- Reduced flickering by removing unnecessary reruns

Files changed (1) hide show
  1. app.py +11 -5
app.py CHANGED
@@ -394,15 +394,18 @@ def main():
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,
406
  placeholder="e.g., How do I perform cross-validation in scikit-learn?",
407
  key="question_input"
408
  )
@@ -428,7 +431,10 @@ def main():
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
 
394
  st.header("💬 Ask Your Question")
395
 
396
  # Question input with better state management
397
+ # Initialize question input key if it doesn't exist
398
+ if 'question_input' not in st.session_state:
399
+ st.session_state.question_input = ''
400
+
401
+ # Handle selected question from examples
402
  if 'selected_question' in st.session_state:
403
+ st.session_state.question_input = st.session_state['selected_question']
404
+ # Clear after setting to prevent re-triggering
405
  del st.session_state['selected_question']
406
 
407
  user_question = st.text_input(
408
  "Enter your question about Scikit-learn:",
 
409
  placeholder="e.g., How do I perform cross-validation in scikit-learn?",
410
  key="question_input"
411
  )
 
431
  'sources': sources
432
  })
433
 
434
+ # Clear the input field after successful submission
435
+ st.session_state.question_input = ""
436
+
437
+ # Success message
438
  st.success("✅ Answer generated successfully! Check the chat history below.")
439
 
440
  # Display chat history