Rathapoom commited on
Commit
906cfa5
·
verified ·
1 Parent(s): 511dc37

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -1
app.py CHANGED
@@ -104,9 +104,15 @@ def init_session_state():
104
  st.session_state.badges = []
105
  if 'should_reset' not in st.session_state:
106
  st.session_state.should_reset = False
 
 
107
 
108
  init_session_state()
109
 
 
 
 
 
110
  def show_welcome_section():
111
  st.markdown("""
112
  <div class="welcome-header">
@@ -457,15 +463,32 @@ with col1:
457
  </div>
458
  """, unsafe_allow_html=True)
459
 
460
- user_input = st.text_area("เขียนต่อจากเรื่องราว | Continue the story:", height=100)
 
 
 
 
 
461
 
462
  if st.button("ส่งคำตอบ | Submit"):
463
  if user_input.strip():
 
464
  st.session_state.story.append({"role": "You", "content": user_input})
 
 
465
  update_achievements(user_input)
 
 
466
  st.session_state.feedback = provide_feedback(user_input, st.session_state.level)
 
 
467
  ai_response = generate_story_continuation(user_input, st.session_state.level)
468
  st.session_state.story.append({"role": "AI", "content": ai_response})
 
 
 
 
 
469
  st.rerun()
470
  else:
471
  st.warning("กรุณาเขียนเนื้อเรื่องก่อนกดส่ง | Please write something to continue the story.")
 
104
  st.session_state.badges = []
105
  if 'should_reset' not in st.session_state:
106
  st.session_state.should_reset = False
107
+ if 'user_input' not in st.session_state:
108
+ st.session_state.user_input = ""
109
 
110
  init_session_state()
111
 
112
+ # เพิ่มฟังก์ชันสำหรับจัดการ input
113
+ def clear_input():
114
+ st.session_state.user_input = ""
115
+
116
  def show_welcome_section():
117
  st.markdown("""
118
  <div class="welcome-header">
 
463
  </div>
464
  """, unsafe_allow_html=True)
465
 
466
+ user_input = st.text_area(
467
+ "เขียนต่อจากเรื่องราว | Continue the story:",
468
+ height=100,
469
+ key="user_input", # ใช้ key เดียวกับ session state
470
+ value=st.session_state.user_input # ผูก value กับ session state
471
+ )
472
 
473
  if st.button("ส่งคำตอบ | Submit"):
474
  if user_input.strip():
475
+ # Add user's input to story
476
  st.session_state.story.append({"role": "You", "content": user_input})
477
+
478
+ # Update achievements
479
  update_achievements(user_input)
480
+
481
+ # Generate feedback
482
  st.session_state.feedback = provide_feedback(user_input, st.session_state.level)
483
+
484
+ # Generate AI continuation
485
  ai_response = generate_story_continuation(user_input, st.session_state.level)
486
  st.session_state.story.append({"role": "AI", "content": ai_response})
487
+
488
+ # Clear the input
489
+ clear_input()
490
+
491
+ # Rerun the app
492
  st.rerun()
493
  else:
494
  st.warning("กรุณาเขียนเนื้อเรื่องก่อนกดส่ง | Please write something to continue the story.")