Update app.py
Browse files
app.py
CHANGED
@@ -382,6 +382,13 @@ st.markdown("""
|
|
382 |
transform: translateY(-5px);
|
383 |
box-shadow: 0 5px 15px rgba(0,0,0,0.1);
|
384 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
385 |
|
386 |
.stButton > button {
|
387 |
width: 100%;
|
@@ -1207,31 +1214,52 @@ def show_theme_selection():
|
|
1207 |
available_themes = get_available_themes(st.session_state.level)
|
1208 |
|
1209 |
# แบ่งธีมเป็น rows
|
1210 |
-
for
|
1211 |
row_themes = available_themes[i:i + themes_per_row]
|
1212 |
cols = st.columns(themes_per_row)
|
1213 |
|
1214 |
# แสดงแต่ละธีมใน column
|
1215 |
-
for
|
1216 |
with col:
|
1217 |
-
# สร้าง unique key โดยใช้
|
1218 |
-
unique_key = f"
|
1219 |
|
1220 |
-
#
|
1221 |
-
|
1222 |
-
|
1223 |
-
|
1224 |
-
|
1225 |
-
|
1226 |
-
|
1227 |
-
|
1228 |
-
|
1229 |
-
|
1230 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1231 |
st.session_state.current_theme = theme['id']
|
1232 |
-
# สร้างจุดเริ่มต้นเรื่อง
|
1233 |
starter = generate_dynamic_story_starter(theme['id'], st.session_state.level)
|
1234 |
-
# เพิ่มเป็นประโยคแรกในเรื่อง
|
1235 |
st.session_state.story = [{
|
1236 |
"role": "AI",
|
1237 |
"content": starter['en'],
|
@@ -1240,13 +1268,10 @@ def show_theme_selection():
|
|
1240 |
}]
|
1241 |
st.rerun()
|
1242 |
|
1243 |
-
#
|
1244 |
-
st.
|
1245 |
-
|
1246 |
-
|
1247 |
-
</div>""",
|
1248 |
-
unsafe_allow_html=True
|
1249 |
-
)
|
1250 |
|
1251 |
# เพิ่มช่อ��ว่างด้านล่าง
|
1252 |
st.markdown("<br>", unsafe_allow_html=True)
|
|
|
382 |
transform: translateY(-5px);
|
383 |
box-shadow: 0 5px 15px rgba(0,0,0,0.1);
|
384 |
}
|
385 |
+
|
386 |
+
/* Theme button hover effect */
|
387 |
+
div[style*="cursor: pointer"]:hover {
|
388 |
+
transform: translateY(-5px);
|
389 |
+
box-shadow: 0 5px 15px rgba(0,0,0,0.1);
|
390 |
+
transition: all 0.3s ease;
|
391 |
+
}
|
392 |
|
393 |
.stButton > button {
|
394 |
width: 100%;
|
|
|
1214 |
available_themes = get_available_themes(st.session_state.level)
|
1215 |
|
1216 |
# แบ่งธีมเป็น rows
|
1217 |
+
for i in range(0, len(available_themes), themes_per_row):
|
1218 |
row_themes = available_themes[i:i + themes_per_row]
|
1219 |
cols = st.columns(themes_per_row)
|
1220 |
|
1221 |
# แสดงแต่ละธีมใน column
|
1222 |
+
for col, theme in zip(cols, row_themes):
|
1223 |
with col:
|
1224 |
+
# สร้าง unique key โดยใช้ timestamp และ theme id
|
1225 |
+
unique_key = f"theme_{theme['id']}_{datetime.now().timestamp()}"
|
1226 |
|
1227 |
+
# ใช้ container เพื่อจัดการ layout
|
1228 |
+
with st.container():
|
1229 |
+
# สร้างปุ่มพร้อมสไตล์
|
1230 |
+
button_html = f"""
|
1231 |
+
<div style="
|
1232 |
+
background: linear-gradient(135deg, {theme['background_color']}, white);
|
1233 |
+
border: 2px solid {theme['accent_color']};
|
1234 |
+
border-radius: 12px;
|
1235 |
+
padding: 15px;
|
1236 |
+
margin: 5px;
|
1237 |
+
text-align: center;
|
1238 |
+
min-height: 150px;">
|
1239 |
+
<div style="font-size: 2em; margin-bottom: 8px;">
|
1240 |
+
{theme['icon']}
|
1241 |
+
</div>
|
1242 |
+
<h4 style="color: {theme['accent_color']};
|
1243 |
+
margin: 5px 0;
|
1244 |
+
font-family: 'Sarabun', sans-serif;">
|
1245 |
+
{theme['name_th']}
|
1246 |
+
</h4>
|
1247 |
+
<p style="font-size: 0.85em;
|
1248 |
+
color: #666;
|
1249 |
+
margin-top: 5px;">
|
1250 |
+
{theme['description_th']}
|
1251 |
+
</p>
|
1252 |
+
</div>
|
1253 |
+
"""
|
1254 |
+
|
1255 |
+
# ใช้ clickable div แทน button
|
1256 |
+
if st.markdown(f"""
|
1257 |
+
<div style="cursor: pointer;" onclick="document.getElementById('{unique_key}').click()">
|
1258 |
+
{button_html}
|
1259 |
+
</div>
|
1260 |
+
""", unsafe_allow_html=True):
|
1261 |
st.session_state.current_theme = theme['id']
|
|
|
1262 |
starter = generate_dynamic_story_starter(theme['id'], st.session_state.level)
|
|
|
1263 |
st.session_state.story = [{
|
1264 |
"role": "AI",
|
1265 |
"content": starter['en'],
|
|
|
1268 |
}]
|
1269 |
st.rerun()
|
1270 |
|
1271 |
+
# ซ่อนปุ่มจริงไว้
|
1272 |
+
st.button("Select", key=unique_key, help=theme['description_th'],
|
1273 |
+
on_click=lambda: None,
|
1274 |
+
style="display: none;")
|
|
|
|
|
|
|
1275 |
|
1276 |
# เพิ่มช่อ��ว่างด้านล่าง
|
1277 |
st.markdown("<br>", unsafe_allow_html=True)
|