Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -83,11 +83,11 @@ def learning_style_quiz(*answers):
|
|
| 83 |
# PanoramaEd categories and multiple choice questions
|
| 84 |
get_to_know_categories = {
|
| 85 |
"All About Me": [
|
| 86 |
-
("What
|
| 87 |
("If you could only eat one food for the rest of your life, what would it be?", []),
|
| 88 |
("Do you have any pets? If so, what are their names?", []),
|
| 89 |
("If you could travel anywhere in the world, where would you go?", []),
|
| 90 |
-
("What
|
| 91 |
("What are some of your favorite movies or shows?", []),
|
| 92 |
("Do you have a favorite book or book series? Why?", []),
|
| 93 |
("Who is a character from a show, book, or movie that you relate to? Why?", []),
|
|
@@ -95,24 +95,24 @@ get_to_know_categories = {
|
|
| 95 |
],
|
| 96 |
"Hopes and Dreams": [
|
| 97 |
("What do you want to be when you grow up?", []),
|
| 98 |
-
("What
|
| 99 |
("If you could change the world in one way, what would you do?", []),
|
| 100 |
("What are you most proud of?", []),
|
| 101 |
-
("What
|
| 102 |
],
|
| 103 |
"School Life": [
|
| 104 |
-
("What
|
| 105 |
-
("What
|
| 106 |
("Do you prefer working alone or in groups?", []),
|
| 107 |
("What helps you feel confident in class?", []),
|
| 108 |
-
("What
|
| 109 |
],
|
| 110 |
"Relationships": [
|
| 111 |
("Who do you look up to and why?", []),
|
| 112 |
("Who is someone that makes you feel safe and supported?", []),
|
| 113 |
("Do you have a best friend? What do you like to do together?", []),
|
| 114 |
-
("What
|
| 115 |
-
("What
|
| 116 |
]
|
| 117 |
}
|
| 118 |
|
|
@@ -160,7 +160,7 @@ def save_profile(file, *inputs):
|
|
| 160 |
return "β οΈ Please complete all 'Get to Know You' sections before saving."
|
| 161 |
|
| 162 |
if blog_checkbox and blog_text.strip() == "":
|
| 163 |
-
return "β οΈ You checked the blog option but didn
|
| 164 |
|
| 165 |
df = parse_transcript(file)
|
| 166 |
transcript_info = extract_transcript_info(df)
|
|
@@ -216,7 +216,7 @@ with gr.Blocks() as demo:
|
|
| 216 |
blog_checkbox = gr.Checkbox(label="π I'd like to write a mini blog about myself")
|
| 217 |
blog_text = gr.Textbox(lines=5, label="βοΈ Mini Blog", visible=False)
|
| 218 |
|
| 219 |
-
blog_checkbox.change(fn=lambda x: gr.update(visible=x), inputs=blog_checkbox, outputs=blog_text
|
| 220 |
|
| 221 |
submit = gr.Button("ποΈ Save My Profile")
|
| 222 |
output = gr.Textbox(label="Status")
|
|
@@ -224,112 +224,113 @@ 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 |
-
|
| 229 |
-
|
| 230 |
-
|
| 231 |
-
|
| 232 |
-
|
| 233 |
-
|
| 234 |
-
|
| 235 |
-
|
| 236 |
-
|
| 237 |
-
|
| 238 |
-
"
|
| 239 |
-
|
| 240 |
-
|
| 241 |
-
|
| 242 |
-
|
| 243 |
-
|
| 244 |
-
|
| 245 |
-
"
|
| 246 |
-
|
| 247 |
-
|
| 248 |
-
|
| 249 |
-
|
| 250 |
-
|
| 251 |
-
|
| 252 |
-
"
|
| 253 |
-
|
| 254 |
-
|
| 255 |
-
|
| 256 |
-
|
| 257 |
-
|
| 258 |
-
|
| 259 |
-
|
| 260 |
-
|
| 261 |
-
|
| 262 |
-
|
| 263 |
-
|
| 264 |
-
"
|
| 265 |
-
|
| 266 |
-
|
| 267 |
-
|
| 268 |
-
|
| 269 |
-
|
| 270 |
-
"
|
| 271 |
-
|
| 272 |
-
|
| 273 |
-
|
| 274 |
-
|
| 275 |
-
|
| 276 |
-
"
|
| 277 |
-
|
| 278 |
-
|
| 279 |
-
|
| 280 |
-
|
| 281 |
-
|
| 282 |
-
"
|
| 283 |
-
|
| 284 |
-
|
| 285 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 286 |
]
|
| 287 |
-
|
| 288 |
-
|
| 289 |
-
|
| 290 |
-
|
| 291 |
-
|
| 292 |
-
|
| 293 |
-
|
| 294 |
-
|
| 295 |
-
|
| 296 |
-
|
| 297 |
-
|
| 298 |
-
for
|
| 299 |
-
|
| 300 |
-
|
| 301 |
-
|
| 302 |
-
|
| 303 |
-
|
| 304 |
-
|
| 305 |
-
|
| 306 |
-
|
| 307 |
-
|
| 308 |
-
|
| 309 |
-
|
| 310 |
-
|
| 311 |
-
|
| 312 |
-
|
| 313 |
-
|
| 314 |
-
|
| 315 |
-
|
| 316 |
-
|
| 317 |
-
|
| 318 |
-
|
| 319 |
-
|
| 320 |
-
|
| 321 |
-
|
| 322 |
-
|
| 323 |
-
|
| 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:
|
|
@@ -340,8 +341,8 @@ Here's how I can help:
|
|
| 340 |
|
| 341 |
What would you like to focus on today?
|
| 342 |
"""
|
| 343 |
-
|
| 344 |
-
|
| 345 |
π **Personalized Study Advice**
|
| 346 |
|
| 347 |
π¨ For your {learning_style} learning style:
|
|
@@ -350,8 +351,8 @@ What would you like to focus on today?
|
|
| 350 |
π Subject-specific tips:
|
| 351 |
{'\n'.join(f'- {advice}' for advice in subject_advice)}
|
| 352 |
"""
|
| 353 |
-
|
| 354 |
-
|
| 355 |
π
**Suggested Study Schedule**
|
| 356 |
- Morning (30 min): Review previous material
|
| 357 |
- Afternoon (45 min): Practice new concepts
|
|
@@ -360,8 +361,8 @@ What would you like to focus on today?
|
|
| 360 |
|
| 361 |
Remember to take breaks every 25-30 minutes!
|
| 362 |
"""
|
| 363 |
-
|
| 364 |
-
|
| 365 |
πͺ **Motivation Boost**
|
| 366 |
{personal_message}
|
| 367 |
|
|
@@ -370,8 +371,8 @@ Remember:
|
|
| 370 |
- Small steps add up to big achievements
|
| 371 |
- Your {learning_style} learning style is your superpower!
|
| 372 |
"""
|
| 373 |
-
|
| 374 |
-
|
| 375 |
{personal_message}
|
| 376 |
|
| 377 |
I'm your personalized learning assistant! Here are things I can help with:
|
|
@@ -386,18 +387,20 @@ Try asking about:
|
|
| 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 |
-
|
| 392 |
-
|
| 393 |
-
|
| 394 |
-
|
| 395 |
-
|
| 396 |
-
|
| 397 |
-
|
| 398 |
-
|
| 399 |
-
|
| 400 |
-
|
| 401 |
-
|
|
|
|
| 402 |
if __name__ == '__main__':
|
| 403 |
-
demo.launch()
|
|
|
|
|
|
| 83 |
# PanoramaEd categories and multiple choice questions
|
| 84 |
get_to_know_categories = {
|
| 85 |
"All About Me": [
|
| 86 |
+
("What's your favorite way to spend a day off?", []),
|
| 87 |
("If you could only eat one food for the rest of your life, what would it be?", []),
|
| 88 |
("Do you have any pets? If so, what are their names?", []),
|
| 89 |
("If you could travel anywhere in the world, where would you go?", []),
|
| 90 |
+
("What's your favorite holiday or tradition?", []),
|
| 91 |
("What are some of your favorite movies or shows?", []),
|
| 92 |
("Do you have a favorite book or book series? Why?", []),
|
| 93 |
("Who is a character from a show, book, or movie that you relate to? Why?", []),
|
|
|
|
| 95 |
],
|
| 96 |
"Hopes and Dreams": [
|
| 97 |
("What do you want to be when you grow up?", []),
|
| 98 |
+
("What's something you hope to achieve this year?", []),
|
| 99 |
("If you could change the world in one way, what would you do?", []),
|
| 100 |
("What are you most proud of?", []),
|
| 101 |
+
("What's a big dream you have for your future?", [])
|
| 102 |
],
|
| 103 |
"School Life": [
|
| 104 |
+
("What's your favorite subject in school?", []),
|
| 105 |
+
("What's something that makes learning easier for you?", []),
|
| 106 |
("Do you prefer working alone or in groups?", []),
|
| 107 |
("What helps you feel confident in class?", []),
|
| 108 |
+
("What's something you're good at in school?", [])
|
| 109 |
],
|
| 110 |
"Relationships": [
|
| 111 |
("Who do you look up to and why?", []),
|
| 112 |
("Who is someone that makes you feel safe and supported?", []),
|
| 113 |
("Do you have a best friend? What do you like to do together?", []),
|
| 114 |
+
("What's one thing you wish people knew about you?", []),
|
| 115 |
+
("What's something kind you've done for someone else?", [])
|
| 116 |
]
|
| 117 |
}
|
| 118 |
|
|
|
|
| 160 |
return "β οΈ Please complete all 'Get to Know You' sections before saving."
|
| 161 |
|
| 162 |
if blog_checkbox and blog_text.strip() == "":
|
| 163 |
+
return "β οΈ You checked the blog option but didn't write anything. Please write your mini blog or uncheck the option."
|
| 164 |
|
| 165 |
df = parse_transcript(file)
|
| 166 |
transcript_info = extract_transcript_info(df)
|
|
|
|
| 216 |
blog_checkbox = gr.Checkbox(label="π I'd like to write a mini blog about myself")
|
| 217 |
blog_text = gr.Textbox(lines=5, label="βοΈ Mini Blog", visible=False)
|
| 218 |
|
| 219 |
+
blog_checkbox.change(fn=lambda x: gr.update(visible=x), inputs=blog_checkbox, outputs=blog_text
|
| 220 |
|
| 221 |
submit = gr.Button("ποΈ Save My Profile")
|
| 222 |
output = gr.Textbox(label="Status")
|
|
|
|
| 224 |
submit.click(fn=save_profile,
|
| 225 |
inputs=[file, *quiz_components, blog_checkbox, blog_text, *category_inputs],
|
| 226 |
outputs=[output])
|
| 227 |
+
|
| 228 |
+
# Assistant component functions
|
| 229 |
+
def load_student_profile():
|
| 230 |
+
try:
|
| 231 |
+
with open("student_profile.json", "r") as f:
|
| 232 |
+
return json.load(f)
|
| 233 |
+
except FileNotFoundError:
|
| 234 |
+
return None
|
| 235 |
+
|
| 236 |
+
def generate_study_tips(learning_style):
|
| 237 |
+
tips = {
|
| 238 |
+
"Visual": [
|
| 239 |
+
"Use color-coding in your notes",
|
| 240 |
+
"Create mind maps or diagrams",
|
| 241 |
+
"Watch educational videos",
|
| 242 |
+
"Use flashcards with images",
|
| 243 |
+
"Draw pictures to represent concepts"
|
| 244 |
+
],
|
| 245 |
+
"Auditory": [
|
| 246 |
+
"Record lectures and listen to them",
|
| 247 |
+
"Explain concepts out loud to yourself",
|
| 248 |
+
"Participate in study groups",
|
| 249 |
+
"Use mnemonic devices with rhymes",
|
| 250 |
+
"Listen to educational podcasts"
|
| 251 |
+
],
|
| 252 |
+
"Reading/writing": [
|
| 253 |
+
"Rewrite your notes in your own words",
|
| 254 |
+
"Create detailed outlines",
|
| 255 |
+
"Write summaries of what you learn",
|
| 256 |
+
"Read textbooks and articles",
|
| 257 |
+
"Keep a learning journal"
|
| 258 |
+
]
|
| 259 |
+
}
|
| 260 |
+
return tips.get(learning_style.split(", ")[0], [])
|
| 261 |
+
|
| 262 |
+
def generate_subject_specific_advice(courses):
|
| 263 |
+
advice = {
|
| 264 |
+
"Math": [
|
| 265 |
+
"Practice problems daily",
|
| 266 |
+
"Focus on understanding concepts, not just memorization",
|
| 267 |
+
"Show all your work step-by-step",
|
| 268 |
+
"Relate math to real-world applications"
|
| 269 |
+
],
|
| 270 |
+
"Science": [
|
| 271 |
+
"Conduct simple experiments at home",
|
| 272 |
+
"Create concept maps of scientific processes",
|
| 273 |
+
"Relate concepts to everyday phenomena",
|
| 274 |
+
"Watch science documentaries"
|
| 275 |
+
],
|
| 276 |
+
"English": [
|
| 277 |
+
"Read diverse genres of literature",
|
| 278 |
+
"Keep a vocabulary journal",
|
| 279 |
+
"Practice writing in different styles",
|
| 280 |
+
"Analyze author's techniques"
|
| 281 |
+
],
|
| 282 |
+
"History": [
|
| 283 |
+
"Create timelines of events",
|
| 284 |
+
"Connect historical events to current affairs",
|
| 285 |
+
"Watch historical films (and fact-check them)",
|
| 286 |
+
"Debate different historical perspectives"
|
| 287 |
+
]
|
| 288 |
+
}
|
| 289 |
+
|
| 290 |
+
default_advice = [
|
| 291 |
+
"Break study sessions into 25-minute chunks",
|
| 292 |
+
"Review material regularly, not just before tests",
|
| 293 |
+
"Connect new information to what you already know",
|
| 294 |
+
"Teach the material to someone else"
|
| 295 |
]
|
| 296 |
+
|
| 297 |
+
course_advice = []
|
| 298 |
+
for course in courses:
|
| 299 |
+
for subject in advice:
|
| 300 |
+
if subject.lower() in course.lower():
|
| 301 |
+
course_advice.extend(advice[subject])
|
| 302 |
+
|
| 303 |
+
return course_advice if course_advice else default_advice
|
| 304 |
+
|
| 305 |
+
def generate_personalized_message(responses):
|
| 306 |
+
hobbies = [ans for q, ans in responses.items() if "favorite way to spend" in q.lower()]
|
| 307 |
+
goals = [ans for q, ans in responses.items() if "want to be when" in q.lower() or "hope to achieve" in q.lower()]
|
| 308 |
+
|
| 309 |
+
messages = []
|
| 310 |
+
if hobbies:
|
| 311 |
+
messages.append(f"I see you enjoy {hobbies[0].lower()}. Let's find ways to connect that to your learning!")
|
| 312 |
+
if goals:
|
| 313 |
+
messages.append(f"Your goal to {goals[0].lower()} is inspiring! Here's how we can work toward that:")
|
| 314 |
+
return "\n".join(messages) if messages else "I'm excited to help you achieve your learning goals!"
|
| 315 |
+
|
| 316 |
+
def assistant_response(message, history):
|
| 317 |
+
profile = load_student_profile()
|
| 318 |
+
if not profile:
|
| 319 |
+
return "Please complete and save your profile first using the previous tabs."
|
| 320 |
+
|
| 321 |
+
# Get profile data
|
| 322 |
+
learning_style = profile["learning_style"]
|
| 323 |
+
courses = profile["transcript_info"].get("Courses", [])
|
| 324 |
+
responses = profile["get_to_know_answers"]
|
| 325 |
+
|
| 326 |
+
# Generate personalized content
|
| 327 |
+
study_tips = generate_study_tips(learning_style)
|
| 328 |
+
subject_advice = generate_subject_specific_advice(courses)
|
| 329 |
+
personal_message = generate_personalized_message(responses)
|
| 330 |
+
|
| 331 |
+
# Common responses
|
| 332 |
+
if "help" in message.lower() or "support" in message.lower():
|
| 333 |
+
return f"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 334 |
{personal_message}
|
| 335 |
|
| 336 |
Here's how I can help:
|
|
|
|
| 341 |
|
| 342 |
What would you like to focus on today?
|
| 343 |
"""
|
| 344 |
+
elif "tip" in message.lower() or "advice" in message.lower():
|
| 345 |
+
return f"""
|
| 346 |
π **Personalized Study Advice**
|
| 347 |
|
| 348 |
π¨ For your {learning_style} learning style:
|
|
|
|
| 351 |
π Subject-specific tips:
|
| 352 |
{'\n'.join(f'- {advice}' for advice in subject_advice)}
|
| 353 |
"""
|
| 354 |
+
elif "plan" in message.lower() or "schedule" in message.lower():
|
| 355 |
+
return """
|
| 356 |
π
**Suggested Study Schedule**
|
| 357 |
- Morning (30 min): Review previous material
|
| 358 |
- Afternoon (45 min): Practice new concepts
|
|
|
|
| 361 |
|
| 362 |
Remember to take breaks every 25-30 minutes!
|
| 363 |
"""
|
| 364 |
+
elif "motiv" in message.lower():
|
| 365 |
+
return f"""
|
| 366 |
πͺ **Motivation Boost**
|
| 367 |
{personal_message}
|
| 368 |
|
|
|
|
| 371 |
- Small steps add up to big achievements
|
| 372 |
- Your {learning_style} learning style is your superpower!
|
| 373 |
"""
|
| 374 |
+
else:
|
| 375 |
+
return f"""
|
| 376 |
{personal_message}
|
| 377 |
|
| 378 |
I'm your personalized learning assistant! Here are things I can help with:
|
|
|
|
| 387 |
- "Can you help me make a study plan?"
|
| 388 |
"""
|
| 389 |
|
| 390 |
+
# Add assistant tab to the interface
|
| 391 |
+
with gr.Tab("π€ AI Teaching Assistant"):
|
| 392 |
+
gr.Markdown("## π Your Personalized Learning Assistant")
|
| 393 |
+
gr.Markdown("Chat with your AI assistant to get personalized learning support based on your profile.")
|
| 394 |
+
chatbot = gr.ChatInterface(
|
| 395 |
+
assistant_response,
|
| 396 |
+
examples=[
|
| 397 |
+
"How should I study based on my learning style?",
|
| 398 |
+
"Give me study tips for my courses",
|
| 399 |
+
"Help me make a study plan",
|
| 400 |
+
"I need motivation"
|
| 401 |
+
]
|
| 402 |
+
)
|
| 403 |
+
|
| 404 |
if __name__ == '__main__':
|
| 405 |
+
demo.launch()
|
| 406 |
+
|