Update app.py
Browse files
app.py
CHANGED
@@ -114,21 +114,34 @@ def main():
|
|
114 |
# Display chat history
|
115 |
display_chat_history()
|
116 |
|
|
|
|
|
|
|
|
|
117 |
# Main query interface
|
118 |
query = st.text_input(
|
119 |
"โปรดระบุคำถามเกี่ยวกับปฏิทินการศึกษา:",
|
|
|
120 |
placeholder="เช่น: วันสุดท้ายของการสอบปากเปล่าในภาคเรียนที่ 1/2567 คือวันที่เท่าไร?",
|
121 |
key="query_input"
|
122 |
)
|
123 |
|
|
|
|
|
|
|
124 |
# Add query button and clear chat button in the same line
|
125 |
col1, col2 = st.columns([1, 4])
|
126 |
with col1:
|
127 |
if st.button("ส่งคำถาม", type="primary", use_container_width=True):
|
128 |
-
|
|
|
|
|
|
|
|
|
129 |
with col2:
|
130 |
if st.button("ล้างประวัติการสนทนา", type="secondary", use_container_width=True):
|
131 |
st.session_state.chat_history = []
|
|
|
132 |
st.rerun()
|
133 |
|
134 |
with info_col:
|
@@ -152,5 +165,4 @@ def main():
|
|
152 |
st.markdown(f"**สถานะระบบ:** {'🟢 พร้อมใช้งาน' if st.session_state.pipeline else '🔴 ไม่พร้อมใช้งาน'}")
|
153 |
|
154 |
if __name__ == "__main__":
|
155 |
-
main()
|
156 |
-
|
|
|
114 |
# Display chat history
|
115 |
display_chat_history()
|
116 |
|
117 |
+
# Initialize query input in session state if not present
|
118 |
+
if 'current_query' not in st.session_state:
|
119 |
+
st.session_state.current_query = ''
|
120 |
+
|
121 |
# Main query interface
|
122 |
query = st.text_input(
|
123 |
"โปรดระบุคำถามเกี่ยวกับปฏิทินการศึกษา:",
|
124 |
+
value=st.session_state.current_query,
|
125 |
placeholder="เช่น: วันสุดท้ายของการสอบปากเปล่าในภาคเรียนที่ 1/2567 คือวันที่เท่าไร?",
|
126 |
key="query_input"
|
127 |
)
|
128 |
|
129 |
+
# Update current query in session state
|
130 |
+
st.session_state.current_query = query
|
131 |
+
|
132 |
# Add query button and clear chat button in the same line
|
133 |
col1, col2 = st.columns([1, 4])
|
134 |
with col1:
|
135 |
if st.button("ส่งคำถาม", type="primary", use_container_width=True):
|
136 |
+
if query: # Only process if query is not empty
|
137 |
+
process_query(query)
|
138 |
+
# Clear the input only after successful processing
|
139 |
+
st.session_state.current_query = ''
|
140 |
+
st.rerun()
|
141 |
with col2:
|
142 |
if st.button("ล้างประวัติการสนทนา", type="secondary", use_container_width=True):
|
143 |
st.session_state.chat_history = []
|
144 |
+
st.session_state.current_query = ''
|
145 |
st.rerun()
|
146 |
|
147 |
with info_col:
|
|
|
165 |
st.markdown(f"**สถานะระบบ:** {'🟢 พร้อมใช้งาน' if st.session_state.pipeline else '🔴 ไม่พร้อมใช้งาน'}")
|
166 |
|
167 |
if __name__ == "__main__":
|
168 |
+
main()
|
|