VishnuRamDebyez commited on
Commit
3f58e3f
·
verified ·
1 Parent(s): 02ab853

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -12
app.py CHANGED
@@ -22,8 +22,8 @@ if 'chat_history' not in st.session_state:
22
  st.session_state.chat_history = []
23
  if 'last_response' not in st.session_state:
24
  st.session_state.last_response = None
25
- if 'clear_chat' not in st.session_state:
26
- st.session_state.clear_chat = False
27
 
28
  # Title
29
  st.title("Legal Assistant")
@@ -71,11 +71,9 @@ def add_to_chat_history(question, answer):
71
  # Main input area with clear button
72
  col1, col2 = st.columns([3, 1])
73
  with col1:
74
- # Use a key to manage the text input state
75
- # If clear_chat is True, use an empty default value
76
- default_text = "" if st.session_state.clear_chat else st.session_state.get('last_question', '')
77
  prompt1 = st.text_input("Enter Your Question From Documents",
78
- value=default_text,
79
  key="user_question")
80
 
81
  with col2:
@@ -85,13 +83,9 @@ with col2:
85
 
86
  # Clear chat functionality
87
  if clear_button:
88
- # Reset flags and last response
89
- st.session_state.clear_chat = True
90
  st.session_state.last_response = None
91
- st.experimental_rerun()
92
-
93
- # Reset clear_chat flag after processing
94
- st.session_state.clear_chat = False
95
 
96
  # Process question and generate response
97
  if prompt1:
 
22
  st.session_state.chat_history = []
23
  if 'last_response' not in st.session_state:
24
  st.session_state.last_response = None
25
+ if 'last_question' not in st.session_state:
26
+ st.session_state.last_question = ""
27
 
28
  # Title
29
  st.title("Legal Assistant")
 
71
  # Main input area with clear button
72
  col1, col2 = st.columns([3, 1])
73
  with col1:
74
+ # Text input with dynamic value management
 
 
75
  prompt1 = st.text_input("Enter Your Question From Documents",
76
+ value=st.session_state.last_question,
77
  key="user_question")
78
 
79
  with col2:
 
83
 
84
  # Clear chat functionality
85
  if clear_button:
86
+ # Reset last question and response
87
+ st.session_state.last_question = ""
88
  st.session_state.last_response = None
 
 
 
 
89
 
90
  # Process question and generate response
91
  if prompt1: