Spaces:
Running
Running
Update src/streamlit_app.py
Browse files- src/streamlit_app.py +25 -98
src/streamlit_app.py
CHANGED
|
@@ -16,7 +16,7 @@ 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');
|
|
@@ -58,13 +58,6 @@ st.markdown("""
|
|
| 58 |
border: none;
|
| 59 |
font-family: 'Comic Neue', cursive;
|
| 60 |
font-weight: bold;
|
| 61 |
-
transition: all 0.3s ease;
|
| 62 |
-
box-shadow: 0 5px 15px rgba(255, 107, 107, 0.4);
|
| 63 |
-
}
|
| 64 |
-
|
| 65 |
-
.stButton > button:hover {
|
| 66 |
-
transform: scale(1.05);
|
| 67 |
-
box-shadow: 0 8px 25px rgba(255, 107, 107, 0.6);
|
| 68 |
}
|
| 69 |
|
| 70 |
.stTextInput > div > input {
|
|
@@ -75,39 +68,19 @@ st.markdown("""
|
|
| 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;
|
| 84 |
-
z-index: 9999;
|
| 85 |
-
}
|
| 86 |
-
|
| 87 |
-
@keyframes celebrationFall {
|
| 88 |
-
to { transform: translateY(100vh) rotate(360deg); opacity: 0; }
|
| 89 |
-
}
|
| 90 |
-
|
| 91 |
-
.celebration-confetti {
|
| 92 |
-
position: fixed;
|
| 93 |
-
width: 12px;
|
| 94 |
-
height: 12px;
|
| 95 |
-
animation: celebrationConfetti 2s linear forwards;
|
| 96 |
-
pointer-events: none;
|
| 97 |
-
z-index: 9998;
|
| 98 |
-
}
|
| 99 |
-
|
| 100 |
-
@keyframes celebrationConfetti {
|
| 101 |
-
to { transform: translateY(100vh) rotate(360deg); opacity: 0; }
|
| 102 |
-
}
|
| 103 |
-
|
| 104 |
.progress-bar {
|
| 105 |
-
background:
|
| 106 |
border-radius: 10px;
|
| 107 |
height: 25px;
|
| 108 |
margin: 20px 0;
|
| 109 |
}
|
| 110 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 111 |
.animal-characters {
|
| 112 |
display: flex;
|
| 113 |
justify-content: space-around;
|
|
@@ -115,7 +88,6 @@ st.markdown("""
|
|
| 115 |
font-size: 40px;
|
| 116 |
}
|
| 117 |
|
| 118 |
-
/* Help box styling */
|
| 119 |
.help-box {
|
| 120 |
background: rgba(255, 255, 255, 0.95);
|
| 121 |
padding: 20px;
|
|
@@ -125,7 +97,6 @@ st.markdown("""
|
|
| 125 |
font-family: 'Comic Neue', cursive;
|
| 126 |
}
|
| 127 |
|
| 128 |
-
/* Completion celebration */
|
| 129 |
.completion-celebration {
|
| 130 |
text-align: center;
|
| 131 |
padding: 40px;
|
|
@@ -135,7 +106,6 @@ st.markdown("""
|
|
| 135 |
margin: 20px 0;
|
| 136 |
}
|
| 137 |
|
| 138 |
-
/* Auto progress countdown */
|
| 139 |
.countdown {
|
| 140 |
font-size: 18px;
|
| 141 |
color: #FF6B6B;
|
|
@@ -146,44 +116,10 @@ st.markdown("""
|
|
| 146 |
</style>
|
| 147 |
""", unsafe_allow_html=True)
|
| 148 |
|
| 149 |
-
#
|
| 150 |
st.markdown("""
|
| 151 |
<script>
|
| 152 |
-
//
|
| 153 |
-
function createCelebration() {
|
| 154 |
-
const emojis = ['π', 'π', 'β', 'π', 'π', 'π'];
|
| 155 |
-
const colors = ['#FF6B6B', '#4ECDC4', '#FFD93D', '#45B7D1', '#96CEB4'];
|
| 156 |
-
|
| 157 |
-
// Create emojis
|
| 158 |
-
for (let i = 0; i < 20; i++) {
|
| 159 |
-
setTimeout(() => {
|
| 160 |
-
const emoji = document.createElement('div');
|
| 161 |
-
emoji.className = 'celebration-emoji';
|
| 162 |
-
emoji.textContent = emojis[Math.floor(Math.random() * emojis.length)];
|
| 163 |
-
emoji.style.left = Math.random() * 100 + 'vw';
|
| 164 |
-
emoji.style.animationDuration = (Math.random() * 1 + 1.5) + 's';
|
| 165 |
-
document.body.appendChild(emoji);
|
| 166 |
-
|
| 167 |
-
setTimeout(() => emoji.remove(), 2500);
|
| 168 |
-
}, i * 150);
|
| 169 |
-
}
|
| 170 |
-
|
| 171 |
-
// Create confetti
|
| 172 |
-
for (let i = 0; i < 50; i++) {
|
| 173 |
-
setTimeout(() => {
|
| 174 |
-
const confetti = document.createElement('div');
|
| 175 |
-
confetti.className = 'celebration-confetti';
|
| 176 |
-
confetti.style.background = colors[Math.floor(Math.random() * colors.length)];
|
| 177 |
-
confetti.style.left = Math.random() * 100 + 'vw';
|
| 178 |
-
confetti.style.animationDuration = (Math.random() * 1 + 1.5) + 's';
|
| 179 |
-
document.body.appendChild(confetti);
|
| 180 |
-
|
| 181 |
-
setTimeout(() => confetti.remove(), 2500);
|
| 182 |
-
}, i * 50);
|
| 183 |
-
}
|
| 184 |
-
}
|
| 185 |
-
|
| 186 |
-
// Auto progression after completion
|
| 187 |
function startAutoProgression(seconds) {
|
| 188 |
let timeLeft = seconds;
|
| 189 |
const countdownElement = document.getElementById('countdown-timer');
|
|
@@ -219,7 +155,7 @@ def initialize_session_state():
|
|
| 219 |
|
| 220 |
initialize_session_state()
|
| 221 |
|
| 222 |
-
#
|
| 223 |
st.markdown("""
|
| 224 |
<div class="main-container">
|
| 225 |
<div class="animal-characters">
|
|
@@ -273,7 +209,6 @@ with st.sidebar:
|
|
| 273 |
π« **Pro Tips:**
|
| 274 |
- Take your time with each problem
|
| 275 |
- Use the hints when you need help
|
| 276 |
-
- Celebrate every correct answer! π
|
| 277 |
- Practice makes perfect! π
|
| 278 |
""")
|
| 279 |
|
|
@@ -312,17 +247,17 @@ with col1:
|
|
| 312 |
with zipfile.ZipFile(zip_path, "r") as zip_ref:
|
| 313 |
zip_ref.extractall(temp_image_folder)
|
| 314 |
except Exception as e:
|
| 315 |
-
st.warning(f"β οΈ
|
| 316 |
|
| 317 |
if not os.path.exists(dataset_path):
|
| 318 |
-
st.error(f"β
|
| 319 |
st.stop()
|
| 320 |
|
| 321 |
try:
|
| 322 |
df = pd.read_excel(dataset_path)
|
| 323 |
df['category'] = df['category'].astype(str).str.strip()
|
| 324 |
except Exception as e:
|
| 325 |
-
st.error(f"β
|
| 326 |
st.stop()
|
| 327 |
|
| 328 |
# Category selection
|
|
@@ -346,14 +281,14 @@ with col1:
|
|
| 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 |
-
π―
|
| 354 |
</div>
|
| 355 |
-
<div class="progress-bar"
|
| 356 |
-
<div style="width: {progress}%;
|
| 357 |
</div>
|
| 358 |
</div>
|
| 359 |
""", unsafe_allow_html=True)
|
|
@@ -384,7 +319,7 @@ with col1:
|
|
| 384 |
except:
|
| 385 |
pass
|
| 386 |
if not image_found:
|
| 387 |
-
st.warning("πΌοΈ Image not
|
| 388 |
|
| 389 |
# Answer input
|
| 390 |
user_ans = st.text_input("βοΈ Your Answer:", key=f"ans_{st.session_state.question_index}")
|
|
@@ -396,15 +331,9 @@ with col1:
|
|
| 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
|
| 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!",
|
|
@@ -428,7 +357,7 @@ with col1:
|
|
| 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 |
|
|
@@ -462,11 +391,11 @@ with col1:
|
|
| 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! π
|
|
@@ -474,12 +403,10 @@ with col1:
|
|
| 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 |
-
πππππ
|
| 479 |
-
</div>
|
| 480 |
</div>
|
| 481 |
""", unsafe_allow_html=True)
|
| 482 |
|
|
|
|
| 483 |
st.balloons()
|
| 484 |
|
| 485 |
# Auto-progress logic
|
|
|
|
| 16 |
initial_sidebar_state="expanded"
|
| 17 |
)
|
| 18 |
|
| 19 |
+
# COMPLETELY CLEAN CSS - NO ANIMATIONS AT ALL
|
| 20 |
st.markdown("""
|
| 21 |
<style>
|
| 22 |
@import url('https://fonts.googleapis.com/css2?family=Comic+Neue:wght@700&display=swap');
|
|
|
|
| 58 |
border: none;
|
| 59 |
font-family: 'Comic Neue', cursive;
|
| 60 |
font-weight: bold;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 61 |
}
|
| 62 |
|
| 63 |
.stTextInput > div > input {
|
|
|
|
| 68 |
font-family: 'Comic Neue', cursive;
|
| 69 |
}
|
| 70 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 71 |
.progress-bar {
|
| 72 |
+
background: #f0f0f0;
|
| 73 |
border-radius: 10px;
|
| 74 |
height: 25px;
|
| 75 |
margin: 20px 0;
|
| 76 |
}
|
| 77 |
|
| 78 |
+
.progress-fill {
|
| 79 |
+
background: linear-gradient(45deg, #FF6B6B, #FFD93D);
|
| 80 |
+
border-radius: 10px;
|
| 81 |
+
height: 100%;
|
| 82 |
+
}
|
| 83 |
+
|
| 84 |
.animal-characters {
|
| 85 |
display: flex;
|
| 86 |
justify-content: space-around;
|
|
|
|
| 88 |
font-size: 40px;
|
| 89 |
}
|
| 90 |
|
|
|
|
| 91 |
.help-box {
|
| 92 |
background: rgba(255, 255, 255, 0.95);
|
| 93 |
padding: 20px;
|
|
|
|
| 97 |
font-family: 'Comic Neue', cursive;
|
| 98 |
}
|
| 99 |
|
|
|
|
| 100 |
.completion-celebration {
|
| 101 |
text-align: center;
|
| 102 |
padding: 40px;
|
|
|
|
| 106 |
margin: 20px 0;
|
| 107 |
}
|
| 108 |
|
|
|
|
| 109 |
.countdown {
|
| 110 |
font-size: 18px;
|
| 111 |
color: #FF6B6B;
|
|
|
|
| 116 |
</style>
|
| 117 |
""", unsafe_allow_html=True)
|
| 118 |
|
| 119 |
+
# NO JAVASCRIPT FOR ANIMATIONS - completely removed
|
| 120 |
st.markdown("""
|
| 121 |
<script>
|
| 122 |
+
// Auto progression after completion - ONLY FUNCTIONAL CODE
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 123 |
function startAutoProgression(seconds) {
|
| 124 |
let timeLeft = seconds;
|
| 125 |
const countdownElement = document.getElementById('countdown-timer');
|
|
|
|
| 155 |
|
| 156 |
initialize_session_state()
|
| 157 |
|
| 158 |
+
# COMPLETELY STABLE WELCOME - NO MOVEMENT
|
| 159 |
st.markdown("""
|
| 160 |
<div class="main-container">
|
| 161 |
<div class="animal-characters">
|
|
|
|
| 209 |
π« **Pro Tips:**
|
| 210 |
- Take your time with each problem
|
| 211 |
- Use the hints when you need help
|
|
|
|
| 212 |
- Practice makes perfect! π
|
| 213 |
""")
|
| 214 |
|
|
|
|
| 247 |
with zipfile.ZipFile(zip_path, "r") as zip_ref:
|
| 248 |
zip_ref.extractall(temp_image_folder)
|
| 249 |
except Exception as e:
|
| 250 |
+
st.warning(f"β οΈ Could not extract images: {e}")
|
| 251 |
|
| 252 |
if not os.path.exists(dataset_path):
|
| 253 |
+
st.error(f"β Dataset not found: {dataset_path}")
|
| 254 |
st.stop()
|
| 255 |
|
| 256 |
try:
|
| 257 |
df = pd.read_excel(dataset_path)
|
| 258 |
df['category'] = df['category'].astype(str).str.strip()
|
| 259 |
except Exception as e:
|
| 260 |
+
st.error(f"β Error loading dataset: {e}")
|
| 261 |
st.stop()
|
| 262 |
|
| 263 |
# Category selection
|
|
|
|
| 281 |
question = subset_df.iloc[st.session_state.question_index]
|
| 282 |
progress = int((st.session_state.question_index / len(subset_df)) * 100)
|
| 283 |
|
| 284 |
+
# Progress bar - NO ANIMATIONS
|
| 285 |
st.markdown(f"""
|
| 286 |
<div style="text-align: center; margin: 20px 0;">
|
| 287 |
<div style="font-family: 'Comic Neue', cursive; color: #FF6B6B; font-size: 18px;">
|
| 288 |
+
π― Progress: {st.session_state.question_index + 1} of {len(subset_df)}
|
| 289 |
</div>
|
| 290 |
+
<div class="progress-bar">
|
| 291 |
+
<div class="progress-fill" style="width: {progress}%;"></div>
|
| 292 |
</div>
|
| 293 |
</div>
|
| 294 |
""", unsafe_allow_html=True)
|
|
|
|
| 319 |
except:
|
| 320 |
pass
|
| 321 |
if not image_found:
|
| 322 |
+
st.warning("πΌοΈ Image not available")
|
| 323 |
|
| 324 |
# Answer input
|
| 325 |
user_ans = st.text_input("βοΈ Your Answer:", key=f"ans_{st.session_state.question_index}")
|
|
|
|
| 331 |
if st.button("π― Submit Answer", key=f"submit_{st.session_state.question_index}", use_container_width=True):
|
| 332 |
st.session_state.last_activity = time.time()
|
| 333 |
if str(user_ans).strip().lower() == str(question['answer']).strip().lower():
|
| 334 |
+
# SIMPLE CELEBRATION - just Streamlit balloons, no CSS animations
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 335 |
st.success("πβ¨ CORRECT! Amazing work! β¨π")
|
| 336 |
+
st.balloons() # This is the ONLY animation - controlled by Streamlit
|
| 337 |
|
| 338 |
success_messages = [
|
| 339 |
"π You're a math superstar!",
|
|
|
|
| 357 |
st.session_state.last_activity = time.time()
|
| 358 |
st.rerun()
|
| 359 |
else:
|
| 360 |
+
st.error("β Not quite right. Try again!")
|
| 361 |
st.session_state.show_answer = True
|
| 362 |
st.session_state.show_steps = False
|
| 363 |
|
|
|
|
| 391 |
elif subset_df.empty:
|
| 392 |
st.warning("β οΈ No questions available in this category. Try another one!")
|
| 393 |
else:
|
| 394 |
+
# COMPLETION MESSAGE - NO ANIMATIONS
|
| 395 |
st.markdown("""
|
| 396 |
<div class="completion-celebration">
|
| 397 |
<div style="font-size: 60px; margin-bottom: 20px;">
|
| 398 |
+
ππ
|
| 399 |
</div>
|
| 400 |
<h1 style="font-family: 'Comic Neue', cursive;">
|
| 401 |
CONGRATULATIONS! π
|
|
|
|
| 403 |
<p style="font-size: 24px;">
|
| 404 |
You've completed all challenges in this category!
|
| 405 |
</p>
|
|
|
|
|
|
|
|
|
|
| 406 |
</div>
|
| 407 |
""", unsafe_allow_html=True)
|
| 408 |
|
| 409 |
+
# Only show balloons for completion
|
| 410 |
st.balloons()
|
| 411 |
|
| 412 |
# Auto-progress logic
|