Update app.py
Browse files
app.py
CHANGED
@@ -1072,93 +1072,119 @@ def init_theme_state():
|
|
1072 |
# Theme Selection UI
|
1073 |
def show_theme_selection():
|
1074 |
st.markdown("""
|
1075 |
-
<div class="
|
1076 |
-
<
|
1077 |
-
<div class="eng">Choose Story Theme</div>
|
1078 |
</div>
|
1079 |
""", unsafe_allow_html=True)
|
1080 |
|
|
|
|
|
1081 |
available_themes = get_available_themes(st.session_state.level)
|
1082 |
|
1083 |
-
#
|
1084 |
-
|
1085 |
-
|
1086 |
-
|
1087 |
-
# สลับระหว่าง column 1 และ 2
|
1088 |
-
with col1 if idx % 2 == 0 else col2:
|
1089 |
-
theme_card = f"""
|
1090 |
-
<div class="theme-card"
|
1091 |
-
style="background-color: {theme['background_color']};
|
1092 |
-
padding: 15px;
|
1093 |
-
border-radius: 10px;
|
1094 |
-
margin: 5px 0;
|
1095 |
-
border: 2px solid {theme['accent_color']};
|
1096 |
-
cursor: pointer;">
|
1097 |
-
<h3>{theme['icon']} {theme['name_th']}</h3>
|
1098 |
-
<p style="font-size: 0.9em; color: #666;">
|
1099 |
-
{theme['description_th']}
|
1100 |
-
</p>
|
1101 |
-
</div>
|
1102 |
-
"""
|
1103 |
-
# ใช้ button แทน markdown สำหรับการคลิก
|
1104 |
-
if st.button(theme['name_th'], key=f"theme_button_{theme['id']}", help=theme['description_th']):
|
1105 |
-
# บันทึกธีมที่เลือก
|
1106 |
-
st.session_state.current_theme = theme['id']
|
1107 |
-
|
1108 |
-
# สร้างจุดเริ่มต้นเรื่อง
|
1109 |
-
starter = generate_dynamic_story_starter(theme['id'], st.session_state.level)
|
1110 |
-
st.session_state.theme_story_starter = starter
|
1111 |
-
|
1112 |
-
# เพิ่มจุดเริ่มต้นเรื่องเป็นประโยคแรกใน story
|
1113 |
-
st.session_state.story = [{
|
1114 |
-
"role": "AI",
|
1115 |
-
"content": starter['en'],
|
1116 |
-
"thai_content": starter['th'],
|
1117 |
-
"is_starter": True
|
1118 |
-
}]
|
1119 |
-
|
1120 |
-
# แสดง theme intro
|
1121 |
-
st.markdown(f"""
|
1122 |
-
<div style="background-color: {theme['background_color']};
|
1123 |
-
padding: 20px;
|
1124 |
-
border-radius: 10px;
|
1125 |
-
margin: 10px 0;
|
1126 |
-
border: 2px solid {theme['accent_color']}">
|
1127 |
-
<h3>{theme['icon']} เริ่มต้นการผจญภัยในธีม {theme['name_th']}</h3>
|
1128 |
-
<p>{theme['description_th']}</p>
|
1129 |
-
<div style="background-color: rgba(255,255,255,0.7);
|
1130 |
-
padding: 15px;
|
1131 |
-
border-radius: 8px;
|
1132 |
-
margin-top: 10px;">
|
1133 |
-
<p style="color: #666;">AI เริ่มเรื่องให้คุณแล้ว คุณพร้อมที่จะเขียนต่อ:</p>
|
1134 |
-
<p style="color: #1e88e5;">{starter['th']}</p>
|
1135 |
-
<p style="color: #333;">{starter['en']}</p>
|
1136 |
-
</div>
|
1137 |
-
</div>
|
1138 |
-
""", unsafe_allow_html=True)
|
1139 |
|
1140 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1141 |
|
1142 |
# เพิ่ม CSS สำหรับ theme cards
|
1143 |
st.markdown("""
|
1144 |
<style>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1145 |
.theme-card {
|
1146 |
-
|
|
|
1147 |
}
|
|
|
1148 |
.theme-card:hover {
|
1149 |
-
transform: translateY(-
|
1150 |
-
box-shadow: 0
|
1151 |
}
|
1152 |
-
|
1153 |
-
|
1154 |
-
|
1155 |
-
|
|
|
|
|
1156 |
width: 100%;
|
1157 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1158 |
}
|
1159 |
-
|
1160 |
-
|
1161 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1162 |
}
|
1163 |
</style>
|
1164 |
""", unsafe_allow_html=True)
|
|
|
1072 |
# Theme Selection UI
|
1073 |
def show_theme_selection():
|
1074 |
st.markdown("""
|
1075 |
+
<div class="theme-header">
|
1076 |
+
<h3>🎨 เลือกธีมเรื่องราว | Choose Story Theme</h3>
|
|
|
1077 |
</div>
|
1078 |
""", unsafe_allow_html=True)
|
1079 |
|
1080 |
+
# สร้าง 2 rows, แต่ละ row มี 4 themes
|
1081 |
+
themes_per_row = 4
|
1082 |
available_themes = get_available_themes(st.session_state.level)
|
1083 |
|
1084 |
+
# แบ่งธีมเป็น 2 rows
|
1085 |
+
for i in range(0, len(available_themes), themes_per_row):
|
1086 |
+
row_themes = available_themes[i:i + themes_per_row]
|
1087 |
+
cols = st.columns(themes_per_row)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1088 |
|
1089 |
+
for col, theme in zip(cols, row_themes):
|
1090 |
+
with col:
|
1091 |
+
# สร้าง theme card แบบ interactive
|
1092 |
+
theme_card = f"""
|
1093 |
+
<div class="theme-card"
|
1094 |
+
onclick="this.classList.toggle('selected')"
|
1095 |
+
style="background: linear-gradient(135deg, {theme['background_color']}, white);
|
1096 |
+
border: 2px solid {theme['accent_color']};
|
1097 |
+
border-radius: 12px;
|
1098 |
+
padding: 15px;
|
1099 |
+
margin: 5px;
|
1100 |
+
cursor: pointer;
|
1101 |
+
transition: all 0.3s ease;
|
1102 |
+
box-shadow: 0 2px 5px rgba(0,0,0,0.1);
|
1103 |
+
text-align: center;
|
1104 |
+
min-height: 150px;">
|
1105 |
+
<div style="font-size: 2em; margin-bottom: 8px;">
|
1106 |
+
{theme['icon']}
|
1107 |
+
</div>
|
1108 |
+
<h4 style="color: {theme['accent_color']};
|
1109 |
+
margin: 5px 0;
|
1110 |
+
font-family: 'Sarabun', sans-serif;">
|
1111 |
+
{theme['name_th']}
|
1112 |
+
</h4>
|
1113 |
+
<p style="font-size: 0.85em;
|
1114 |
+
color: #666;
|
1115 |
+
margin-top: 5px;
|
1116 |
+
display: -webkit-box;
|
1117 |
+
-webkit-line-clamp: 2;
|
1118 |
+
-webkit-box-orient: vertical;
|
1119 |
+
overflow: hidden;">
|
1120 |
+
{theme['description_th']}
|
1121 |
+
</p>
|
1122 |
+
</div>
|
1123 |
+
"""
|
1124 |
+
|
1125 |
+
if st.markdown(theme_card, unsafe_allow_html=True):
|
1126 |
+
st.session_state.current_theme = theme['id']
|
1127 |
+
starter = generate_dynamic_story_starter(theme['id'], st.session_state.level)
|
1128 |
+
st.session_state.theme_story_starter = starter
|
1129 |
+
st.rerun()
|
1130 |
|
1131 |
# เพิ่ม CSS สำหรับ theme cards
|
1132 |
st.markdown("""
|
1133 |
<style>
|
1134 |
+
.theme-header {
|
1135 |
+
text-align: center;
|
1136 |
+
margin-bottom: 20px;
|
1137 |
+
}
|
1138 |
+
|
1139 |
+
.theme-header h3 {
|
1140 |
+
color: #1e88e5;
|
1141 |
+
font-family: 'Sarabun', sans-serif;
|
1142 |
+
}
|
1143 |
+
|
1144 |
.theme-card {
|
1145 |
+
position: relative;
|
1146 |
+
overflow: hidden;
|
1147 |
}
|
1148 |
+
|
1149 |
.theme-card:hover {
|
1150 |
+
transform: translateY(-5px);
|
1151 |
+
box-shadow: 0 5px 15px rgba(0,0,0,0.2);
|
1152 |
}
|
1153 |
+
|
1154 |
+
.theme-card:before {
|
1155 |
+
content: '';
|
1156 |
+
position: absolute;
|
1157 |
+
top: 0;
|
1158 |
+
left: 0;
|
1159 |
width: 100%;
|
1160 |
+
height: 100%;
|
1161 |
+
background: linear-gradient(45deg, rgba(255,255,255,0.1), rgba(255,255,255,0.5));
|
1162 |
+
opacity: 0;
|
1163 |
+
transition: opacity 0.3s ease;
|
1164 |
+
}
|
1165 |
+
|
1166 |
+
.theme-card:hover:before {
|
1167 |
+
opacity: 1;
|
1168 |
+
}
|
1169 |
+
|
1170 |
+
.theme-card.selected {
|
1171 |
+
transform: scale(0.98);
|
1172 |
+
box-shadow: 0 2px 5px rgba(0,0,0,0.2);
|
1173 |
}
|
1174 |
+
|
1175 |
+
/* Responsive adjustments */
|
1176 |
+
@media (max-width: 768px) {
|
1177 |
+
.theme-card {
|
1178 |
+
min-height: 120px;
|
1179 |
+
}
|
1180 |
+
|
1181 |
+
.theme-card h4 {
|
1182 |
+
font-size: 0.9em;
|
1183 |
+
}
|
1184 |
+
|
1185 |
+
.theme-card p {
|
1186 |
+
font-size: 0.8em;
|
1187 |
+
}
|
1188 |
}
|
1189 |
</style>
|
1190 |
""", unsafe_allow_html=True)
|