Rathapoom commited on
Commit
d85f1b5
·
verified ·
1 Parent(s): 57701ef

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +61 -101
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
- # แบ่งธีมเป็น 2 rows
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
- # สร้าง theme card แบบ interactive
1188
- theme_card = f"""
1189
- <div class="theme-card"
1190
- onclick="this.classList.toggle('selected')"
1191
- style="background: linear-gradient(135deg, {theme['background_color']}, white);
1192
- border: 2px solid {theme['accent_color']};
1193
- border-radius: 12px;
1194
- padding: 15px;
1195
- margin: 5px;
1196
- cursor: pointer;
1197
- transition: all 0.3s ease;
1198
- box-shadow: 0 2px 5px rgba(0,0,0,0.1);
1199
- text-align: center;
1200
- min-height: 150px;">
1201
- <div style="font-size: 2em; margin-bottom: 8px;">
1202
- {theme['icon']}
1203
- </div>
1204
- <h4 style="color: {theme['accent_color']};
1205
- margin: 5px 0;
1206
- font-family: 'Sarabun', sans-serif;">
1207
- {theme['name_th']}
1208
- </h4>
1209
- <p style="font-size: 0.85em;
1210
- color: #666;
1211
- margin-top: 5px;
1212
- display: -webkit-box;
1213
- -webkit-line-clamp: 2;
1214
- -webkit-box-orient: vertical;
1215
- overflow: hidden;">
1216
- {theme['description_th']}
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