Update app.py
Browse files
app.py
CHANGED
@@ -273,38 +273,43 @@ def handle_submit():
|
|
273 |
|
274 |
def create_chat_input():
|
275 |
"""Create the chat input section with form handling"""
|
276 |
-
|
277 |
-
|
278 |
-
|
279 |
-
|
280 |
-
|
281 |
-
|
282 |
-
|
283 |
-
|
284 |
-
|
285 |
-
|
286 |
-
|
287 |
-
|
288 |
-
|
289 |
-
|
290 |
-
|
291 |
-
|
292 |
-
|
293 |
-
|
294 |
-
|
295 |
-
|
296 |
-
|
|
|
|
|
297 |
"📤 ส่งคำถาม",
|
298 |
type="primary",
|
299 |
-
use_container_width=True
|
300 |
-
on_click=handle_submit
|
301 |
)
|
302 |
-
|
303 |
-
|
304 |
-
|
305 |
-
|
306 |
-
|
307 |
-
|
|
|
|
|
|
|
|
|
308 |
|
309 |
def main():
|
310 |
# Page config
|
@@ -352,7 +357,7 @@ def main():
|
|
352 |
chat_col, info_col = st.columns([7, 3])
|
353 |
|
354 |
with chat_col:
|
355 |
-
# Display chat history
|
356 |
for i, (role, content) in enumerate(st.session_state.chat_history):
|
357 |
if role == "user":
|
358 |
st.markdown(f"""
|
@@ -383,40 +388,10 @@ def main():
|
|
383 |
{doc.content}
|
384 |
</div>
|
385 |
""", unsafe_allow_html=True)
|
386 |
-
|
387 |
-
# Create chat input using the new
|
388 |
create_chat_input()
|
389 |
|
390 |
-
# Input section at the bottom
|
391 |
-
with st.container():
|
392 |
-
st.markdown("""
|
393 |
-
<label for="query_input" style="font-size: 1.2rem; font-weight: 600; margin-bottom: 1rem; display: block;">
|
394 |
-
<span style="color: #ffffff; border-left: 4px solid #ffffff; padding-left: 0.8rem;">
|
395 |
-
โปรดระบุคำถามเกี่ยวกับปฏิทินการศึกษา:
|
396 |
-
</span>
|
397 |
-
</label>
|
398 |
-
""", unsafe_allow_html=True)
|
399 |
-
|
400 |
-
# Text input with enter key handling
|
401 |
-
st.text_input(
|
402 |
-
"",
|
403 |
-
key="query_input",
|
404 |
-
placeholder="เช่น: วันสุดท้ายของการสอบปากเปล่าในภาคเรียนที่ 1/2567 คือวันที่เท่าไร?",
|
405 |
-
on_change=submit
|
406 |
-
)
|
407 |
-
|
408 |
-
# Button layout
|
409 |
-
col1, col2, col3 = st.columns([1, 1, 4])
|
410 |
-
|
411 |
-
with col1:
|
412 |
-
st.button("📤 ส่งคำถาม", type="primary", use_container_width=True, on_click=submit)
|
413 |
-
|
414 |
-
with col2:
|
415 |
-
if st.button("🗑️ ล้างประวัติ", type="secondary", use_container_width=True):
|
416 |
-
st.session_state.context_memory = []
|
417 |
-
st.session_state.chat_history = []
|
418 |
-
# st.rerun()
|
419 |
-
|
420 |
# Sidebar info column
|
421 |
with info_col:
|
422 |
st.markdown("""
|
|
|
273 |
|
274 |
def create_chat_input():
|
275 |
"""Create the chat input section with form handling"""
|
276 |
+
# Column layout for the entire input section
|
277 |
+
input_col, clear_col = st.columns([4, 1])
|
278 |
+
|
279 |
+
with input_col:
|
280 |
+
# Create the form for chat input
|
281 |
+
with st.form(key="chat_form", clear_on_submit=True):
|
282 |
+
st.markdown("""
|
283 |
+
<label for="query_input" style="font-size: 1.2rem; font-weight: 600; margin-bottom: 1rem; display: block;">
|
284 |
+
<span style="color: #ffffff; border-left: 4px solid #ffffff; padding-left: 0.8rem;">
|
285 |
+
โปรดระบุคำถามเกี่ยวกับปฏิทินการศึกษา:
|
286 |
+
</span>
|
287 |
+
</label>
|
288 |
+
""", unsafe_allow_html=True)
|
289 |
+
|
290 |
+
# Text input
|
291 |
+
st.text_input(
|
292 |
+
"",
|
293 |
+
key="query_input",
|
294 |
+
placeholder="เช่น: วันสุดท้ายของการสอบปากเปล่าในภาคเรียนที่ 1/2567 คือวันที่เท่าไร?"
|
295 |
+
)
|
296 |
+
|
297 |
+
# Submit button in form
|
298 |
+
submitted = st.form_submit_button(
|
299 |
"📤 ส่งคำถาม",
|
300 |
type="primary",
|
301 |
+
use_container_width=True
|
|
|
302 |
)
|
303 |
+
|
304 |
+
if submitted:
|
305 |
+
handle_submit()
|
306 |
+
|
307 |
+
# Clear history button outside the form
|
308 |
+
with clear_col:
|
309 |
+
if st.button("🗑️ ล้างประวัติ", type="secondary", use_container_width=True):
|
310 |
+
st.session_state.context_memory = []
|
311 |
+
st.session_state.chat_history = []
|
312 |
+
st.rerun()
|
313 |
|
314 |
def main():
|
315 |
# Page config
|
|
|
357 |
chat_col, info_col = st.columns([7, 3])
|
358 |
|
359 |
with chat_col:
|
360 |
+
# Display chat history first
|
361 |
for i, (role, content) in enumerate(st.session_state.chat_history):
|
362 |
if role == "user":
|
363 |
st.markdown(f"""
|
|
|
388 |
{doc.content}
|
389 |
</div>
|
390 |
""", unsafe_allow_html=True)
|
391 |
+
|
392 |
+
# Create chat input using the new implementation
|
393 |
create_chat_input()
|
394 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
395 |
# Sidebar info column
|
396 |
with info_col:
|
397 |
st.markdown("""
|