Update app.py
Browse files
app.py
CHANGED
@@ -369,6 +369,35 @@ st.markdown("""
|
|
369 |
<style>
|
370 |
@import url('https://fonts.googleapis.com/css2?family=Sarabun:wght@400;700&display=swap');
|
371 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
372 |
/* ส่วน CSS เดิม */
|
373 |
.thai-eng {
|
374 |
font-size: 1.1em;
|
@@ -1177,113 +1206,44 @@ def show_theme_selection():
|
|
1177 |
themes_per_row = 4
|
1178 |
available_themes = get_available_themes(st.session_state.level)
|
1179 |
|
1180 |
-
# แบ่งธีมเป็น
|
1181 |
for i in range(0, len(available_themes), themes_per_row):
|
1182 |
row_themes = available_themes[i:i + themes_per_row]
|
1183 |
cols = st.columns(themes_per_row)
|
1184 |
|
|
|
1185 |
for col, theme in zip(cols, row_themes):
|
1186 |
with col:
|
1187 |
-
# สร้าง
|
1188 |
-
|
1189 |
-
|
1190 |
-
|
1191 |
-
|
1192 |
-
|
1193 |
-
|
1194 |
-
|
1195 |
-
|
1196 |
-
|
1197 |
-
|
1198 |
-
|
1199 |
-
|
1200 |
-
|
1201 |
-
|
1202 |
-
{
|
1203 |
-
|
1204 |
-
|
1205 |
-
|
1206 |
-
|
1207 |
-
|
1208 |
-
|
1209 |
-
|
1210 |
-
|
1211 |
-
|
1212 |
-
|
1213 |
-
|
1214 |
-
|
1215 |
-
|
1216 |
-
|
1217 |
-
</p>
|
1218 |
-
</div>
|
1219 |
-
"""
|
1220 |
-
|
1221 |
-
if st.markdown(theme_card, unsafe_allow_html=True):
|
1222 |
-
st.session_state.current_theme = theme['id']
|
1223 |
-
starter = generate_dynamic_story_starter(theme['id'], st.session_state.level)
|
1224 |
-
st.session_state.theme_story_starter = starter
|
1225 |
-
st.rerun()
|
1226 |
-
|
1227 |
-
# เพิ่ม CSS สำหรับ theme cards
|
1228 |
-
st.markdown("""
|
1229 |
-
<style>
|
1230 |
-
.theme-header {
|
1231 |
-
text-align: center;
|
1232 |
-
margin-bottom: 20px;
|
1233 |
-
}
|
1234 |
-
|
1235 |
-
.theme-header h3 {
|
1236 |
-
color: #1e88e5;
|
1237 |
-
font-family: 'Sarabun', sans-serif;
|
1238 |
-
}
|
1239 |
-
|
1240 |
-
.theme-card {
|
1241 |
-
position: relative;
|
1242 |
-
overflow: hidden;
|
1243 |
-
}
|
1244 |
-
|
1245 |
-
.theme-card:hover {
|
1246 |
-
transform: translateY(-5px);
|
1247 |
-
box-shadow: 0 5px 15px rgba(0,0,0,0.2);
|
1248 |
-
}
|
1249 |
-
|
1250 |
-
.theme-card:before {
|
1251 |
-
content: '';
|
1252 |
-
position: absolute;
|
1253 |
-
top: 0;
|
1254 |
-
left: 0;
|
1255 |
-
width: 100%;
|
1256 |
-
height: 100%;
|
1257 |
-
background: linear-gradient(45deg, rgba(255,255,255,0.1), rgba(255,255,255,0.5));
|
1258 |
-
opacity: 0;
|
1259 |
-
transition: opacity 0.3s ease;
|
1260 |
-
}
|
1261 |
-
|
1262 |
-
.theme-card:hover:before {
|
1263 |
-
opacity: 1;
|
1264 |
-
}
|
1265 |
-
|
1266 |
-
.theme-card.selected {
|
1267 |
-
transform: scale(0.98);
|
1268 |
-
box-shadow: 0 2px 5px rgba(0,0,0,0.2);
|
1269 |
-
}
|
1270 |
-
|
1271 |
-
/* Responsive adjustments */
|
1272 |
-
@media (max-width: 768px) {
|
1273 |
-
.theme-card {
|
1274 |
-
min-height: 120px;
|
1275 |
-
}
|
1276 |
-
|
1277 |
-
.theme-card h4 {
|
1278 |
-
font-size: 0.9em;
|
1279 |
-
}
|
1280 |
-
|
1281 |
-
.theme-card p {
|
1282 |
-
font-size: 0.8em;
|
1283 |
-
}
|
1284 |
-
}
|
1285 |
-
</style>
|
1286 |
-
""", unsafe_allow_html=True)
|
1287 |
|
1288 |
|
1289 |
# Add theme-specific CSS
|
|
|
369 |
<style>
|
370 |
@import url('https://fonts.googleapis.com/css2?family=Sarabun:wght@400;700&display=swap');
|
371 |
|
372 |
+
/* Theme Layout Styles - ส่วนที่เพิ่มใหม่ */
|
373 |
+
div[data-testid="stHorizontalBlock"] > div {
|
374 |
+
background-color: #ffffff;
|
375 |
+
border-radius: 10px;
|
376 |
+
padding: 10px;
|
377 |
+
margin: 5px;
|
378 |
+
transition: transform 0.2s, box-shadow 0.2s;
|
379 |
+
}
|
380 |
+
|
381 |
+
div[data-testid="stHorizontalBlock"] > div:hover {
|
382 |
+
transform: translateY(-5px);
|
383 |
+
box-shadow: 0 5px 15px rgba(0,0,0,0.1);
|
384 |
+
}
|
385 |
+
|
386 |
+
.stButton > button {
|
387 |
+
width: 100%;
|
388 |
+
height: auto;
|
389 |
+
padding: 15px;
|
390 |
+
background: linear-gradient(135deg, var(--background-color, #f0f2f6), white);
|
391 |
+
border: 2px solid var(--accent-color, #1e88e5);
|
392 |
+
color: var(--accent-color, #1e88e5);
|
393 |
+
}
|
394 |
+
|
395 |
+
.stButton > button:hover {
|
396 |
+
border-color: var(--accent-color, #1e88e5);
|
397 |
+
transform: translateY(-2px);
|
398 |
+
box-shadow: 0 2px 5px rgba(0,0,0,0.1);
|
399 |
+
}
|
400 |
+
|
401 |
/* ส่วน CSS เดิม */
|
402 |
.thai-eng {
|
403 |
font-size: 1.1em;
|
|
|
1206 |
themes_per_row = 4
|
1207 |
available_themes = get_available_themes(st.session_state.level)
|
1208 |
|
1209 |
+
# แบ่งธีมเป็น rows
|
1210 |
for i in range(0, len(available_themes), themes_per_row):
|
1211 |
row_themes = available_themes[i:i + themes_per_row]
|
1212 |
cols = st.columns(themes_per_row)
|
1213 |
|
1214 |
+
# แสดงแต่ละธีมใน column
|
1215 |
for col, theme in zip(cols, row_themes):
|
1216 |
with col:
|
1217 |
+
# สร้าง container สำหรับแต่ละธีม
|
1218 |
+
theme_container = st.container()
|
1219 |
+
with theme_container:
|
1220 |
+
# ใช้ button แทน div
|
1221 |
+
if st.button(
|
1222 |
+
f"{theme['icon']} {theme['name_th']}",
|
1223 |
+
key=f"theme_button_{theme['id']}",
|
1224 |
+
help=theme['description_th'],
|
1225 |
+
use_container_width=True,
|
1226 |
+
):
|
1227 |
+
# เมื่อกดเลือกธีม
|
1228 |
+
st.session_state.current_theme = theme['id']
|
1229 |
+
# สร้างจุดเริ่มต้นเรื่อง
|
1230 |
+
starter = generate_dynamic_story_starter(theme['id'], st.session_state.level)
|
1231 |
+
# เพิ่มเป็นประโยคแรกในเรื่อง
|
1232 |
+
st.session_state.story = [{
|
1233 |
+
"role": "AI",
|
1234 |
+
"content": starter['en'],
|
1235 |
+
"thai_content": starter['th'],
|
1236 |
+
"is_starter": True
|
1237 |
+
}]
|
1238 |
+
st.rerun()
|
1239 |
+
|
1240 |
+
# แสดงคำอธิบายใต้ปุ่ม
|
1241 |
+
st.markdown(
|
1242 |
+
f"""<div style='font-size: 0.85em; color: #666; padding: 5px;'>
|
1243 |
+
{theme['description_th']}
|
1244 |
+
</div>""",
|
1245 |
+
unsafe_allow_html=True
|
1246 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1247 |
|
1248 |
|
1249 |
# Add theme-specific CSS
|