Dannyar608 commited on
Commit
cbc7b9d
Β·
verified Β·
1 Parent(s): 373d965

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +141 -138
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’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,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’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,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’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,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
- # 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:
@@ -340,8 +341,8 @@ Here's how I can help:
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:
@@ -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
- 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
@@ -360,8 +361,8 @@ What would you like to focus on today?
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
 
@@ -370,8 +371,8 @@ Remember:
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:
@@ -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
- 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()
 
 
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
+