Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -224,6 +224,180 @@ with gr.Blocks() as demo:
|
|
| 224 |
submit.click(fn=save_profile,
|
| 225 |
inputs=[file, *quiz_components, blog_checkbox, blog_text, *category_inputs],
|
| 226 |
outputs=[output])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 227 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 228 |
if __name__ == '__main__':
|
| 229 |
demo.launch()
|
|
|
|
| 224 |
submit.click(fn=save_profile,
|
| 225 |
inputs=[file, *quiz_components, blog_checkbox, blog_text, *category_inputs],
|
| 226 |
outputs=[output])
|
| 227 |
+
# Assistant component functions
|
| 228 |
+
def load_student_profile():
|
| 229 |
+
try:
|
| 230 |
+
with open("student_profile.json", "r") as f:
|
| 231 |
+
return json.load(f)
|
| 232 |
+
except FileNotFoundError:
|
| 233 |
+
return None
|
| 234 |
+
|
| 235 |
+
def generate_study_tips(learning_style):
|
| 236 |
+
tips = {
|
| 237 |
+
"Visual": [
|
| 238 |
+
"Use color-coding in your notes",
|
| 239 |
+
"Create mind maps or diagrams",
|
| 240 |
+
"Watch educational videos",
|
| 241 |
+
"Use flashcards with images",
|
| 242 |
+
"Draw pictures to represent concepts"
|
| 243 |
+
],
|
| 244 |
+
"Auditory": [
|
| 245 |
+
"Record lectures and listen to them",
|
| 246 |
+
"Explain concepts out loud to yourself",
|
| 247 |
+
"Participate in study groups",
|
| 248 |
+
"Use mnemonic devices with rhymes",
|
| 249 |
+
"Listen to educational podcasts"
|
| 250 |
+
],
|
| 251 |
+
"Reading/writing": [
|
| 252 |
+
"Rewrite your notes in your own words",
|
| 253 |
+
"Create detailed outlines",
|
| 254 |
+
"Write summaries of what you learn",
|
| 255 |
+
"Read textbooks and articles",
|
| 256 |
+
"Keep a learning journal"
|
| 257 |
+
]
|
| 258 |
+
}
|
| 259 |
+
return tips.get(learning_style.split(", ")[0], []
|
| 260 |
+
|
| 261 |
+
def generate_subject_specific_advice(courses):
|
| 262 |
+
advice = {
|
| 263 |
+
"Math": [
|
| 264 |
+
"Practice problems daily",
|
| 265 |
+
"Focus on understanding concepts, not just memorization",
|
| 266 |
+
"Show all your work step-by-step",
|
| 267 |
+
"Relate math to real-world applications"
|
| 268 |
+
],
|
| 269 |
+
"Science": [
|
| 270 |
+
"Conduct simple experiments at home",
|
| 271 |
+
"Create concept maps of scientific processes",
|
| 272 |
+
"Relate concepts to everyday phenomena",
|
| 273 |
+
"Watch science documentaries"
|
| 274 |
+
],
|
| 275 |
+
"English": [
|
| 276 |
+
"Read diverse genres of literature",
|
| 277 |
+
"Keep a vocabulary journal",
|
| 278 |
+
"Practice writing in different styles",
|
| 279 |
+
"Analyze author's techniques"
|
| 280 |
+
],
|
| 281 |
+
"History": [
|
| 282 |
+
"Create timelines of events",
|
| 283 |
+
"Connect historical events to current affairs",
|
| 284 |
+
"Watch historical films (and fact-check them)",
|
| 285 |
+
"Debate different historical perspectives"
|
| 286 |
+
]
|
| 287 |
+
}
|
| 288 |
+
|
| 289 |
+
default_advice = [
|
| 290 |
+
"Break study sessions into 25-minute chunks",
|
| 291 |
+
"Review material regularly, not just before tests",
|
| 292 |
+
"Connect new information to what you already know",
|
| 293 |
+
"Teach the material to someone else"
|
| 294 |
+
]
|
| 295 |
+
|
| 296 |
+
course_advice = []
|
| 297 |
+
for course in courses:
|
| 298 |
+
for subject in advice:
|
| 299 |
+
if subject.lower() in course.lower():
|
| 300 |
+
course_advice.extend(advice[subject])
|
| 301 |
+
|
| 302 |
+
return course_advice if course_advice else default_advice
|
| 303 |
+
|
| 304 |
+
def generate_personalized_message(responses):
|
| 305 |
+
hobbies = [ans for q, ans in responses.items() if "favorite way to spend" in q.lower()]
|
| 306 |
+
goals = [ans for q, ans in responses.items() if "want to be when" in q.lower() or "hope to achieve" in q.lower()]
|
| 307 |
+
|
| 308 |
+
messages = []
|
| 309 |
+
if hobbies:
|
| 310 |
+
messages.append(f"I see you enjoy {hobbies[0].lower()}. Let's find ways to connect that to your learning!")
|
| 311 |
+
if goals:
|
| 312 |
+
messages.append(f"Your goal to {goals[0].lower()} is inspiring! Here's how we can work toward that:")
|
| 313 |
+
return "\n".join(messages) if messages else "I'm excited to help you achieve your learning goals!"
|
| 314 |
+
|
| 315 |
+
def assistant_response(message, history):
|
| 316 |
+
profile = load_student_profile()
|
| 317 |
+
if not profile:
|
| 318 |
+
return "Please complete and save your profile first using the previous tabs."
|
| 319 |
+
|
| 320 |
+
# Get profile data
|
| 321 |
+
learning_style = profile["learning_style"]
|
| 322 |
+
courses = profile["transcript_info"].get("Courses", [])
|
| 323 |
+
responses = profile["get_to_know_answers"]
|
| 324 |
+
|
| 325 |
+
# Generate personalized content
|
| 326 |
+
study_tips, _ = generate_study_tips(learning_style)
|
| 327 |
+
subject_advice = generate_subject_specific_advice(courses)
|
| 328 |
+
personal_message = generate_personalized_message(responses)
|
| 329 |
+
|
| 330 |
+
# Common responses
|
| 331 |
+
if "help" in message.lower() or "support" in message.lower():
|
| 332 |
+
return f"""
|
| 333 |
+
{personal_message}
|
| 334 |
+
|
| 335 |
+
Here's how I can help:
|
| 336 |
+
1. Provide study tips matching your {learning_style} learning style
|
| 337 |
+
2. Offer subject-specific advice for {', '.join(courses[:3]) if courses else 'your courses'}
|
| 338 |
+
3. Answer questions about your learning plan
|
| 339 |
+
4. Help you stay motivated
|
| 340 |
+
|
| 341 |
+
What would you like to focus on today?
|
| 342 |
+
"""
|
| 343 |
+
elif "tip" in message.lower() or "advice" in message.lower():
|
| 344 |
+
return f"""
|
| 345 |
+
π **Personalized Study Advice**
|
| 346 |
+
|
| 347 |
+
π¨ For your {learning_style} learning style:
|
| 348 |
+
{'\n'.join(f'- {tip}' for tip in study_tips)}
|
| 349 |
+
|
| 350 |
+
π Subject-specific tips:
|
| 351 |
+
{'\n'.join(f'- {advice}' for advice in subject_advice)}
|
| 352 |
+
"""
|
| 353 |
+
elif "plan" in message.lower() or "schedule" in message.lower():
|
| 354 |
+
return """
|
| 355 |
+
π
**Suggested Study Schedule**
|
| 356 |
+
- Morning (30 min): Review previous material
|
| 357 |
+
- Afternoon (45 min): Practice new concepts
|
| 358 |
+
- Evening (20 min): Quick recap
|
| 359 |
+
- Weekend: Longer project work
|
| 360 |
+
|
| 361 |
+
Remember to take breaks every 25-30 minutes!
|
| 362 |
+
"""
|
| 363 |
+
elif "motiv" in message.lower():
|
| 364 |
+
return f"""
|
| 365 |
+
πͺ **Motivation Boost**
|
| 366 |
+
{personal_message}
|
| 367 |
+
|
| 368 |
+
Remember:
|
| 369 |
+
- Progress is more important than perfection
|
| 370 |
+
- Small steps add up to big achievements
|
| 371 |
+
- Your {learning_style} learning style is your superpower!
|
| 372 |
+
"""
|
| 373 |
+
else:
|
| 374 |
+
return f"""
|
| 375 |
+
{personal_message}
|
| 376 |
+
|
| 377 |
+
I'm your personalized learning assistant! Here are things I can help with:
|
| 378 |
+
- Study tips and techniques
|
| 379 |
+
- Learning plan advice
|
| 380 |
+
- Motivation and encouragement
|
| 381 |
+
- Answering questions about your progress
|
| 382 |
+
|
| 383 |
+
Try asking about:
|
| 384 |
+
- "How should I study for my classes?"
|
| 385 |
+
- "What's the best way to learn based on my style?"
|
| 386 |
+
- "Can you help me make a study plan?"
|
| 387 |
+
"""
|
| 388 |
|
| 389 |
+
# Add assistant tab to the interface
|
| 390 |
+
with gr.Tab("π€ AI Teaching Assistant"):
|
| 391 |
+
gr.Markdown("## π Your Personalized Learning Assistant")
|
| 392 |
+
gr.Markdown("Chat with your AI assistant to get personalized learning support based on your profile.")
|
| 393 |
+
chatbot = gr.ChatInterface(
|
| 394 |
+
assistant_response,
|
| 395 |
+
examples=[
|
| 396 |
+
"How should I study based on my learning style?",
|
| 397 |
+
"Give me study tips for my courses",
|
| 398 |
+
"Help me make a study plan",
|
| 399 |
+
"I need motivation"
|
| 400 |
+
]
|
| 401 |
+
)
|
| 402 |
if __name__ == '__main__':
|
| 403 |
demo.launch()
|