Update app.py
Browse files
app.py
CHANGED
@@ -227,19 +227,19 @@ def submit():
|
|
227 |
st.error("❌ ไม่สามารถเชื่อมต่อกับระบบได้ กรุณาลองใหม่อีกครั้ง")
|
228 |
return
|
229 |
|
230 |
-
#
|
231 |
user_query = st.session_state.query_input
|
232 |
st.session_state.chat_history.append(("user", user_query))
|
233 |
|
234 |
-
#
|
235 |
-
st.session_state.chat_history.append(("assistant", "🔍 กำลังค้นหาคำตอบ..."))
|
236 |
-
st.rerun() # Force
|
237 |
|
238 |
try:
|
239 |
# Process query
|
240 |
result = st.session_state.pipeline.process_query(user_query)
|
241 |
|
242 |
-
# Replace loading
|
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
|
254 |
st.session_state.query_input = ""
|
255 |
-
st.rerun()
|
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(
|