Spaces:
Sleeping
Sleeping
Update src/streamlit_app.py
Browse files- src/streamlit_app.py +50 -163
src/streamlit_app.py
CHANGED
|
@@ -16,27 +16,19 @@ st.set_page_config(
|
|
| 16 |
initial_sidebar_state="expanded"
|
| 17 |
)
|
| 18 |
|
| 19 |
-
#
|
| 20 |
st.markdown("""
|
| 21 |
<style>
|
| 22 |
@import url('https://fonts.googleapis.com/css2?family=Comic+Neue:wght@700&display=swap');
|
| 23 |
|
| 24 |
.main-container {
|
| 25 |
background: linear-gradient(45deg, #FF6B6B, #4ECDC4, #45B7D1, #96CEB4, #FFEAA7);
|
| 26 |
-
background-size: 400% 400%;
|
| 27 |
-
animation: gradientBG 15s ease infinite;
|
| 28 |
padding: 20px;
|
| 29 |
border-radius: 25px;
|
| 30 |
border: 8px dashed #FFD93D;
|
| 31 |
margin-bottom: 20px;
|
| 32 |
}
|
| 33 |
|
| 34 |
-
@keyframes gradientBG {
|
| 35 |
-
0% { background-position: 0% 50% }
|
| 36 |
-
50% { background-position: 100% 50% }
|
| 37 |
-
100% { background-position: 0% 50% }
|
| 38 |
-
}
|
| 39 |
-
|
| 40 |
.fun-title {
|
| 41 |
font-size: 50px;
|
| 42 |
color: #FF6B6B;
|
|
@@ -55,11 +47,6 @@ st.markdown("""
|
|
| 55 |
font-family: 'Comic Neue', cursive;
|
| 56 |
box-shadow: 0 10px 25px rgba(0,0,0,0.2);
|
| 57 |
margin: 20px 0;
|
| 58 |
-
transition: transform 0.3s ease;
|
| 59 |
-
}
|
| 60 |
-
|
| 61 |
-
.question-box:hover {
|
| 62 |
-
transform: scale(1.02);
|
| 63 |
}
|
| 64 |
|
| 65 |
.stButton > button {
|
|
@@ -88,37 +75,9 @@ st.markdown("""
|
|
| 88 |
font-family: 'Comic Neue', cursive;
|
| 89 |
}
|
| 90 |
|
| 91 |
-
/*
|
| 92 |
-
.gentle-bounce {
|
| 93 |
-
animation: gentleBounce 3s ease-in-out infinite;
|
| 94 |
-
}
|
| 95 |
-
|
| 96 |
-
@keyframes gentleBounce {
|
| 97 |
-
0%, 100% { transform: translateY(0); }
|
| 98 |
-
50% { transform: translateY(-5px); }
|
| 99 |
-
}
|
| 100 |
-
|
| 101 |
-
.soft-pulse {
|
| 102 |
-
animation: softPulse 4s ease-in-out infinite;
|
| 103 |
-
}
|
| 104 |
-
|
| 105 |
-
@keyframes softPulse {
|
| 106 |
-
0%, 100% { transform: scale(1); opacity: 1; }
|
| 107 |
-
50% { transform: scale(1.03); opacity: 0.9; }
|
| 108 |
-
}
|
| 109 |
-
|
| 110 |
-
.slow-rotate {
|
| 111 |
-
animation: slowRotate 8s linear infinite;
|
| 112 |
-
}
|
| 113 |
-
|
| 114 |
-
@keyframes slowRotate {
|
| 115 |
-
from { transform: rotate(0deg); }
|
| 116 |
-
to { transform: rotate(360deg); }
|
| 117 |
-
}
|
| 118 |
-
|
| 119 |
-
/* Celebration elements - only show during celebrations */
|
| 120 |
.celebration-emoji {
|
| 121 |
-
position:
|
| 122 |
font-size: 24px;
|
| 123 |
animation: celebrationFall 2s linear forwards;
|
| 124 |
pointer-events: none;
|
|
@@ -130,7 +89,7 @@ st.markdown("""
|
|
| 130 |
}
|
| 131 |
|
| 132 |
.celebration-confetti {
|
| 133 |
-
position:
|
| 134 |
width: 12px;
|
| 135 |
height: 12px;
|
| 136 |
animation: celebrationConfetti 2s linear forwards;
|
|
@@ -156,22 +115,6 @@ st.markdown("""
|
|
| 156 |
font-size: 40px;
|
| 157 |
}
|
| 158 |
|
| 159 |
-
/* Live activity indicator */
|
| 160 |
-
.live-indicator {
|
| 161 |
-
display: inline-block;
|
| 162 |
-
width: 12px;
|
| 163 |
-
height: 12px;
|
| 164 |
-
background: #4ECDC4;
|
| 165 |
-
border-radius: 50%;
|
| 166 |
-
margin-right: 8px;
|
| 167 |
-
animation: gentleBlink 2s infinite;
|
| 168 |
-
}
|
| 169 |
-
|
| 170 |
-
@keyframes gentleBlink {
|
| 171 |
-
0%, 100% { opacity: 1; }
|
| 172 |
-
50% { opacity: 0.7; }
|
| 173 |
-
}
|
| 174 |
-
|
| 175 |
/* Help box styling */
|
| 176 |
.help-box {
|
| 177 |
background: rgba(255, 255, 255, 0.95);
|
|
@@ -190,12 +133,6 @@ st.markdown("""
|
|
| 190 |
border-radius: 25px;
|
| 191 |
color: white;
|
| 192 |
margin: 20px 0;
|
| 193 |
-
animation: completionPulse 2s ease-in-out;
|
| 194 |
-
}
|
| 195 |
-
|
| 196 |
-
@keyframes completionPulse {
|
| 197 |
-
0% { transform: scale(0.9); opacity: 0; }
|
| 198 |
-
100% { transform: scale(1); opacity: 1; }
|
| 199 |
}
|
| 200 |
|
| 201 |
/* Auto progress countdown */
|
|
@@ -209,10 +146,10 @@ st.markdown("""
|
|
| 209 |
</style>
|
| 210 |
""", unsafe_allow_html=True)
|
| 211 |
|
| 212 |
-
# JavaScript for
|
| 213 |
st.markdown("""
|
| 214 |
<script>
|
| 215 |
-
// Celebration functions
|
| 216 |
function createCelebration() {
|
| 217 |
const emojis = ['π', 'π', 'β', 'π', 'π', 'π'];
|
| 218 |
const colors = ['#FF6B6B', '#4ECDC4', '#FFD93D', '#45B7D1', '#96CEB4'];
|
|
@@ -259,7 +196,6 @@ function startAutoProgression(seconds) {
|
|
| 259 |
|
| 260 |
if (timeLeft < 0) {
|
| 261 |
clearInterval(timer);
|
| 262 |
-
// Trigger the Streamlit rerun
|
| 263 |
window.location.reload();
|
| 264 |
}
|
| 265 |
}, 1000);
|
|
@@ -267,7 +203,7 @@ function startAutoProgression(seconds) {
|
|
| 267 |
</script>
|
| 268 |
""", unsafe_allow_html=True)
|
| 269 |
|
| 270 |
-
# Initialize session state
|
| 271 |
def initialize_session_state():
|
| 272 |
if 'app_initialized' not in st.session_state:
|
| 273 |
st.session_state.app_initialized = True
|
|
@@ -279,37 +215,37 @@ def initialize_session_state():
|
|
| 279 |
st.session_state.show_answer = False
|
| 280 |
st.session_state.show_steps = False
|
| 281 |
st.session_state.session_initialized = False
|
| 282 |
-
st.session_state.auto_progress = True
|
| 283 |
|
| 284 |
initialize_session_state()
|
| 285 |
|
| 286 |
-
#
|
| 287 |
st.markdown("""
|
| 288 |
<div class="main-container">
|
| 289 |
<div class="animal-characters">
|
| 290 |
-
<span
|
| 291 |
-
<span
|
| 292 |
-
<span
|
| 293 |
-
<span
|
| 294 |
-
<span
|
| 295 |
</div>
|
| 296 |
<div class="fun-title">
|
| 297 |
-
|
| 298 |
</div>
|
| 299 |
<div style="text-align: center; font-size: 24px; color: #FF6B6B; font-family: 'Comic Neue', cursive;">
|
| 300 |
-
Where Numbers Become Friends! π€
|
| 301 |
</div>
|
| 302 |
</div>
|
| 303 |
""", unsafe_allow_html=True)
|
| 304 |
|
| 305 |
-
# Age group setup
|
| 306 |
age_groups = {
|
| 307 |
"πΆ Little Explorers (4-6)": {"dataset": "src/Datase_of_4-6_Age_Group.xlsx", "zip_file": "src/Image_for_group_4-6.zip", "image_folder": "Image_for_group_4-6", "emoji": "πΆ"},
|
| 308 |
"π Math Adventurers (7-9)": {"dataset": "src/Datase_of_7-9_Age_Group.xlsx", "zip_file": "src/Image_for_group_7-9.zip", "image_folder": "Image_for_group_7-9", "emoji": "π"},
|
| 309 |
"π Math Wizards (13-15)": {"dataset": "src/Datase_of_13-15_Age_Group.xlsx", "zip_file": "src/Image_for_group_13-15.zip", "image_folder": "Image_for_group_13-15", "emoji": "π"}
|
| 310 |
}
|
| 311 |
|
| 312 |
-
# SIDEBAR -
|
| 313 |
with st.sidebar:
|
| 314 |
st.markdown("### π― Quick Help Guide")
|
| 315 |
|
|
@@ -332,20 +268,6 @@ with st.sidebar:
|
|
| 332 |
st.session_state.auto_progress = auto_progress
|
| 333 |
st.rerun()
|
| 334 |
|
| 335 |
-
# Live activity monitor
|
| 336 |
-
st.markdown("### π Activity Monitor")
|
| 337 |
-
activity_time = time.time() - st.session_state.last_activity
|
| 338 |
-
if activity_time < 10:
|
| 339 |
-
status = "π’ Very Active"
|
| 340 |
-
elif activity_time < 30:
|
| 341 |
-
status = "π‘ Active"
|
| 342 |
-
else:
|
| 343 |
-
status = "π΄ Idle"
|
| 344 |
-
|
| 345 |
-
st.metric("Session Status", status)
|
| 346 |
-
|
| 347 |
-
st.markdown("---")
|
| 348 |
-
|
| 349 |
st.markdown("### π Achievement Tips")
|
| 350 |
st.info("""
|
| 351 |
π« **Pro Tips:**
|
|
@@ -403,7 +325,7 @@ with col1:
|
|
| 403 |
st.error(f"β Oh no! The math treasure got mixed up! {e}")
|
| 404 |
st.stop()
|
| 405 |
|
| 406 |
-
# Category selection
|
| 407 |
categories = sorted(df['category'].dropna().unique())
|
| 408 |
category_emojis = {"Addition": "β", "Subtraction": "β", "Multiplication": "βοΈ", "Division": "β", "Geometry": "π", "Algebra": "π"}
|
| 409 |
selected_category = st.selectbox("π Choose Your Math Quest:", options=categories)
|
|
@@ -424,19 +346,19 @@ with col1:
|
|
| 424 |
question = subset_df.iloc[st.session_state.question_index]
|
| 425 |
progress = int((st.session_state.question_index / len(subset_df)) * 100)
|
| 426 |
|
| 427 |
-
#
|
| 428 |
st.markdown(f"""
|
| 429 |
<div style="text-align: center; margin: 20px 0;">
|
| 430 |
<div style="font-family: 'Comic Neue', cursive; color: #FF6B6B; font-size: 18px;">
|
| 431 |
π― Adventure Progress: {st.session_state.question_index + 1} of {len(subset_df)}
|
| 432 |
</div>
|
| 433 |
<div class="progress-bar" style="width: 100%; background: #f0f0f0; border-radius: 10px; height: 25px;">
|
| 434 |
-
<div style="width: {progress}%; background: linear-gradient(45deg, #FF6B6B, #FFD93D); height: 100%; border-radius: 10px;
|
| 435 |
</div>
|
| 436 |
</div>
|
| 437 |
""", unsafe_allow_html=True)
|
| 438 |
|
| 439 |
-
# Display question
|
| 440 |
category_emoji = category_emojis.get(selected_category, "β")
|
| 441 |
st.markdown(f"""
|
| 442 |
<div class="question-box">
|
|
@@ -462,37 +384,34 @@ with col1:
|
|
| 462 |
except:
|
| 463 |
pass
|
| 464 |
if not image_found:
|
| 465 |
-
st.warning("πΌοΈ
|
| 466 |
|
| 467 |
-
#
|
| 468 |
-
user_ans = st.text_input("βοΈ Your
|
| 469 |
|
| 470 |
-
#
|
| 471 |
col_btn1, col_btn2, col_btn3 = st.columns([1, 1, 1])
|
| 472 |
|
| 473 |
with col_btn1:
|
| 474 |
if st.button("π― Submit Answer", key=f"submit_{st.session_state.question_index}", use_container_width=True):
|
| 475 |
st.session_state.last_activity = time.time()
|
| 476 |
if str(user_ans).strip().lower() == str(question['answer']).strip().lower():
|
| 477 |
-
#
|
| 478 |
st.markdown("""
|
| 479 |
<script>
|
| 480 |
createCelebration();
|
| 481 |
</script>
|
| 482 |
""", unsafe_allow_html=True)
|
| 483 |
|
| 484 |
-
st.success("πβ¨
|
| 485 |
-
|
| 486 |
-
# Gentle balloons
|
| 487 |
st.balloons()
|
| 488 |
|
| 489 |
-
# Success message
|
| 490 |
success_messages = [
|
| 491 |
-
"π You're
|
| 492 |
-
"π
|
| 493 |
-
"π
|
| 494 |
-
"π
|
| 495 |
-
"π¦
|
| 496 |
]
|
| 497 |
|
| 498 |
st.markdown(f"""
|
|
@@ -509,7 +428,7 @@ with col1:
|
|
| 509 |
st.session_state.last_activity = time.time()
|
| 510 |
st.rerun()
|
| 511 |
else:
|
| 512 |
-
st.error("β
|
| 513 |
st.session_state.show_answer = True
|
| 514 |
st.session_state.show_steps = False
|
| 515 |
|
|
@@ -517,48 +436,43 @@ with col1:
|
|
| 517 |
if st.button("π Show Hint", key=f"hint_{st.session_state.question_index}", use_container_width=True):
|
| 518 |
st.session_state.last_activity = time.time()
|
| 519 |
st.session_state.show_answer = True
|
| 520 |
-
st.info("π‘
|
| 521 |
|
| 522 |
with col_btn3:
|
| 523 |
-
if st.button("βοΈ Skip
|
| 524 |
st.session_state.last_activity = time.time()
|
| 525 |
st.session_state.question_index += 1
|
| 526 |
st.session_state.show_answer = False
|
| 527 |
st.session_state.show_steps = False
|
| 528 |
-
st.info("
|
| 529 |
time.sleep(1)
|
| 530 |
st.rerun()
|
| 531 |
|
| 532 |
-
# Show answer
|
| 533 |
if st.session_state.show_answer:
|
| 534 |
-
st.info(f""
|
| 535 |
-
π‘ **Hint from Your Math Friend:**
|
| 536 |
-
The magical answer is **{question['answer']}**
|
| 537 |
-
|
| 538 |
-
Remember: Even math superheroes need help sometimes! π¦Έ
|
| 539 |
-
""")
|
| 540 |
|
| 541 |
if selected_age_group in ["π Math Adventurers (7-9)", "π Math Wizards (13-15)"]:
|
| 542 |
-
if st.button("
|
| 543 |
st.session_state.last_activity = time.time()
|
| 544 |
st.session_state.show_steps = True
|
| 545 |
if st.session_state.show_steps and pd.notna(question.get("steps", None)):
|
| 546 |
-
st.success(f"###
|
| 547 |
|
| 548 |
elif subset_df.empty:
|
| 549 |
-
st.warning("β οΈ
|
| 550 |
else:
|
| 551 |
-
# COMPLETION
|
| 552 |
st.markdown("""
|
| 553 |
<div class="completion-celebration">
|
| 554 |
<div style="font-size: 60px; margin-bottom: 20px;">
|
| 555 |
ππβ¨
|
| 556 |
</div>
|
| 557 |
<h1 style="font-family: 'Comic Neue', cursive;">
|
| 558 |
-
|
| 559 |
</h1>
|
| 560 |
<p style="font-size: 24px;">
|
| 561 |
-
You've completed all
|
| 562 |
</p>
|
| 563 |
<div style="font-size: 40px; margin: 20px 0;">
|
| 564 |
πππππ
|
|
@@ -570,7 +484,6 @@ with col1:
|
|
| 570 |
|
| 571 |
# Auto-progress logic
|
| 572 |
if st.session_state.auto_progress:
|
| 573 |
-
# Show countdown and auto-progress
|
| 574 |
st.markdown("""
|
| 575 |
<div class="countdown" id="countdown-timer">
|
| 576 |
Next adventure starting in: 5 seconds
|
|
@@ -580,22 +493,20 @@ with col1:
|
|
| 580 |
</script>
|
| 581 |
""", unsafe_allow_html=True)
|
| 582 |
|
| 583 |
-
# Wait and auto-progress
|
| 584 |
time.sleep(5)
|
| 585 |
st.session_state.question_index = 0
|
| 586 |
st.session_state.show_answer = False
|
| 587 |
st.session_state.show_steps = False
|
| 588 |
|
| 589 |
-
# Move to next category
|
| 590 |
current_idx = categories.index(selected_category)
|
| 591 |
if current_idx < len(categories) - 1:
|
| 592 |
st.session_state.category = categories[current_idx + 1]
|
| 593 |
else:
|
| 594 |
-
st.session_state.category = categories[0]
|
| 595 |
|
| 596 |
st.rerun()
|
| 597 |
else:
|
| 598 |
-
# Manual progression
|
| 599 |
if st.button("π Start New Adventure", use_container_width=True):
|
| 600 |
st.session_state.last_activity = time.time()
|
| 601 |
st.session_state.question_index = 0
|
|
@@ -607,38 +518,14 @@ with col2:
|
|
| 607 |
st.markdown("### π¨ Fun Zone")
|
| 608 |
st.markdown("""
|
| 609 |
<div style="text-align: center; font-size: 40px; margin: 20px 0;">
|
| 610 |
-
|
| 611 |
-
<span class="slow-rotate">β¨</span><br>
|
| 612 |
-
<span class="soft-pulse">π</span>
|
| 613 |
</div>
|
| 614 |
""", unsafe_allow_html=True)
|
| 615 |
|
| 616 |
-
st.markdown("### π
|
| 617 |
if not subset_df.empty:
|
| 618 |
completed = min(st.session_state.question_index, len(subset_df))
|
| 619 |
-
st.metric("
|
| 620 |
-
|
| 621 |
-
if completed > 0:
|
| 622 |
-
accuracy = "π― Perfect!" if completed == st.session_state.question_index else "π Great!"
|
| 623 |
-
st.metric("Accuracy", accuracy)
|
| 624 |
-
|
| 625 |
-
st.markdown("### π« Pro Tip")
|
| 626 |
-
st.info("""
|
| 627 |
-
β¨ **Math Superpower:**
|
| 628 |
-
Use scrap paper to work out
|
| 629 |
-
tricky problems! It's like
|
| 630 |
-
having a math sidekick! π¦ΈββοΈ
|
| 631 |
-
""")
|
| 632 |
-
|
| 633 |
-
# Add periodic invisible updates to prevent sleeping
|
| 634 |
-
if 'update_counter' not in st.session_state:
|
| 635 |
-
st.session_state.update_counter = 0
|
| 636 |
-
|
| 637 |
-
st.session_state.update_counter += 1
|
| 638 |
-
|
| 639 |
-
# This creates a very subtle continuous activity
|
| 640 |
-
if st.session_state.update_counter % 10 == 0:
|
| 641 |
-
st.markdown(f'<div style="display:none">{random.random()}</div>', unsafe_allow_html=True)
|
| 642 |
|
| 643 |
# Cleanup function
|
| 644 |
def cleanup():
|
|
|
|
| 16 |
initial_sidebar_state="expanded"
|
| 17 |
)
|
| 18 |
|
| 19 |
+
# Clean, stable CSS without excessive animations
|
| 20 |
st.markdown("""
|
| 21 |
<style>
|
| 22 |
@import url('https://fonts.googleapis.com/css2?family=Comic+Neue:wght@700&display=swap');
|
| 23 |
|
| 24 |
.main-container {
|
| 25 |
background: linear-gradient(45deg, #FF6B6B, #4ECDC4, #45B7D1, #96CEB4, #FFEAA7);
|
|
|
|
|
|
|
| 26 |
padding: 20px;
|
| 27 |
border-radius: 25px;
|
| 28 |
border: 8px dashed #FFD93D;
|
| 29 |
margin-bottom: 20px;
|
| 30 |
}
|
| 31 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 32 |
.fun-title {
|
| 33 |
font-size: 50px;
|
| 34 |
color: #FF6B6B;
|
|
|
|
| 47 |
font-family: 'Comic Neue', cursive;
|
| 48 |
box-shadow: 0 10px 25px rgba(0,0,0,0.2);
|
| 49 |
margin: 20px 0;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 50 |
}
|
| 51 |
|
| 52 |
.stButton > button {
|
|
|
|
| 75 |
font-family: 'Comic Neue', cursive;
|
| 76 |
}
|
| 77 |
|
| 78 |
+
/* Only show animations during celebrations */
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 79 |
.celebration-emoji {
|
| 80 |
+
position: fixed;
|
| 81 |
font-size: 24px;
|
| 82 |
animation: celebrationFall 2s linear forwards;
|
| 83 |
pointer-events: none;
|
|
|
|
| 89 |
}
|
| 90 |
|
| 91 |
.celebration-confetti {
|
| 92 |
+
position: fixed;
|
| 93 |
width: 12px;
|
| 94 |
height: 12px;
|
| 95 |
animation: celebrationConfetti 2s linear forwards;
|
|
|
|
| 115 |
font-size: 40px;
|
| 116 |
}
|
| 117 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 118 |
/* Help box styling */
|
| 119 |
.help-box {
|
| 120 |
background: rgba(255, 255, 255, 0.95);
|
|
|
|
| 133 |
border-radius: 25px;
|
| 134 |
color: white;
|
| 135 |
margin: 20px 0;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 136 |
}
|
| 137 |
|
| 138 |
/* Auto progress countdown */
|
|
|
|
| 146 |
</style>
|
| 147 |
""", unsafe_allow_html=True)
|
| 148 |
|
| 149 |
+
# JavaScript for celebrations only (no initial animations)
|
| 150 |
st.markdown("""
|
| 151 |
<script>
|
| 152 |
+
// Celebration functions - ONLY during correct answers
|
| 153 |
function createCelebration() {
|
| 154 |
const emojis = ['π', 'π', 'β', 'π', 'π', 'π'];
|
| 155 |
const colors = ['#FF6B6B', '#4ECDC4', '#FFD93D', '#45B7D1', '#96CEB4'];
|
|
|
|
| 196 |
|
| 197 |
if (timeLeft < 0) {
|
| 198 |
clearInterval(timer);
|
|
|
|
| 199 |
window.location.reload();
|
| 200 |
}
|
| 201 |
}, 1000);
|
|
|
|
| 203 |
</script>
|
| 204 |
""", unsafe_allow_html=True)
|
| 205 |
|
| 206 |
+
# Initialize session state
|
| 207 |
def initialize_session_state():
|
| 208 |
if 'app_initialized' not in st.session_state:
|
| 209 |
st.session_state.app_initialized = True
|
|
|
|
| 215 |
st.session_state.show_answer = False
|
| 216 |
st.session_state.show_steps = False
|
| 217 |
st.session_state.session_initialized = False
|
| 218 |
+
st.session_state.auto_progress = True
|
| 219 |
|
| 220 |
initialize_session_state()
|
| 221 |
|
| 222 |
+
# Clean, stable welcome title - NO ANIMATIONS
|
| 223 |
st.markdown("""
|
| 224 |
<div class="main-container">
|
| 225 |
<div class="animal-characters">
|
| 226 |
+
<span>π±</span>
|
| 227 |
+
<span>πΆ</span>
|
| 228 |
+
<span>π¦</span>
|
| 229 |
+
<span>πΌ</span>
|
| 230 |
+
<span>π―</span>
|
| 231 |
</div>
|
| 232 |
<div class="fun-title">
|
| 233 |
+
πͺ Welcome to Math Adventure Land! πͺ
|
| 234 |
</div>
|
| 235 |
<div style="text-align: center; font-size: 24px; color: #FF6B6B; font-family: 'Comic Neue', cursive;">
|
| 236 |
+
Where Numbers Become Friends! π€ β¨
|
| 237 |
</div>
|
| 238 |
</div>
|
| 239 |
""", unsafe_allow_html=True)
|
| 240 |
|
| 241 |
+
# Age group setup
|
| 242 |
age_groups = {
|
| 243 |
"πΆ Little Explorers (4-6)": {"dataset": "src/Datase_of_4-6_Age_Group.xlsx", "zip_file": "src/Image_for_group_4-6.zip", "image_folder": "Image_for_group_4-6", "emoji": "πΆ"},
|
| 244 |
"π Math Adventurers (7-9)": {"dataset": "src/Datase_of_7-9_Age_Group.xlsx", "zip_file": "src/Image_for_group_7-9.zip", "image_folder": "Image_for_group_7-9", "emoji": "π"},
|
| 245 |
"π Math Wizards (13-15)": {"dataset": "src/Datase_of_13-15_Age_Group.xlsx", "zip_file": "src/Image_for_group_13-15.zip", "image_folder": "Image_for_group_13-15", "emoji": "π"}
|
| 246 |
}
|
| 247 |
|
| 248 |
+
# SIDEBAR - Clean and stable
|
| 249 |
with st.sidebar:
|
| 250 |
st.markdown("### π― Quick Help Guide")
|
| 251 |
|
|
|
|
| 268 |
st.session_state.auto_progress = auto_progress
|
| 269 |
st.rerun()
|
| 270 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 271 |
st.markdown("### π Achievement Tips")
|
| 272 |
st.info("""
|
| 273 |
π« **Pro Tips:**
|
|
|
|
| 325 |
st.error(f"β Oh no! The math treasure got mixed up! {e}")
|
| 326 |
st.stop()
|
| 327 |
|
| 328 |
+
# Category selection
|
| 329 |
categories = sorted(df['category'].dropna().unique())
|
| 330 |
category_emojis = {"Addition": "β", "Subtraction": "β", "Multiplication": "βοΈ", "Division": "β", "Geometry": "π", "Algebra": "π"}
|
| 331 |
selected_category = st.selectbox("π Choose Your Math Quest:", options=categories)
|
|
|
|
| 346 |
question = subset_df.iloc[st.session_state.question_index]
|
| 347 |
progress = int((st.session_state.question_index / len(subset_df)) * 100)
|
| 348 |
|
| 349 |
+
# Progress bar
|
| 350 |
st.markdown(f"""
|
| 351 |
<div style="text-align: center; margin: 20px 0;">
|
| 352 |
<div style="font-family: 'Comic Neue', cursive; color: #FF6B6B; font-size: 18px;">
|
| 353 |
π― Adventure Progress: {st.session_state.question_index + 1} of {len(subset_df)}
|
| 354 |
</div>
|
| 355 |
<div class="progress-bar" style="width: 100%; background: #f0f0f0; border-radius: 10px; height: 25px;">
|
| 356 |
+
<div style="width: {progress}%; background: linear-gradient(45deg, #FF6B6B, #FFD93D); height: 100%; border-radius: 10px;"></div>
|
| 357 |
</div>
|
| 358 |
</div>
|
| 359 |
""", unsafe_allow_html=True)
|
| 360 |
|
| 361 |
+
# Display question - NO ANIMATIONS
|
| 362 |
category_emoji = category_emojis.get(selected_category, "β")
|
| 363 |
st.markdown(f"""
|
| 364 |
<div class="question-box">
|
|
|
|
| 384 |
except:
|
| 385 |
pass
|
| 386 |
if not image_found:
|
| 387 |
+
st.warning("πΌοΈ Image not found for this question")
|
| 388 |
|
| 389 |
+
# Answer input
|
| 390 |
+
user_ans = st.text_input("βοΈ Your Answer:", key=f"ans_{st.session_state.question_index}")
|
| 391 |
|
| 392 |
+
# Action buttons
|
| 393 |
col_btn1, col_btn2, col_btn3 = st.columns([1, 1, 1])
|
| 394 |
|
| 395 |
with col_btn1:
|
| 396 |
if st.button("π― Submit Answer", key=f"submit_{st.session_state.question_index}", use_container_width=True):
|
| 397 |
st.session_state.last_activity = time.time()
|
| 398 |
if str(user_ans).strip().lower() == str(question['answer']).strip().lower():
|
| 399 |
+
# CELEBRATION ONLY HAPPENS HERE - when answer is correct
|
| 400 |
st.markdown("""
|
| 401 |
<script>
|
| 402 |
createCelebration();
|
| 403 |
</script>
|
| 404 |
""", unsafe_allow_html=True)
|
| 405 |
|
| 406 |
+
st.success("πβ¨ CORRECT! Amazing work! β¨π")
|
|
|
|
|
|
|
| 407 |
st.balloons()
|
| 408 |
|
|
|
|
| 409 |
success_messages = [
|
| 410 |
+
"π You're a math superstar!",
|
| 411 |
+
"π Excellent work!",
|
| 412 |
+
"π Brilliant answer!",
|
| 413 |
+
"π Perfect!",
|
| 414 |
+
"π¦ Outstanding!"
|
| 415 |
]
|
| 416 |
|
| 417 |
st.markdown(f"""
|
|
|
|
| 428 |
st.session_state.last_activity = time.time()
|
| 429 |
st.rerun()
|
| 430 |
else:
|
| 431 |
+
st.error("β Not quite right. Try again! π«")
|
| 432 |
st.session_state.show_answer = True
|
| 433 |
st.session_state.show_steps = False
|
| 434 |
|
|
|
|
| 436 |
if st.button("π Show Hint", key=f"hint_{st.session_state.question_index}", use_container_width=True):
|
| 437 |
st.session_state.last_activity = time.time()
|
| 438 |
st.session_state.show_answer = True
|
| 439 |
+
st.info("π‘ Need some help? Here's the answer below!")
|
| 440 |
|
| 441 |
with col_btn3:
|
| 442 |
+
if st.button("βοΈ Skip", key=f"skip_{st.session_state.question_index}", use_container_width=True):
|
| 443 |
st.session_state.last_activity = time.time()
|
| 444 |
st.session_state.question_index += 1
|
| 445 |
st.session_state.show_answer = False
|
| 446 |
st.session_state.show_steps = False
|
| 447 |
+
st.info("Moving to next challenge...")
|
| 448 |
time.sleep(1)
|
| 449 |
st.rerun()
|
| 450 |
|
| 451 |
+
# Show answer
|
| 452 |
if st.session_state.show_answer:
|
| 453 |
+
st.info(f"π‘ **Correct Answer:** **{question['answer']}**")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 454 |
|
| 455 |
if selected_age_group in ["π Math Adventurers (7-9)", "π Math Wizards (13-15)"]:
|
| 456 |
+
if st.button("π Show Steps", key=f"steps_{st.session_state.question_index}"):
|
| 457 |
st.session_state.last_activity = time.time()
|
| 458 |
st.session_state.show_steps = True
|
| 459 |
if st.session_state.show_steps and pd.notna(question.get("steps", None)):
|
| 460 |
+
st.success(f"### Step-by-Step Solution:\n{question['steps']}")
|
| 461 |
|
| 462 |
elif subset_df.empty:
|
| 463 |
+
st.warning("β οΈ No questions available in this category. Try another one!")
|
| 464 |
else:
|
| 465 |
+
# COMPLETION MESSAGE
|
| 466 |
st.markdown("""
|
| 467 |
<div class="completion-celebration">
|
| 468 |
<div style="font-size: 60px; margin-bottom: 20px;">
|
| 469 |
ππβ¨
|
| 470 |
</div>
|
| 471 |
<h1 style="font-family: 'Comic Neue', cursive;">
|
| 472 |
+
CONGRATULATIONS! π
|
| 473 |
</h1>
|
| 474 |
<p style="font-size: 24px;">
|
| 475 |
+
You've completed all challenges in this category!
|
| 476 |
</p>
|
| 477 |
<div style="font-size: 40px; margin: 20px 0;">
|
| 478 |
πππππ
|
|
|
|
| 484 |
|
| 485 |
# Auto-progress logic
|
| 486 |
if st.session_state.auto_progress:
|
|
|
|
| 487 |
st.markdown("""
|
| 488 |
<div class="countdown" id="countdown-timer">
|
| 489 |
Next adventure starting in: 5 seconds
|
|
|
|
| 493 |
</script>
|
| 494 |
""", unsafe_allow_html=True)
|
| 495 |
|
|
|
|
| 496 |
time.sleep(5)
|
| 497 |
st.session_state.question_index = 0
|
| 498 |
st.session_state.show_answer = False
|
| 499 |
st.session_state.show_steps = False
|
| 500 |
|
| 501 |
+
# Move to next category
|
| 502 |
current_idx = categories.index(selected_category)
|
| 503 |
if current_idx < len(categories) - 1:
|
| 504 |
st.session_state.category = categories[current_idx + 1]
|
| 505 |
else:
|
| 506 |
+
st.session_state.category = categories[0]
|
| 507 |
|
| 508 |
st.rerun()
|
| 509 |
else:
|
|
|
|
| 510 |
if st.button("π Start New Adventure", use_container_width=True):
|
| 511 |
st.session_state.last_activity = time.time()
|
| 512 |
st.session_state.question_index = 0
|
|
|
|
| 518 |
st.markdown("### π¨ Fun Zone")
|
| 519 |
st.markdown("""
|
| 520 |
<div style="text-align: center; font-size: 40px; margin: 20px 0;">
|
| 521 |
+
πͺ<br>β¨<br>π
|
|
|
|
|
|
|
| 522 |
</div>
|
| 523 |
""", unsafe_allow_html=True)
|
| 524 |
|
| 525 |
+
st.markdown("### π Progress")
|
| 526 |
if not subset_df.empty:
|
| 527 |
completed = min(st.session_state.question_index, len(subset_df))
|
| 528 |
+
st.metric("Completed", f"{completed}/{len(subset_df)}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 529 |
|
| 530 |
# Cleanup function
|
| 531 |
def cleanup():
|