JirasakJo commited on
Commit
5fac735
·
verified ·
1 Parent(s): 72e6844

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -2
app.py CHANGED
@@ -231,9 +231,16 @@ def submit():
231
  user_query = st.session_state.query_input
232
  st.session_state.chat_history.append(("user", user_query))
233
 
 
 
 
 
 
 
 
234
  # Add loading message as an assistant's response
235
  st.session_state.chat_history.append(("assistant", {"answer": "🔍 กำลังค้นหาคำตอบ...", "documents": [], "query_info": {}}))
236
- st.rerun() # Force UI update
237
 
238
  try:
239
  # Process query
@@ -250,9 +257,11 @@ def submit():
250
  # Replace spinner with error message
251
  st.session_state.chat_history[-1] = ("assistant", {"answer": f"❌ เกิดข้อผิดพลาด: {str(e)}", "documents": [], "query_info": {}})
252
 
253
- # Reset input
254
  st.session_state.query_input = ""
 
255
  st.rerun()
 
256
 
257
  def main():
258
  # Page config
 
231
  user_query = st.session_state.query_input
232
  st.session_state.chat_history.append(("user", user_query))
233
 
234
+ # Prevent duplicate runs by checking if a query is already being processed
235
+ if 'processing_query' in st.session_state and st.session_state.processing_query:
236
+ return
237
+
238
+ # Mark that a query is being processed
239
+ st.session_state.processing_query = True
240
+
241
  # Add loading message as an assistant's response
242
  st.session_state.chat_history.append(("assistant", {"answer": "🔍 กำลังค้นหาคำตอบ...", "documents": [], "query_info": {}}))
243
+ st.rerun() # Trigger UI update for spinner
244
 
245
  try:
246
  # Process query
 
257
  # Replace spinner with error message
258
  st.session_state.chat_history[-1] = ("assistant", {"answer": f"❌ เกิดข้อผิดพลาด: {str(e)}", "documents": [], "query_info": {}})
259
 
260
+ # Reset input and allow new queries
261
  st.session_state.query_input = ""
262
+ st.session_state.processing_query = False
263
  st.rerun()
264
+
265
 
266
  def main():
267
  # Page config