NSamson1 commited on
Commit
356a7d3
·
verified ·
1 Parent(s): f3ecedc

Update src/streamlit_app.py

Browse files
Files changed (1) hide show
  1. src/streamlit_app.py +69 -161
src/streamlit_app.py CHANGED
@@ -1,28 +1,43 @@
1
- import altair as alt
2
  import streamlit as st
3
  import pandas as pd
4
  import os
5
  import zipfile
6
  from PIL import Image
7
- import sympy as sp
8
  import time
9
  import tempfile
10
  import random
11
 
12
- # Page config with optimized settings
13
  st.set_page_config(
14
  page_title="Math Adventure Land",
15
  layout="wide",
16
  initial_sidebar_state="expanded"
17
  )
18
 
19
- # COMPLETELY CLEAN CSS - NO ANIMATIONS, NO MOVEMENTS, NO TRANSITIONS
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;
@@ -31,9 +46,8 @@ st.markdown("""
31
 
32
  .fun-title {
33
  font-size: 50px;
34
- color: #FF6B6B;
35
  text-align: center;
36
- font-family: 'Comic Neue', cursive;
37
  margin-bottom: 30px;
38
  }
39
 
@@ -41,9 +55,8 @@ st.markdown("""
41
  border: 6px dotted #FF6B6B;
42
  padding: 25px;
43
  border-radius: 25px;
44
- background-color: rgba(255, 255, 255, 0.9);
45
  font-size: 22px;
46
- font-family: 'Comic Neue', cursive;
47
  margin: 20px 0;
48
  }
49
 
@@ -54,8 +67,6 @@ st.markdown("""
54
  border-radius: 15px;
55
  padding: 12px 25px;
56
  border: none;
57
- font-family: 'Comic Neue', cursive;
58
- font-weight: bold;
59
  }
60
 
61
  .stTextInput > div > input {
@@ -63,7 +74,6 @@ st.markdown("""
63
  border-radius: 15px;
64
  border: 3px solid #4ECDC4;
65
  padding: 15px;
66
- font-family: 'Comic Neue', cursive;
67
  }
68
 
69
  .progress-bar {
@@ -87,12 +97,11 @@ st.markdown("""
87
  }
88
 
89
  .help-box {
90
- background: rgba(255, 255, 255, 0.95);
91
  padding: 20px;
92
  border-radius: 15px;
93
  border: 3px solid #FFD93D;
94
  margin-bottom: 20px;
95
- font-family: 'Comic Neue', cursive;
96
  }
97
 
98
  .completion-message {
@@ -111,20 +120,12 @@ st.markdown("""
111
  text-align: center;
112
  margin: 10px 0;
113
  }
114
-
115
- /* DISABLE ALL ANIMATIONS GLOBALLY */
116
- * {
117
- animation: none !important;
118
- transition: none !important;
119
- transform: none !important;
120
- }
121
  </style>
122
  """, unsafe_allow_html=True)
123
 
124
- # NO JAVASCRIPT AT ALL - completely removed
125
  st.markdown("""
126
  <script>
127
- // Simple auto progression - NO ANIMATIONS
128
  function startAutoProgression(seconds) {
129
  let timeLeft = seconds;
130
  const countdownElement = document.getElementById('countdown-timer');
@@ -144,40 +145,21 @@ function startAutoProgression(seconds) {
144
  </script>
145
  """, unsafe_allow_html=True)
146
 
147
- # Initialize session state with complete reset
148
  def initialize_session_state():
149
- required_keys = [
150
- 'app_initialized', 'temp_dir', 'last_activity', 'age_group',
151
- 'category', 'question_index', 'show_answer', 'show_steps',
152
- 'session_initialized', 'auto_progress'
153
- ]
154
-
155
- for key in required_keys:
156
- if key not in st.session_state:
157
- if key == 'app_initialized':
158
- st.session_state.app_initialized = True
159
- elif key == 'temp_dir':
160
- st.session_state.temp_dir = tempfile.mkdtemp()
161
- elif key == 'last_activity':
162
- st.session_state.last_activity = time.time()
163
- elif key == 'age_group':
164
- st.session_state.age_group = None
165
- elif key == 'category':
166
- st.session_state.category = None
167
- elif key == 'question_index':
168
- st.session_state.question_index = 0
169
- elif key == 'show_answer':
170
- st.session_state.show_answer = False
171
- elif key == 'show_steps':
172
- st.session_state.show_steps = False
173
- elif key == 'session_initialized':
174
- st.session_state.session_initialized = False
175
- elif key == 'auto_progress':
176
- st.session_state.auto_progress = True
177
 
178
  initialize_session_state()
179
 
180
- # COMPLETELY STABLE WELCOME - NO MOVEMENT AT ALL
181
  st.markdown("""
182
  <div class="main-container">
183
  <div class="animal-characters">
@@ -188,71 +170,53 @@ st.markdown("""
188
  <span>🐯</span>
189
  </div>
190
  <div class="fun-title">
191
- Welcome to Math Adventure Land!
192
  </div>
193
- <div style="text-align: center; font-size: 24px; color: #FF6B6B; font-family: 'Comic Neue', cursive;">
194
- Where Numbers Become Friends!
195
  </div>
196
  </div>
197
  """, unsafe_allow_html=True)
198
 
199
  # Age group setup
200
  age_groups = {
201
- "👶 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": "👶"},
202
- "🚀 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": "🚀"},
203
- "🌟 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": "🌟"}
204
  }
205
 
206
- # SIDEBAR - Clean and stable
207
  with st.sidebar:
208
- st.markdown("### Quick Help Guide")
209
 
210
  st.markdown("""
211
  <div class="help-box">
212
  <h4>How to Play:</h4>
213
  <p>1. Choose your age group<br>
214
  2. Pick a math category<br>
215
- 3. Solve the fun problems!<br>
216
- 4. Get instant feedback</p>
217
  </div>
218
  """, unsafe_allow_html=True)
219
 
220
- # Auto-progress toggle
221
- st.markdown("### Settings")
222
- auto_progress = st.toggle("Auto-Progress", value=st.session_state.auto_progress,
223
- help="Automatically move to next category when finished")
224
 
225
  if auto_progress != st.session_state.auto_progress:
226
  st.session_state.auto_progress = auto_progress
227
- st.rerun()
228
-
229
- st.markdown("### Achievement Tips")
230
- st.info("""
231
- Pro Tips:
232
- - Take your time with each problem
233
- - Use the hints when you need help
234
- - Practice makes perfect!
235
- """)
236
 
237
- # MAIN CONTENT AREA
238
  col1, col2 = st.columns([3, 1])
239
 
240
  with col1:
241
- # Update activity timestamp
242
- st.session_state.last_activity = time.time()
243
-
244
- # Age group selection
245
- selected_age_group = st.selectbox("Choose Your Adventure Level:", list(age_groups.keys()))
246
 
247
- # Force reset when age group changes
248
  if st.session_state.age_group != selected_age_group:
249
  st.session_state.age_group = selected_age_group
250
  st.session_state.category = None
251
  st.session_state.question_index = 0
252
  st.session_state.show_answer = False
253
  st.session_state.show_steps = False
254
- st.session_state.session_initialized = True
255
- st.rerun()
256
 
257
  # Load dataset
258
  group_info = age_groups[selected_age_group]
@@ -260,7 +224,7 @@ with col1:
260
  zip_path = group_info["zip_file"]
261
  image_folder = group_info["image_folder"]
262
 
263
- # Create image folder in temp directory
264
  temp_image_folder = os.path.join(st.session_state.temp_dir, image_folder)
265
  os.makedirs(temp_image_folder, exist_ok=True)
266
 
@@ -270,7 +234,7 @@ with col1:
270
  with zipfile.ZipFile(zip_path, "r") as zip_ref:
271
  zip_ref.extractall(temp_image_folder)
272
  except Exception as e:
273
- st.warning(f"Could not extract images: {e}")
274
 
275
  if not os.path.exists(dataset_path):
276
  st.error(f"Dataset not found: {dataset_path}")
@@ -283,10 +247,8 @@ with col1:
283
  st.error(f"Error loading dataset: {e}")
284
  st.stop()
285
 
286
- # Category selection
287
  categories = sorted(df['category'].dropna().unique())
288
- category_emojis = {"Addition": "+", "Subtraction": "-", "Multiplication": "×", "Division": "÷", "Geometry": "📐", "Algebra": "📊"}
289
- selected_category = st.selectbox("Choose Your Math Quest:", options=categories)
290
 
291
  # Update session if category changes
292
  if st.session_state.category != selected_category:
@@ -294,20 +256,18 @@ with col1:
294
  st.session_state.question_index = 0
295
  st.session_state.show_answer = False
296
  st.session_state.show_steps = False
297
- st.rerun()
298
 
299
- # Filter questions by selected category only
300
  subset_df = df[df['category'] == selected_category].reset_index(drop=True)
301
 
302
- # MATH QUESTIONS SECTION
303
  if not subset_df.empty and st.session_state.question_index < len(subset_df):
304
  question = subset_df.iloc[st.session_state.question_index]
305
  progress = int((st.session_state.question_index / len(subset_df)) * 100)
306
 
307
- # Progress bar - NO ANIMATIONS
308
  st.markdown(f"""
309
  <div style="text-align: center; margin: 20px 0;">
310
- <div style="font-family: 'Comic Neue', cursive; color: #FF6B6B; font-size: 18px;">
311
  Progress: {st.session_state.question_index + 1} of {len(subset_df)}
312
  </div>
313
  <div class="progress-bar">
@@ -316,19 +276,18 @@ with col1:
316
  </div>
317
  """, unsafe_allow_html=True)
318
 
319
- # Display question - NO ANIMATIONS
320
- category_emoji = category_emojis.get(selected_category, "?")
321
  st.markdown(f"""
322
  <div class="question-box">
323
  <div style="text-align: center; font-size: 30px; margin-bottom: 15px;">
324
  Challenge {st.session_state.question_index + 1}
325
  </div>
326
- <b>Math Quest:</b><br><br>
327
  {question['problem']}
328
  </div>
329
  """, unsafe_allow_html=True)
330
 
331
- # Display image with error handling
332
  if pd.notna(question.get('image')):
333
  image_name = str(question['image']).strip()
334
  image_found = False
@@ -341,8 +300,6 @@ with col1:
341
  break
342
  except:
343
  pass
344
- if not image_found:
345
- st.warning("Image not available")
346
 
347
  # Answer input
348
  user_ans = st.text_input("Your Answer:", key=f"ans_{st.session_state.question_index}")
@@ -352,125 +309,76 @@ with col1:
352
 
353
  with col_btn1:
354
  if st.button("Submit Answer", key=f"submit_{st.session_state.question_index}", use_container_width=True):
355
- st.session_state.last_activity = time.time()
356
  if str(user_ans).strip().lower() == str(question['answer']).strip().lower():
357
- # SIMPLE SUCCESS MESSAGE - NO ANIMATIONS
358
  st.success("CORRECT! Great job!")
359
-
360
- success_messages = [
361
- "You're a math superstar!",
362
- "Excellent work!",
363
- "Brilliant answer!",
364
- "Perfect!",
365
- "Outstanding!"
366
- ]
367
-
368
- st.markdown(f"""
369
- <div style="text-align: center; font-size: 24px; color: #FF6B6B; font-family: 'Comic Neue', cursive; padding: 20px;">
370
- {random.choice(success_messages)}
371
- </div>
372
- """, unsafe_allow_html=True)
373
-
374
- # Wait 2 seconds then continue
375
- time.sleep(2)
376
  st.session_state.question_index += 1
377
  st.session_state.show_answer = False
378
  st.session_state.show_steps = False
379
- st.session_state.last_activity = time.time()
380
  st.rerun()
381
  else:
382
- st.error("Not quite right. Try again!")
383
  st.session_state.show_answer = True
384
- st.session_state.show_steps = False
385
 
386
  with col_btn2:
387
  if st.button("Show Hint", key=f"hint_{st.session_state.question_index}", use_container_width=True):
388
- st.session_state.last_activity = time.time()
389
  st.session_state.show_answer = True
390
- st.info("Need some help? Here's the answer below!")
391
 
392
  with col_btn3:
393
  if st.button("Skip", key=f"skip_{st.session_state.question_index}", use_container_width=True):
394
- st.session_state.last_activity = time.time()
395
  st.session_state.question_index += 1
396
  st.session_state.show_answer = False
397
  st.session_state.show_steps = False
398
- st.info("Moving to next challenge...")
399
- time.sleep(1)
400
  st.rerun()
401
 
402
  # Show answer
403
  if st.session_state.show_answer:
404
- st.info(f"Correct Answer: {question['answer']}")
405
-
406
- if selected_age_group in ["🚀 Math Adventurers (7-9)", "🌟 Math Wizards (13-15)"]:
407
- if st.button("Show Steps", key=f"steps_{st.session_state.question_index}"):
408
- st.session_state.last_activity = time.time()
409
- st.session_state.show_steps = True
410
- if st.session_state.show_steps and pd.notna(question.get("steps", None)):
411
- st.success(f"Step-by-Step Solution:\n{question['steps']}")
412
 
413
  elif subset_df.empty:
414
- st.warning("No questions available in this category. Try another one!")
415
  else:
416
- # COMPLETION MESSAGE - NO ANIMATIONS
417
  st.markdown("""
418
  <div class="completion-message">
419
- <h1 style="font-family: 'Comic Neue', cursive;">
420
- CONGRATULATIONS!
421
- </h1>
422
- <p style="font-size: 24px;">
423
- You've completed all challenges in this category!
424
- </p>
425
  </div>
426
  """, unsafe_allow_html=True)
427
 
428
- # Auto-progress logic
429
  if st.session_state.auto_progress:
430
  st.markdown("""
431
  <div class="countdown" id="countdown-timer">
432
- Next adventure starting in: 5 seconds
433
  </div>
434
  <script>
435
  startAutoProgression(5);
436
  </script>
437
  """, unsafe_allow_html=True)
438
-
439
  time.sleep(5)
440
  st.session_state.question_index = 0
441
  st.session_state.show_answer = False
442
  st.session_state.show_steps = False
443
-
444
- # Move to next category
445
  current_idx = categories.index(selected_category)
446
  if current_idx < len(categories) - 1:
447
  st.session_state.category = categories[current_idx + 1]
448
  else:
449
  st.session_state.category = categories[0]
450
-
451
  st.rerun()
452
  else:
453
- if st.button("Start New Adventure", use_container_width=True):
454
- st.session_state.last_activity = time.time()
455
  st.session_state.question_index = 0
456
  st.session_state.show_answer = False
457
  st.session_state.show_steps = False
458
  st.rerun()
459
 
460
  with col2:
461
- st.markdown("### Fun Zone")
462
- st.markdown("""
463
- <div style="text-align: center; font-size: 40px; margin: 20px 0;">
464
- 🎪<br>✨<br>🌟
465
- </div>
466
- """, unsafe_allow_html=True)
467
-
468
  st.markdown("### Progress")
469
  if not subset_df.empty:
470
  completed = min(st.session_state.question_index, len(subset_df))
471
  st.metric("Completed", f"{completed}/{len(subset_df)}")
472
 
473
- # Cleanup function
474
  def cleanup():
475
  import shutil
476
  if 'temp_dir' in st.session_state and os.path.exists(st.session_state.temp_dir):
 
 
1
  import streamlit as st
2
  import pandas as pd
3
  import os
4
  import zipfile
5
  from PIL import Image
 
6
  import time
7
  import tempfile
8
  import random
9
 
10
+ # Disable all Streamlit animations and behaviors that might cause movement
11
  st.set_page_config(
12
  page_title="Math Adventure Land",
13
  layout="wide",
14
  initial_sidebar_state="expanded"
15
  )
16
 
17
+ # MINIMAL CSS - NO GRADIENTS, NO ANIMATIONS, NO EFFECTS
18
  st.markdown("""
19
  <style>
20
+ /* DISABLE ALL ANIMATIONS AND TRANSITIONS GLOBALLY */
21
+ * {
22
+ animation: none !important;
23
+ transition: none !important;
24
+ transform: none !important;
25
+ -webkit-animation: none !important;
26
+ -webkit-transition: none !important;
27
+ -webkit-transform: none !important;
28
+ -moz-animation: none !important;
29
+ -moz-transition: none !important;
30
+ -moz-transform: none !important;
31
+ }
32
 
33
+ /* DISABLE STREAMLIT BUILT-IN ANIMATIONS */
34
+ .stApp {
35
+ animation: none !important;
36
+ }
37
+
38
+ /* SIMPLE STATIC COLORS */
39
  .main-container {
40
+ background: #FF6B6B;
41
  padding: 20px;
42
  border-radius: 25px;
43
  border: 8px dashed #FFD93D;
 
46
 
47
  .fun-title {
48
  font-size: 50px;
49
+ color: white;
50
  text-align: center;
 
51
  margin-bottom: 30px;
52
  }
53
 
 
55
  border: 6px dotted #FF6B6B;
56
  padding: 25px;
57
  border-radius: 25px;
58
+ background-color: white;
59
  font-size: 22px;
 
60
  margin: 20px 0;
61
  }
62
 
 
67
  border-radius: 15px;
68
  padding: 12px 25px;
69
  border: none;
 
 
70
  }
71
 
72
  .stTextInput > div > input {
 
74
  border-radius: 15px;
75
  border: 3px solid #4ECDC4;
76
  padding: 15px;
 
77
  }
78
 
79
  .progress-bar {
 
97
  }
98
 
99
  .help-box {
100
+ background: white;
101
  padding: 20px;
102
  border-radius: 15px;
103
  border: 3px solid #FFD93D;
104
  margin-bottom: 20px;
 
105
  }
106
 
107
  .completion-message {
 
120
  text-align: center;
121
  margin: 10px 0;
122
  }
 
 
 
 
 
 
 
123
  </style>
124
  """, unsafe_allow_html=True)
125
 
126
+ # NO JAVASCRIPT - completely removed
127
  st.markdown("""
128
  <script>
 
129
  function startAutoProgression(seconds) {
130
  let timeLeft = seconds;
131
  const countdownElement = document.getElementById('countdown-timer');
 
145
  </script>
146
  """, unsafe_allow_html=True)
147
 
148
+ # Initialize session state
149
  def initialize_session_state():
150
+ if 'app_initialized' not in st.session_state:
151
+ st.session_state.app_initialized = True
152
+ st.session_state.temp_dir = tempfile.mkdtemp()
153
+ st.session_state.age_group = None
154
+ st.session_state.category = None
155
+ st.session_state.question_index = 0
156
+ st.session_state.show_answer = False
157
+ st.session_state.show_steps = False
158
+ st.session_state.auto_progress = True
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
159
 
160
  initialize_session_state()
161
 
162
+ # SIMPLE STATIC WELCOME
163
  st.markdown("""
164
  <div class="main-container">
165
  <div class="animal-characters">
 
170
  <span>🐯</span>
171
  </div>
172
  <div class="fun-title">
173
+ Math Adventure Land
174
  </div>
175
+ <div style="text-align: center; font-size: 24px; color: white;">
176
+ Learn Math with Fun!
177
  </div>
178
  </div>
179
  """, unsafe_allow_html=True)
180
 
181
  # Age group setup
182
  age_groups = {
183
+ "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"},
184
+ "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"},
185
+ "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"}
186
  }
187
 
188
+ # SIDEBAR
189
  with st.sidebar:
190
+ st.markdown("### Quick Help")
191
 
192
  st.markdown("""
193
  <div class="help-box">
194
  <h4>How to Play:</h4>
195
  <p>1. Choose your age group<br>
196
  2. Pick a math category<br>
197
+ 3. Solve the problems<br>
198
+ 4. Get feedback</p>
199
  </div>
200
  """, unsafe_allow_html=True)
201
 
202
+ auto_progress = st.toggle("Auto-Progress", value=st.session_state.auto_progress)
 
 
 
203
 
204
  if auto_progress != st.session_state.auto_progress:
205
  st.session_state.auto_progress = auto_progress
 
 
 
 
 
 
 
 
 
206
 
207
+ # MAIN CONTENT
208
  col1, col2 = st.columns([3, 1])
209
 
210
  with col1:
211
+ selected_age_group = st.selectbox("Choose Age Group:", list(age_groups.keys()))
 
 
 
 
212
 
213
+ # Reset on age group change
214
  if st.session_state.age_group != selected_age_group:
215
  st.session_state.age_group = selected_age_group
216
  st.session_state.category = None
217
  st.session_state.question_index = 0
218
  st.session_state.show_answer = False
219
  st.session_state.show_steps = False
 
 
220
 
221
  # Load dataset
222
  group_info = age_groups[selected_age_group]
 
224
  zip_path = group_info["zip_file"]
225
  image_folder = group_info["image_folder"]
226
 
227
+ # Create image folder
228
  temp_image_folder = os.path.join(st.session_state.temp_dir, image_folder)
229
  os.makedirs(temp_image_folder, exist_ok=True)
230
 
 
234
  with zipfile.ZipFile(zip_path, "r") as zip_ref:
235
  zip_ref.extractall(temp_image_folder)
236
  except Exception as e:
237
+ pass # Silent fail
238
 
239
  if not os.path.exists(dataset_path):
240
  st.error(f"Dataset not found: {dataset_path}")
 
247
  st.error(f"Error loading dataset: {e}")
248
  st.stop()
249
 
 
250
  categories = sorted(df['category'].dropna().unique())
251
+ selected_category = st.selectbox("Choose Math Category:", options=categories)
 
252
 
253
  # Update session if category changes
254
  if st.session_state.category != selected_category:
 
256
  st.session_state.question_index = 0
257
  st.session_state.show_answer = False
258
  st.session_state.show_steps = False
 
259
 
260
+ # Filter questions
261
  subset_df = df[df['category'] == selected_category].reset_index(drop=True)
262
 
 
263
  if not subset_df.empty and st.session_state.question_index < len(subset_df):
264
  question = subset_df.iloc[st.session_state.question_index]
265
  progress = int((st.session_state.question_index / len(subset_df)) * 100)
266
 
267
+ # Progress bar
268
  st.markdown(f"""
269
  <div style="text-align: center; margin: 20px 0;">
270
+ <div style="color: #FF6B6B; font-size: 18px;">
271
  Progress: {st.session_state.question_index + 1} of {len(subset_df)}
272
  </div>
273
  <div class="progress-bar">
 
276
  </div>
277
  """, unsafe_allow_html=True)
278
 
279
+ # Display question
 
280
  st.markdown(f"""
281
  <div class="question-box">
282
  <div style="text-align: center; font-size: 30px; margin-bottom: 15px;">
283
  Challenge {st.session_state.question_index + 1}
284
  </div>
285
+ <b>Question:</b><br><br>
286
  {question['problem']}
287
  </div>
288
  """, unsafe_allow_html=True)
289
 
290
+ # Display image
291
  if pd.notna(question.get('image')):
292
  image_name = str(question['image']).strip()
293
  image_found = False
 
300
  break
301
  except:
302
  pass
 
 
303
 
304
  # Answer input
305
  user_ans = st.text_input("Your Answer:", key=f"ans_{st.session_state.question_index}")
 
309
 
310
  with col_btn1:
311
  if st.button("Submit Answer", key=f"submit_{st.session_state.question_index}", use_container_width=True):
 
312
  if str(user_ans).strip().lower() == str(question['answer']).strip().lower():
 
313
  st.success("CORRECT! Great job!")
314
+ time.sleep(1)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
315
  st.session_state.question_index += 1
316
  st.session_state.show_answer = False
317
  st.session_state.show_steps = False
 
318
  st.rerun()
319
  else:
320
+ st.error("Try again!")
321
  st.session_state.show_answer = True
 
322
 
323
  with col_btn2:
324
  if st.button("Show Hint", key=f"hint_{st.session_state.question_index}", use_container_width=True):
 
325
  st.session_state.show_answer = True
 
326
 
327
  with col_btn3:
328
  if st.button("Skip", key=f"skip_{st.session_state.question_index}", use_container_width=True):
 
329
  st.session_state.question_index += 1
330
  st.session_state.show_answer = False
331
  st.session_state.show_steps = False
 
 
332
  st.rerun()
333
 
334
  # Show answer
335
  if st.session_state.show_answer:
336
+ st.info(f"Answer: {question['answer']}")
 
 
 
 
 
 
 
337
 
338
  elif subset_df.empty:
339
+ st.warning("No questions in this category.")
340
  else:
341
+ # Completion message
342
  st.markdown("""
343
  <div class="completion-message">
344
+ <h1>CONGRATULATIONS!</h1>
345
+ <p>You completed all challenges!</p>
 
 
 
 
346
  </div>
347
  """, unsafe_allow_html=True)
348
 
 
349
  if st.session_state.auto_progress:
350
  st.markdown("""
351
  <div class="countdown" id="countdown-timer">
352
+ Next category in: 5 seconds
353
  </div>
354
  <script>
355
  startAutoProgression(5);
356
  </script>
357
  """, unsafe_allow_html=True)
 
358
  time.sleep(5)
359
  st.session_state.question_index = 0
360
  st.session_state.show_answer = False
361
  st.session_state.show_steps = False
 
 
362
  current_idx = categories.index(selected_category)
363
  if current_idx < len(categories) - 1:
364
  st.session_state.category = categories[current_idx + 1]
365
  else:
366
  st.session_state.category = categories[0]
 
367
  st.rerun()
368
  else:
369
+ if st.button("Start New Adventure"):
 
370
  st.session_state.question_index = 0
371
  st.session_state.show_answer = False
372
  st.session_state.show_steps = False
373
  st.rerun()
374
 
375
  with col2:
 
 
 
 
 
 
 
376
  st.markdown("### Progress")
377
  if not subset_df.empty:
378
  completed = min(st.session_state.question_index, len(subset_df))
379
  st.metric("Completed", f"{completed}/{len(subset_df)}")
380
 
381
+ # Cleanup
382
  def cleanup():
383
  import shutil
384
  if 'temp_dir' in st.session_state and os.path.exists(st.session_state.temp_dir):