Rathapoom commited on
Commit
f6c280b
·
verified ·
1 Parent(s): 629fead

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -18
app.py CHANGED
@@ -450,7 +450,19 @@ def clear_input():
450
  # Callback function for submit button
451
  def submit_story():
452
  if st.session_state.text_input.strip():
453
- user_text = st.session_state.text_input
 
 
 
 
 
 
 
 
 
 
 
 
454
 
455
  # เพิ่มคำศัพท์ที่ใช้
456
  words = set(user_text.lower().split())
@@ -1106,19 +1118,22 @@ def show_theme_selection():
1106
  </div>
1107
  """
1108
  # ใช้ button แทน markdown สำหรับการคลิก
1109
- if st.button(
1110
- theme['name_th'],
1111
- key=f"theme_button_{theme['id']}",
1112
- help=theme['description_th'],
1113
- use_container_width=True
1114
- ):
1115
- # บันทึกธีมที่เลือกใน session state
1116
  st.session_state.current_theme = theme['id']
1117
 
1118
- # สร้างจุดเริ่มต้นเรื่องแบบไดนามิก
1119
  starter = generate_dynamic_story_starter(theme['id'], st.session_state.level)
1120
  st.session_state.theme_story_starter = starter
1121
 
 
 
 
 
 
 
 
 
1122
  # แสดง theme intro
1123
  st.markdown(f"""
1124
  <div style="background-color: {theme['background_color']};
@@ -1132,20 +1147,13 @@ def show_theme_selection():
1132
  padding: 15px;
1133
  border-radius: 8px;
1134
  margin-top: 10px;">
1135
- <p style="color: #666;">จุดเริ่มต้นเรื่องของคุณ:</p>
1136
  <p style="color: #1e88e5;">{starter['th']}</p>
1137
  <p style="color: #333;">{starter['en']}</p>
1138
  </div>
1139
  </div>
1140
  """, unsafe_allow_html=True)
1141
-
1142
- # เพิ่มคำแนะนำการเขียน
1143
- st.info("📝 เริ่มเขียนเรื่องราวของคุณได้เลย! คุณสามารถใช้จุดเริ่มต้นด้านบนเป็นแรงบันดาลใจ")
1144
-
1145
- # แสดงคำศัพท์แนะนำสำหรับธีมนี้
1146
- with st.expander("📚 คำศัพท์แนะนำสำหรับธีมนี้"):
1147
- show_theme_vocabulary()
1148
-
1149
  st.rerun()
1150
 
1151
  # เพิ่ม CSS สำหรับ theme cards
 
450
  # Callback function for submit button
451
  def submit_story():
452
  if st.session_state.text_input.strip():
453
+ user_text = st.session_state.text_input.strip()
454
+
455
+ # ตรวจสอบว่ามีเรื่องเริ่มต้นหรือยัง
456
+ if not st.session_state.story:
457
+ st.error("กรุณาเลือกธีมเรื่องราวก่อนเริ่มเขียน")
458
+ return
459
+
460
+ # เพิ่มประโยคของผู้ใช้
461
+ st.session_state.story.append({
462
+ "role": "You",
463
+ "content": user_text,
464
+ "is_corrected": False
465
+ })
466
 
467
  # เพิ่มคำศัพท์ที่ใช้
468
  words = set(user_text.lower().split())
 
1118
  </div>
1119
  """
1120
  # ใช้ button แทน markdown สำหรับการคลิก
1121
+ if st.button(theme['name_th'], key=f"theme_button_{theme['id']}", help=theme['description_th']):
1122
+ # บันทึกธีมที่เลือก
 
 
 
 
 
1123
  st.session_state.current_theme = theme['id']
1124
 
1125
+ # สร้างจุดเริ่มต้นเรื่อง
1126
  starter = generate_dynamic_story_starter(theme['id'], st.session_state.level)
1127
  st.session_state.theme_story_starter = starter
1128
 
1129
+ # เพิ่มจุดเริ่มต้นเรื่องเป็นประโยคแรกใน story
1130
+ st.session_state.story = [{
1131
+ "role": "AI",
1132
+ "content": starter['en'],
1133
+ "thai_content": starter['th'],
1134
+ "is_starter": True
1135
+ }]
1136
+
1137
  # แสดง theme intro
1138
  st.markdown(f"""
1139
  <div style="background-color: {theme['background_color']};
 
1147
  padding: 15px;
1148
  border-radius: 8px;
1149
  margin-top: 10px;">
1150
+ <p style="color: #666;">AI เริ่มเรื่องให้คุณแล้ว คุณพร้อมที่จะเขียนต่อ:</p>
1151
  <p style="color: #1e88e5;">{starter['th']}</p>
1152
  <p style="color: #333;">{starter['en']}</p>
1153
  </div>
1154
  </div>
1155
  """, unsafe_allow_html=True)
1156
+
 
 
 
 
 
 
 
1157
  st.rerun()
1158
 
1159
  # เพิ่ม CSS สำหรับ theme cards