Aditya Bakshi commited on
Commit
ca63af9
·
1 Parent(s): 8792f2b

add reset button just below the chat input

Browse files
Files changed (3) hide show
  1. .DS_Store +0 -0
  2. app.py +30 -2
  3. requirements.txt +1 -0
.DS_Store ADDED
Binary file (8.2 kB). View file
 
app.py CHANGED
@@ -19,6 +19,7 @@ from dotenv import load_dotenv
19
  from langchain_community.chat_message_histories import StreamlitChatMessageHistory
20
  from langchain_core.messages import HumanMessage
21
  from langchain_core.prompts import ChatPromptTemplate
 
22
 
23
  import global_config as gcfg
24
  import helpers.file_manager as filem
@@ -134,6 +135,23 @@ def reset_api_key():
134
  st.session_state.api_key_input = ''
135
 
136
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
137
  APP_TEXT = _load_strings()
138
 
139
  # Session variables
@@ -285,12 +303,22 @@ def set_up_chat_ui():
285
  for msg in history.messages:
286
  st.chat_message(msg.type).code(msg.content, language='json')
287
 
288
- if prompt := st.chat_input(
 
289
  placeholder=APP_TEXT['chat_placeholder'],
290
  max_chars=GlobalConfig.LLM_MODEL_MAX_INPUT_LENGTH,
291
  accept_file=True,
292
  file_type=['pdf', ],
293
- ):
 
 
 
 
 
 
 
 
 
294
  prompt_text = prompt.text or ''
295
  if prompt['files']:
296
  # Store uploaded pdf in session state
 
19
  from langchain_community.chat_message_histories import StreamlitChatMessageHistory
20
  from langchain_core.messages import HumanMessage
21
  from langchain_core.prompts import ChatPromptTemplate
22
+ from streamlit_extras.bottom_container import bottom
23
 
24
  import global_config as gcfg
25
  import helpers.file_manager as filem
 
135
  st.session_state.api_key_input = ''
136
 
137
 
138
+ def reset_chat_history():
139
+ """
140
+ Clear the chat history and related session state variables.
141
+ """
142
+ if CHAT_MESSAGES in st.session_state:
143
+ del st.session_state[CHAT_MESSAGES]
144
+ if IS_IT_REFINEMENT in st.session_state:
145
+ del st.session_state[IS_IT_REFINEMENT]
146
+ if ADDITIONAL_INFO in st.session_state:
147
+ del st.session_state[ADDITIONAL_INFO]
148
+ if 'pdf_file' in st.session_state:
149
+ del st.session_state['pdf_file']
150
+ if DOWNLOAD_FILE_KEY in st.session_state:
151
+ del st.session_state[DOWNLOAD_FILE_KEY]
152
+ st.rerun()
153
+
154
+
155
  APP_TEXT = _load_strings()
156
 
157
  # Session variables
 
303
  for msg in history.messages:
304
  st.chat_message(msg.type).code(msg.content, language='json')
305
 
306
+ # Chat input at the bottom
307
+ prompt = st.chat_input(
308
  placeholder=APP_TEXT['chat_placeholder'],
309
  max_chars=GlobalConfig.LLM_MODEL_MAX_INPUT_LENGTH,
310
  accept_file=True,
311
  file_type=['pdf', ],
312
+ )
313
+
314
+ # Reset button below the chat input using bottom container
315
+ with bottom():
316
+ col1, col2, col3 = st.columns([1, 1, 1])
317
+ with col2:
318
+ if st.button("🔄 Reset Chat", help="Clear chat history and start a new conversation", use_container_width=True):
319
+ reset_chat_history()
320
+
321
+ if prompt:
322
  prompt_text = prompt.text or ''
323
  if prompt['files']:
324
  # Store uploaded pdf in session state
requirements.txt CHANGED
@@ -16,6 +16,7 @@ langchain-together==0.3.0
16
  langchain-ollama==0.2.1
17
  langchain-openai==0.3.3
18
  streamlit==1.44.1
 
19
 
20
  python-pptx~=1.0.2
21
  json5~=0.9.14
 
16
  langchain-ollama==0.2.1
17
  langchain-openai==0.3.3
18
  streamlit==1.44.1
19
+ streamlit-extras>=0.3.0
20
 
21
  python-pptx~=1.0.2
22
  json5~=0.9.14