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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -11
app.py CHANGED
@@ -227,19 +227,19 @@ def submit():
227
  st.error("❌ ไม่สามารถเชื่อมต่อกับระบบได้ กรุณาลองใหม่อีกครั้ง")
228
  return
229
 
230
- # Add user query to chat history FIRST
231
  user_query = st.session_state.query_input
232
  st.session_state.chat_history.append(("user", user_query))
233
 
234
- # Show loading spinner in the chat section
235
- st.session_state.chat_history.append(("assistant", "🔍 กำลังค้นหาคำตอบ..."))
236
- st.rerun() # Force rerun to update UI before running pipeline
237
 
238
  try:
239
  # Process query
240
  result = st.session_state.pipeline.process_query(user_query)
241
 
242
- # Replace loading spinner with the actual answer
243
  st.session_state.chat_history[-1] = ("assistant", {
244
  "answer": result["answer"],
245
  "documents": result["documents"],
@@ -248,14 +248,12 @@ def submit():
248
 
249
  except Exception as e:
250
  # Replace spinner with error message
251
- st.session_state.chat_history[-1] = ("assistant", f"❌ เกิดข้อผิดพลาด: {str(e)}")
252
 
253
- # Reset input box
254
  st.session_state.query_input = ""
255
- st.rerun() # Force update the UI
256
-
257
-
258
-
259
  def main():
260
  # Page config
261
  st.set_page_config(
 
227
  st.error("❌ ไม่สามารถเชื่อมต่อกับระบบได้ กรุณาลองใหม่อีกครั้ง")
228
  return
229
 
230
+ # Store user query
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
240
  result = st.session_state.pipeline.process_query(user_query)
241
 
242
+ # Replace loading message with actual response
243
  st.session_state.chat_history[-1] = ("assistant", {
244
  "answer": result["answer"],
245
  "documents": result["documents"],
 
248
 
249
  except Exception as e:
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
259
  st.set_page_config(