Rathapoom commited on
Commit
a9ff0bd
·
verified ·
1 Parent(s): d7c85f1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +82 -13
app.py CHANGED
@@ -402,6 +402,10 @@ st.markdown("""
402
 
403
  # Initialize session state variables
404
  def init_session_state():
 
 
 
 
405
  if 'story' not in st.session_state:
406
  st.session_state.story = []
407
  if 'feedback' not in st.session_state:
@@ -1070,28 +1074,93 @@ def show_theme_selection():
1070
 
1071
  available_themes = get_available_themes(st.session_state.level)
1072
 
1073
- # Create theme selection cards
1074
- cols = st.columns(2)
 
1075
  for idx, theme in enumerate(available_themes):
1076
- with cols[idx % 2]:
 
1077
  theme_card = f"""
1078
- <div style="
1079
- background-color: {theme['background_color']};
1080
- padding: 15px;
1081
- border-radius: 10px;
1082
- margin: 5px 0;
1083
- border: 2px solid {theme['accent_color']};
1084
- cursor: pointer;
1085
- ">
1086
  <h3>{theme['icon']} {theme['name_th']}</h3>
1087
  <p style="font-size: 0.9em; color: #666;">
1088
  {theme['description_th']}
1089
  </p>
1090
  </div>
1091
  """
1092
- if st.markdown(theme_card, unsafe_allow_html=True):
 
 
 
 
 
 
 
1093
  st.session_state.current_theme = theme['id']
1094
- st.session_state.theme_story_starter = get_theme_story_starter(theme['id'], st.session_state.level)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1095
 
1096
  # Add theme-specific CSS
1097
  def add_theme_css():
 
402
 
403
  # Initialize session state variables
404
  def init_session_state():
405
+ if 'current_theme' not in st.session_state:
406
+ st.session_state.current_theme = None
407
+ if 'theme_story_starter' not in st.session_state:
408
+ st.session_state.theme_story_starter = None
409
  if 'story' not in st.session_state:
410
  st.session_state.story = []
411
  if 'feedback' not in st.session_state:
 
1074
 
1075
  available_themes = get_available_themes(st.session_state.level)
1076
 
1077
+ # สร้าง 2 columns สำหรับแสดงธีม
1078
+ col1, col2 = st.columns(2)
1079
+
1080
  for idx, theme in enumerate(available_themes):
1081
+ # สลับระหว่าง column 1 และ 2
1082
+ with col1 if idx % 2 == 0 else col2:
1083
  theme_card = f"""
1084
+ <div class="theme-card"
1085
+ style="background-color: {theme['background_color']};
1086
+ padding: 15px;
1087
+ border-radius: 10px;
1088
+ margin: 5px 0;
1089
+ border: 2px solid {theme['accent_color']};
1090
+ cursor: pointer;">
 
1091
  <h3>{theme['icon']} {theme['name_th']}</h3>
1092
  <p style="font-size: 0.9em; color: #666;">
1093
  {theme['description_th']}
1094
  </p>
1095
  </div>
1096
  """
1097
+ # ใช้ button แทน markdown สำหรับการคลิก
1098
+ if st.button(
1099
+ theme['name_th'],
1100
+ key=f"theme_button_{theme['id']}",
1101
+ help=theme['description_th'],
1102
+ use_container_width=True
1103
+ ):
1104
+ # บันทึกธีมที่เลือกใน session state
1105
  st.session_state.current_theme = theme['id']
1106
+
1107
+ # สร้างจุดเริ่มต้นเรื่องแบบไดนามิก
1108
+ starter = generate_dynamic_story_starter(theme['id'], st.session_state.level)
1109
+ st.session_state.theme_story_starter = starter
1110
+
1111
+ # แสดง theme intro
1112
+ st.markdown(f"""
1113
+ <div style="background-color: {theme['background_color']};
1114
+ padding: 20px;
1115
+ border-radius: 10px;
1116
+ margin: 10px 0;
1117
+ border: 2px solid {theme['accent_color']}">
1118
+ <h3>{theme['icon']} เริ่มต้นการผจญภัยในธีม {theme['name_th']}</h3>
1119
+ <p>{theme['description_th']}</p>
1120
+ <div style="background-color: rgba(255,255,255,0.7);
1121
+ padding: 15px;
1122
+ border-radius: 8px;
1123
+ margin-top: 10px;">
1124
+ <p style="color: #666;">จุดเริ่มต้นเรื่องของคุณ:</p>
1125
+ <p style="color: #1e88e5;">{starter['th']}</p>
1126
+ <p style="color: #333;">{starter['en']}</p>
1127
+ </div>
1128
+ </div>
1129
+ """, unsafe_allow_html=True)
1130
+
1131
+ # เพิ่มคำแนะนำการเขียน
1132
+ st.info("📝 เริ่มเขียนเรื่องราวของคุณได้เลย! คุณสามารถใช้จุดเริ่มต้นด้านบนเป็นแรงบันดาลใจ")
1133
+
1134
+ # แสดงคำศัพท์แนะนำสำหรับธีมนี้
1135
+ with st.expander("📚 คำศัพท์แนะนำสำหรับธีมนี้"):
1136
+ show_theme_vocabulary()
1137
+
1138
+ st.rerun()
1139
+
1140
+ # เพิ่ม CSS สำหรับ theme cards
1141
+ st.markdown("""
1142
+ <style>
1143
+ .theme-card {
1144
+ transition: transform 0.2s, box-shadow 0.2s;
1145
+ }
1146
+ .theme-card:hover {
1147
+ transform: translateY(-2px);
1148
+ box-shadow: 0 4px 6px rgba(0,0,0,0.1);
1149
+ }
1150
+ .stButton button {
1151
+ background-color: transparent;
1152
+ border: none;
1153
+ text-align: left;
1154
+ width: 100%;
1155
+ padding: 0;
1156
+ }
1157
+ .stButton button:hover {
1158
+ background-color: transparent;
1159
+ border: none;
1160
+ }
1161
+ </style>
1162
+ """, unsafe_allow_html=True)
1163
+
1164
 
1165
  # Add theme-specific CSS
1166
  def add_theme_css():