JirasakJo commited on
Commit
53e7e31
·
verified ·
1 Parent(s): 4e9cecb

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +37 -62
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
- with st.form(key="chat_form", clear_on_submit=True):
277
- st.markdown("""
278
- <label for="query_input" style="font-size: 1.2rem; font-weight: 600; margin-bottom: 1rem; display: block;">
279
- <span style="color: #ffffff; border-left: 4px solid #ffffff; padding-left: 0.8rem;">
280
- โปรดระบุคำถามเกี่ยวกับปฏิทินการศึกษา:
281
- </span>
282
- </label>
283
- """, unsafe_allow_html=True)
284
-
285
- # Text input
286
- st.text_input(
287
- "",
288
- key="query_input",
289
- placeholder="เช่น: วันสุดท้ายของการสอบปากเปล่าในภาคเรียนที่ 1/2567 คือวันที่เท่าไร?"
290
- )
291
-
292
- # Button layout
293
- col1, col2, col3 = st.columns([1, 1, 4])
294
-
295
- with col1:
296
- submit_button = st.form_submit_button(
 
 
297
  "📤 ส่งคำถาม",
298
  type="primary",
299
- use_container_width=True,
300
- on_click=handle_submit
301
  )
302
-
303
- with col2:
304
- if st.button("🗑️ ล้างประวัติ", type="secondary", use_container_width=True):
305
- st.session_state.context_memory = []
306
- st.session_state.chat_history = []
307
- st.rerun()
 
 
 
 
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 form-based approach
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("""