Update app.py
Browse files
app.py
CHANGED
|
@@ -280,10 +280,10 @@ def main():
|
|
| 280 |
key="query_input",
|
| 281 |
value="" if 'clear_input' in st.session_state and st.session_state.clear_input else st.session_state.get('query_input', '')
|
| 282 |
)
|
| 283 |
-
|
| 284 |
-
# Button layout inside main() function
|
| 285 |
-
col1, col2, col3 = st.columns([1, 1, 4])
|
| 286 |
|
|
|
|
|
|
|
|
|
|
| 287 |
with col1:
|
| 288 |
send_query = st.button(
|
| 289 |
"📤 ส่งคำถาม",
|
|
@@ -291,7 +291,7 @@ def main():
|
|
| 291 |
use_container_width=True,
|
| 292 |
key="send_query_button"
|
| 293 |
)
|
| 294 |
-
|
| 295 |
with col2:
|
| 296 |
clear_history = st.button(
|
| 297 |
"🗑️ ล้างประวัติ",
|
|
@@ -299,6 +299,7 @@ def main():
|
|
| 299 |
use_container_width=True,
|
| 300 |
key="clear_history_button"
|
| 301 |
)
|
|
|
|
| 302 |
# Process query
|
| 303 |
if send_query and query:
|
| 304 |
if st.session_state.pipeline is None:
|
|
@@ -323,21 +324,26 @@ def main():
|
|
| 323 |
|
| 324 |
with st.expander("🔍 รายละเอียดการวิเคราะห์คำถาม", expanded=False):
|
| 325 |
st.json(result["query_info"])
|
| 326 |
-
|
| 327 |
# Clear the input after successful submission
|
| 328 |
st.session_state.clear_input = True
|
| 329 |
st.rerun()
|
| 330 |
|
| 331 |
except Exception as e:
|
| 332 |
st.error(f"❌ เกิดข้อผิดพลาด: {str(e)}")
|
| 333 |
-
|
| 334 |
elif send_query and not query:
|
| 335 |
st.warning("⚠️ กรุณาระบุคำถาม")
|
| 336 |
-
|
| 337 |
-
|
| 338 |
-
|
| 339 |
-
|
| 340 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 341 |
|
| 342 |
with info_col:
|
| 343 |
# System information
|
|
|
|
| 280 |
key="query_input",
|
| 281 |
value="" if 'clear_input' in st.session_state and st.session_state.clear_input else st.session_state.get('query_input', '')
|
| 282 |
)
|
|
|
|
|
|
|
|
|
|
| 283 |
|
| 284 |
+
# Button layout
|
| 285 |
+
col1, col2, col3 = st.columns([1, 1, 4])
|
| 286 |
+
|
| 287 |
with col1:
|
| 288 |
send_query = st.button(
|
| 289 |
"📤 ส่งคำถาม",
|
|
|
|
| 291 |
use_container_width=True,
|
| 292 |
key="send_query_button"
|
| 293 |
)
|
| 294 |
+
|
| 295 |
with col2:
|
| 296 |
clear_history = st.button(
|
| 297 |
"🗑️ ล้างประวัติ",
|
|
|
|
| 299 |
use_container_width=True,
|
| 300 |
key="clear_history_button"
|
| 301 |
)
|
| 302 |
+
|
| 303 |
# Process query
|
| 304 |
if send_query and query:
|
| 305 |
if st.session_state.pipeline is None:
|
|
|
|
| 324 |
|
| 325 |
with st.expander("🔍 รายละเอียดการวิเคราะห์คำถาม", expanded=False):
|
| 326 |
st.json(result["query_info"])
|
| 327 |
+
|
| 328 |
# Clear the input after successful submission
|
| 329 |
st.session_state.clear_input = True
|
| 330 |
st.rerun()
|
| 331 |
|
| 332 |
except Exception as e:
|
| 333 |
st.error(f"❌ เกิดข้อผิดพลาด: {str(e)}")
|
| 334 |
+
|
| 335 |
elif send_query and not query:
|
| 336 |
st.warning("⚠️ กรุณาระบุคำถาม")
|
| 337 |
+
|
| 338 |
+
# Handle clear history action
|
| 339 |
+
if clear_history:
|
| 340 |
+
st.session_state.chat_history = []
|
| 341 |
+
st.session_state.clear_input = True # Also clear input when clearing history
|
| 342 |
+
st.rerun()
|
| 343 |
+
|
| 344 |
+
# Reset clear_input flag at the end of each render
|
| 345 |
+
if 'clear_input' in st.session_state:
|
| 346 |
+
del st.session_state.clear_input
|
| 347 |
|
| 348 |
with info_col:
|
| 349 |
# System information
|