Spaces:
Running
Running
Update src/streamlit_app.py
Browse files- src/streamlit_app.py +146 -28
src/streamlit_app.py
CHANGED
|
@@ -11,7 +11,7 @@ import tempfile
|
|
| 11 |
# Page config
|
| 12 |
st.set_page_config(page_title="π Smart Math Teacher", layout="centered")
|
| 13 |
|
| 14 |
-
# Custom CSS with beautiful colors
|
| 15 |
st.markdown("""
|
| 16 |
<style>
|
| 17 |
.fun-title {
|
|
@@ -20,6 +20,7 @@ st.markdown("""
|
|
| 20 |
text-align: center;
|
| 21 |
font-family: 'Comic Sans MS', cursive;
|
| 22 |
text-shadow: 2px 2px 4px rgba(0,0,0,0.1);
|
|
|
|
| 23 |
}
|
| 24 |
.question-box {
|
| 25 |
border: 4px solid #4ECDC4;
|
|
@@ -28,6 +29,7 @@ st.markdown("""
|
|
| 28 |
background: linear-gradient(135deg, #FFF9C4, #E3F2FD);
|
| 29 |
font-size: 20px;
|
| 30 |
box-shadow: 0 4px 8px rgba(0,0,0,0.1);
|
|
|
|
| 31 |
}
|
| 32 |
.stButton > button {
|
| 33 |
font-size: 18px;
|
|
@@ -37,9 +39,7 @@ st.markdown("""
|
|
| 37 |
padding: 10px;
|
| 38 |
border: none;
|
| 39 |
font-weight: bold;
|
| 40 |
-
|
| 41 |
-
.stButton > button:hover {
|
| 42 |
-
background: linear-gradient(45deg, #FF8E53, #FF6B6B);
|
| 43 |
}
|
| 44 |
.stTextInput > div > input {
|
| 45 |
font-size: 18px;
|
|
@@ -86,18 +86,65 @@ st.markdown("""
|
|
| 86 |
border-radius: 10px;
|
| 87 |
}
|
| 88 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 89 |
/* DISABLE ALL ANIMATIONS */
|
| 90 |
* {
|
| 91 |
animation: none !important;
|
| 92 |
transition: none !important;
|
| 93 |
transform: none !important;
|
| 94 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 95 |
</style>
|
| 96 |
""", unsafe_allow_html=True)
|
| 97 |
|
| 98 |
# Welcome title
|
| 99 |
st.markdown("<div class='fun-title'>π§ β¨ Welcome to the Smart Math Teacher! β¨π§ </div>", unsafe_allow_html=True)
|
| 100 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 101 |
# Initialize session state for temp directory
|
| 102 |
if 'temp_dir' not in st.session_state:
|
| 103 |
st.session_state.temp_dir = tempfile.mkdtemp()
|
|
@@ -109,7 +156,23 @@ age_groups = {
|
|
| 109 |
"13-15 Age Group": {"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"},
|
| 110 |
}
|
| 111 |
|
| 112 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 113 |
|
| 114 |
# Initialize session
|
| 115 |
if "session_initialized" not in st.session_state or st.session_state.age_group != selected_age_group:
|
|
@@ -150,8 +213,14 @@ except Exception as e:
|
|
| 150 |
st.stop()
|
| 151 |
|
| 152 |
# Category selection
|
|
|
|
|
|
|
| 153 |
categories = sorted(df['category'].dropna().unique())
|
| 154 |
-
selected_category = st.selectbox(
|
|
|
|
|
|
|
|
|
|
|
|
|
| 155 |
|
| 156 |
# Update session if category changes
|
| 157 |
if st.session_state.category != selected_category:
|
|
@@ -164,10 +233,19 @@ if st.session_state.category != selected_category:
|
|
| 164 |
# Filter questions by selected category only
|
| 165 |
subset_df = df[df['category'] == selected_category].reset_index(drop=True)
|
| 166 |
|
|
|
|
|
|
|
|
|
|
| 167 |
if not subset_df.empty and st.session_state.question_index < len(subset_df):
|
| 168 |
question = subset_df.iloc[st.session_state.question_index]
|
| 169 |
progress = int((st.session_state.question_index / len(subset_df)) * 100)
|
| 170 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 171 |
|
| 172 |
st.markdown(f"<div class='question-box'>π <b>Question {st.session_state.question_index + 1}:</b><br><br>{question['problem']}</div>", unsafe_allow_html=True)
|
| 173 |
|
|
@@ -185,41 +263,81 @@ if not subset_df.empty and st.session_state.question_index < len(subset_df):
|
|
| 185 |
except:
|
| 186 |
pass
|
| 187 |
if not image_found:
|
| 188 |
-
st.warning("β Image not found.")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 189 |
|
| 190 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 191 |
|
| 192 |
-
|
| 193 |
-
if
|
| 194 |
-
st.success("π Correct! Well done!")
|
| 195 |
-
st.balloons()
|
| 196 |
-
time.sleep(2)
|
| 197 |
st.session_state.question_index += 1
|
| 198 |
st.session_state.show_answer = False
|
| 199 |
st.session_state.show_steps = False
|
| 200 |
st.rerun()
|
| 201 |
-
else:
|
| 202 |
-
st.error("β Try again or view the correct answer below.")
|
| 203 |
-
st.session_state.show_answer = True
|
| 204 |
-
st.session_state.show_steps = False
|
| 205 |
|
|
|
|
| 206 |
if st.session_state.show_answer:
|
| 207 |
-
st.
|
|
|
|
|
|
|
|
|
|
| 208 |
if selected_age_group in ["7-9 Age Group", "13-15 Age Group"]:
|
| 209 |
-
if st.button("π Show
|
| 210 |
st.session_state.show_steps = True
|
|
|
|
| 211 |
if st.session_state.show_steps and pd.notna(question.get("steps", None)):
|
| 212 |
-
st.success(f"### πͺ
|
| 213 |
|
| 214 |
-
if st.button("βοΈ Skip"):
|
| 215 |
-
st.session_state.question_index += 1
|
| 216 |
-
st.session_state.show_answer = False
|
| 217 |
-
st.session_state.show_steps = False
|
| 218 |
-
st.rerun()
|
| 219 |
elif subset_df.empty:
|
| 220 |
-
st.warning("β οΈ No questions available in this category.
|
| 221 |
else:
|
| 222 |
-
st.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 223 |
|
| 224 |
# Cleanup function
|
| 225 |
def cleanup():
|
|
|
|
| 11 |
# Page config
|
| 12 |
st.set_page_config(page_title="π Smart Math Teacher", layout="centered")
|
| 13 |
|
| 14 |
+
# Custom CSS with beautiful colors and stable layout
|
| 15 |
st.markdown("""
|
| 16 |
<style>
|
| 17 |
.fun-title {
|
|
|
|
| 20 |
text-align: center;
|
| 21 |
font-family: 'Comic Sans MS', cursive;
|
| 22 |
text-shadow: 2px 2px 4px rgba(0,0,0,0.1);
|
| 23 |
+
margin-bottom: 20px;
|
| 24 |
}
|
| 25 |
.question-box {
|
| 26 |
border: 4px solid #4ECDC4;
|
|
|
|
| 29 |
background: linear-gradient(135deg, #FFF9C4, #E3F2FD);
|
| 30 |
font-size: 20px;
|
| 31 |
box-shadow: 0 4px 8px rgba(0,0,0,0.1);
|
| 32 |
+
margin: 15px 0;
|
| 33 |
}
|
| 34 |
.stButton > button {
|
| 35 |
font-size: 18px;
|
|
|
|
| 39 |
padding: 10px;
|
| 40 |
border: none;
|
| 41 |
font-weight: bold;
|
| 42 |
+
margin: 5px;
|
|
|
|
|
|
|
| 43 |
}
|
| 44 |
.stTextInput > div > input {
|
| 45 |
font-size: 18px;
|
|
|
|
| 86 |
border-radius: 10px;
|
| 87 |
}
|
| 88 |
|
| 89 |
+
/* Guide box */
|
| 90 |
+
.guide-box {
|
| 91 |
+
background: linear-gradient(135deg, #A5D6A7, #C8E6C9);
|
| 92 |
+
padding: 15px;
|
| 93 |
+
border-radius: 10px;
|
| 94 |
+
border: 2px solid #4CAF50;
|
| 95 |
+
margin: 10px 0;
|
| 96 |
+
}
|
| 97 |
+
|
| 98 |
/* DISABLE ALL ANIMATIONS */
|
| 99 |
* {
|
| 100 |
animation: none !important;
|
| 101 |
transition: none !important;
|
| 102 |
transform: none !important;
|
| 103 |
}
|
| 104 |
+
|
| 105 |
+
/* Keep content in view */
|
| 106 |
+
.main-content {
|
| 107 |
+
min-height: 100vh;
|
| 108 |
+
}
|
| 109 |
</style>
|
| 110 |
""", unsafe_allow_html=True)
|
| 111 |
|
| 112 |
# Welcome title
|
| 113 |
st.markdown("<div class='fun-title'>π§ β¨ Welcome to the Smart Math Teacher! β¨π§ </div>", unsafe_allow_html=True)
|
| 114 |
|
| 115 |
+
# USER GUIDE SECTION
|
| 116 |
+
with st.expander("π **How to Use This App - Click to Expand Guide**", expanded=True):
|
| 117 |
+
st.markdown("""
|
| 118 |
+
<div class="guide-box">
|
| 119 |
+
<h3>π― Quick Start Guide:</h3>
|
| 120 |
+
|
| 121 |
+
**Step 1: Choose Your Level** π
|
| 122 |
+
- Select your age group from the dropdown
|
| 123 |
+
- 4-6: Basic counting and simple math
|
| 124 |
+
- 7-9: Addition, subtraction, multiplication
|
| 125 |
+
- 13-15: Advanced math and algebra
|
| 126 |
+
|
| 127 |
+
**Step 2: Pick a Category** π
|
| 128 |
+
- Choose what type of math you want to practice
|
| 129 |
+
- Each category has different types of questions
|
| 130 |
+
|
| 131 |
+
**Step 3: Solve Problems** βοΈ
|
| 132 |
+
- Read each question carefully
|
| 133 |
+
- Type your answer in the box
|
| 134 |
+
- Click "Submit Answer" to check
|
| 135 |
+
|
| 136 |
+
**Step 4: Get Help When Needed** π‘
|
| 137 |
+
- Use "Show Hint" if you're stuck
|
| 138 |
+
- "Show Steps" explains how to solve it
|
| 139 |
+
- "Skip" moves to the next question
|
| 140 |
+
|
| 141 |
+
**Tips for Success:** π
|
| 142 |
+
- Take your time with each problem
|
| 143 |
+
- Don't worry about mistakes - they help you learn!
|
| 144 |
+
- Practice regularly to improve your skills
|
| 145 |
+
</div>
|
| 146 |
+
""", unsafe_allow_html=True)
|
| 147 |
+
|
| 148 |
# Initialize session state for temp directory
|
| 149 |
if 'temp_dir' not in st.session_state:
|
| 150 |
st.session_state.temp_dir = tempfile.mkdtemp()
|
|
|
|
| 156 |
"13-15 Age Group": {"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"},
|
| 157 |
}
|
| 158 |
|
| 159 |
+
# Age group selection with better layout
|
| 160 |
+
st.markdown("---")
|
| 161 |
+
st.markdown("### π§ Select Your Learning Level")
|
| 162 |
+
selected_age_group = st.selectbox(
|
| 163 |
+
"Choose your age group:",
|
| 164 |
+
list(age_groups.keys()),
|
| 165 |
+
key="age_group_selector"
|
| 166 |
+
)
|
| 167 |
+
|
| 168 |
+
# Age group descriptions
|
| 169 |
+
age_descriptions = {
|
| 170 |
+
"4-6 Age Group": "π¨ **Fun with Numbers**: Counting, shapes, and basic addition",
|
| 171 |
+
"7-9 Age Group": "π **Math Adventures**: Addition, subtraction, multiplication",
|
| 172 |
+
"13-15 Age Group": "π **Math Master**: Algebra, geometry, and problem solving"
|
| 173 |
+
}
|
| 174 |
+
|
| 175 |
+
st.info(age_descriptions[selected_age_group])
|
| 176 |
|
| 177 |
# Initialize session
|
| 178 |
if "session_initialized" not in st.session_state or st.session_state.age_group != selected_age_group:
|
|
|
|
| 213 |
st.stop()
|
| 214 |
|
| 215 |
# Category selection
|
| 216 |
+
st.markdown("---")
|
| 217 |
+
st.markdown("### π Choose Your Math Category")
|
| 218 |
categories = sorted(df['category'].dropna().unique())
|
| 219 |
+
selected_category = st.selectbox(
|
| 220 |
+
"Select a category to practice:",
|
| 221 |
+
options=categories,
|
| 222 |
+
key="category_selector"
|
| 223 |
+
)
|
| 224 |
|
| 225 |
# Update session if category changes
|
| 226 |
if st.session_state.category != selected_category:
|
|
|
|
| 233 |
# Filter questions by selected category only
|
| 234 |
subset_df = df[df['category'] == selected_category].reset_index(drop=True)
|
| 235 |
|
| 236 |
+
# MAIN CONTENT AREA
|
| 237 |
+
st.markdown("---")
|
| 238 |
+
|
| 239 |
if not subset_df.empty and st.session_state.question_index < len(subset_df):
|
| 240 |
question = subset_df.iloc[st.session_state.question_index]
|
| 241 |
progress = int((st.session_state.question_index / len(subset_df)) * 100)
|
| 242 |
+
|
| 243 |
+
# Progress information
|
| 244 |
+
col_progress1, col_progress2 = st.columns([3, 1])
|
| 245 |
+
with col_progress1:
|
| 246 |
+
st.progress(progress)
|
| 247 |
+
with col_progress2:
|
| 248 |
+
st.write(f"**{st.session_state.question_index + 1} of {len(subset_df)}**")
|
| 249 |
|
| 250 |
st.markdown(f"<div class='question-box'>π <b>Question {st.session_state.question_index + 1}:</b><br><br>{question['problem']}</div>", unsafe_allow_html=True)
|
| 251 |
|
|
|
|
| 263 |
except:
|
| 264 |
pass
|
| 265 |
if not image_found:
|
| 266 |
+
st.warning("β Image not found for this question.")
|
| 267 |
+
|
| 268 |
+
# Answer section
|
| 269 |
+
st.markdown("### βοΈ Your Turn to Solve!")
|
| 270 |
+
user_ans = st.text_input("Type your answer below:", key=f"ans_{st.session_state.question_index}")
|
| 271 |
+
|
| 272 |
+
# Action buttons in columns
|
| 273 |
+
col1, col2, col3 = st.columns(3)
|
| 274 |
+
|
| 275 |
+
with col1:
|
| 276 |
+
if st.button("β
Submit Answer", use_container_width=True):
|
| 277 |
+
if str(user_ans).strip().lower() == str(question['answer']).strip().lower():
|
| 278 |
+
st.success("π Correct! Well done!")
|
| 279 |
+
st.balloons()
|
| 280 |
+
time.sleep(2)
|
| 281 |
+
st.session_state.question_index += 1
|
| 282 |
+
st.session_state.show_answer = False
|
| 283 |
+
st.session_state.show_steps = False
|
| 284 |
+
st.rerun()
|
| 285 |
+
else:
|
| 286 |
+
st.error("β Not quite right. Try again or use the hint below!")
|
| 287 |
+
st.session_state.show_answer = True
|
| 288 |
+
st.session_state.show_steps = False
|
| 289 |
|
| 290 |
+
with col2:
|
| 291 |
+
if st.button("π‘ Show Hint", use_container_width=True):
|
| 292 |
+
st.session_state.show_answer = True
|
| 293 |
+
st.session_state.show_steps = False
|
| 294 |
+
st.info("π‘ Need help? Check the answer below!")
|
| 295 |
|
| 296 |
+
with col3:
|
| 297 |
+
if st.button("βοΈ Skip Question", use_container_width=True):
|
|
|
|
|
|
|
|
|
|
| 298 |
st.session_state.question_index += 1
|
| 299 |
st.session_state.show_answer = False
|
| 300 |
st.session_state.show_steps = False
|
| 301 |
st.rerun()
|
|
|
|
|
|
|
|
|
|
|
|
|
| 302 |
|
| 303 |
+
# Help sections
|
| 304 |
if st.session_state.show_answer:
|
| 305 |
+
st.markdown("---")
|
| 306 |
+
st.markdown("### π‘ Need Help?")
|
| 307 |
+
st.info(f"**β
Correct Answer:** **{question['answer']}**")
|
| 308 |
+
|
| 309 |
if selected_age_group in ["7-9 Age Group", "13-15 Age Group"]:
|
| 310 |
+
if st.button("π Show Step-by-Step Solution"):
|
| 311 |
st.session_state.show_steps = True
|
| 312 |
+
|
| 313 |
if st.session_state.show_steps and pd.notna(question.get("steps", None)):
|
| 314 |
+
st.success(f"### πͺ How to Solve:\n{question['steps']}")
|
| 315 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 316 |
elif subset_df.empty:
|
| 317 |
+
st.warning("β οΈ No questions available in this category. Please try another category!")
|
| 318 |
else:
|
| 319 |
+
st.markdown("---")
|
| 320 |
+
st.success("""
|
| 321 |
+
# π Congratulations!
|
| 322 |
+
|
| 323 |
+
### You've completed all questions in this category!
|
| 324 |
+
|
| 325 |
+
π **Great job!** You're becoming a math superstar!
|
| 326 |
+
|
| 327 |
+
**What to do next:**
|
| 328 |
+
- Try another category in the same age group
|
| 329 |
+
- Move to a more challenging age group
|
| 330 |
+
- Practice regularly to keep improving!
|
| 331 |
+
""")
|
| 332 |
+
st.balloons()
|
| 333 |
+
|
| 334 |
+
# Footer with tips
|
| 335 |
+
st.markdown("---")
|
| 336 |
+
st.markdown("""
|
| 337 |
+
<div style='text-align: center; color: #666; font-size: 14px;'>
|
| 338 |
+
π‘ <b>Tip:</b> The page might scroll when changing groups - this is normal! Just scroll down to continue learning.
|
| 339 |
+
</div>
|
| 340 |
+
""", unsafe_allow_html=True)
|
| 341 |
|
| 342 |
# Cleanup function
|
| 343 |
def cleanup():
|