JirasakJo commited on
Commit
6eee913
·
verified ·
1 Parent(s): 324abdb

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -24
app.py CHANGED
@@ -318,30 +318,32 @@ def handle_submit(user_query: str):
318
  # Add user message to chat history
319
  st.session_state.chat_history.append(("user", user_query))
320
 
321
- # Maintain context memory
322
- if len(st.session_state.context_memory) > 5:
323
- st.session_state.context_memory.pop(0)
324
-
325
- # Build query with context
326
- query_with_context = "\n".join(
327
- [f"Q: {qa['query']}\nA: {qa['answer']}" for qa in st.session_state.context_memory]
328
- ) + f"\nQ: {user_query}"
329
-
330
- # Process query
331
- result = st.session_state.pipeline.process_query(query_with_context)
332
-
333
- # Create response dictionary with answer and documents
334
- response_dict = {
335
- "answer": result.get("answer", ""),
336
- "documents": result.get("documents", [])
337
- }
338
-
339
- # Update chat history and context
340
- st.session_state.chat_history.append(("assistant", response_dict))
341
- st.session_state.context_memory.append({"query": user_query, "answer": response_dict})
342
-
343
- # Save to QA history
344
- add_to_qa_history(user_query, response_dict)
 
 
345
 
346
  except Exception as e:
347
  st.session_state.chat_history.append(("assistant", f"❌ เกิดข้อผิดพลาด: {str(e)}"))
 
318
  # Add user message to chat history
319
  st.session_state.chat_history.append(("user", user_query))
320
 
321
+ # Show loading message while processing
322
+ with st.spinner("🔍 กำลังค้นหาคำตอบ..."):
323
+ # Maintain context memory
324
+ if len(st.session_state.context_memory) > 5:
325
+ st.session_state.context_memory.pop(0)
326
+
327
+ # Build query with context
328
+ query_with_context = "\n".join(
329
+ [f"Q: {qa['query']}\nA: {qa['answer']}" for qa in st.session_state.context_memory]
330
+ ) + f"\nQ: {user_query}"
331
+
332
+ # Process query
333
+ result = st.session_state.pipeline.process_query(query_with_context)
334
+
335
+ # Create response dictionary with answer and documents
336
+ response_dict = {
337
+ "answer": result.get("answer", ""),
338
+ "documents": result.get("documents", [])
339
+ }
340
+
341
+ # Update chat history and context
342
+ st.session_state.chat_history.append(("assistant", response_dict))
343
+ st.session_state.context_memory.append({"query": user_query, "answer": response_dict})
344
+
345
+ # Save to QA history
346
+ add_to_qa_history(user_query, response_dict)
347
 
348
  except Exception as e:
349
  st.session_state.chat_history.append(("assistant", f"❌ เกิดข้อผิดพลาด: {str(e)}"))