Dannyar608 commited on
Commit
ff89cdb
·
verified ·
1 Parent(s): 4fc25a2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +48 -15
app.py CHANGED
@@ -71,10 +71,8 @@ style_count_map = {
71
  # Quiz logic to analyze learning style
72
  def learning_style_quiz(*answers):
73
  scores = {'visual': 0, 'auditory': 0, 'reading/writing': 0}
74
- for i, ans in enumerate(answers):
75
- idx = learning_style_answers[i].index(ans) if ans in learning_style_answers[i] else None
76
- if idx is not None:
77
- scores[style_count_map[idx]] += 1
78
  best = max(scores, key=scores.get)
79
  return best.capitalize()
80
 
@@ -110,6 +108,33 @@ get_to_know_categories = {
110
  ]
111
  }
112
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
113
  # Save all answers into profile
114
  def save_profile(file, *inputs):
115
  if not file:
@@ -119,20 +144,20 @@ def save_profile(file, *inputs):
119
  if any(ans is None for ans in quiz_answers):
120
  return "⚠️ Please answer all the learning style questions."
121
 
122
- blog_opt_in = inputs[len(learning_style_questions)]
123
  blog_text = inputs[len(learning_style_questions)+1]
124
  category_answers = inputs[len(learning_style_questions)+2:]
125
 
126
  if any(ans.strip() == "" for ans in category_answers):
127
  return "⚠️ Please complete all 'Get to Know You' sections before saving."
128
 
 
 
 
129
  df = parse_transcript(file)
130
  transcript_info = extract_transcript_info(df)
131
  learning_type = learning_style_quiz(*quiz_answers)
132
 
133
- if not blog_opt_in and blog_text.strip() == "":
134
- blog_text = "[User chose to skip this section]"
135
-
136
  question_texts = [q for cat in get_to_know_categories.values() for q, _ in cat]
137
  responses = dict(zip(question_texts, category_answers))
138
 
@@ -141,12 +166,21 @@ def save_profile(file, *inputs):
141
  "transcript_info": transcript_info,
142
  "learning_style": learning_type,
143
  "get_to_know_answers": responses,
144
- "blog": blog_text
 
 
 
 
 
 
145
  }
146
 
147
  with open("student_profile.json", "w") as f:
148
  json.dump(profile, f, indent=4)
149
 
 
 
 
150
  return f"✅ Profile saved! Your learning style is: {learning_type}"
151
 
152
  # Build Gradio UI
@@ -161,7 +195,7 @@ with gr.Blocks() as demo:
161
  quiz_components = []
162
  for i, (question, options) in enumerate(zip(learning_style_questions, learning_style_answers)):
163
  quiz_components.append(gr.Radio(
164
- choices=options,
165
  label=f"{i+1}. {question}"
166
  ))
167
 
@@ -171,16 +205,15 @@ with gr.Blocks() as demo:
171
  for q_text, _ in questions:
172
  category_inputs.append(gr.Textbox(label=q_text))
173
 
174
- blog_opt_in = gr.Checkbox(label="I want to write a personal blog for better personalization")
175
- blog_text = gr.Textbox(lines=5, label="✍️ Optional: Write a mini blog about your life", visible=True)
176
 
177
  submit = gr.Button("📥 Save My Profile")
178
  output = gr.Textbox(label="Status")
179
 
180
  submit.click(fn=save_profile,
181
- inputs=[file, *quiz_components, blog_opt_in, blog_text, *category_inputs],
182
  outputs=[output])
183
 
184
  if __name__ == '__main__':
185
- demo.launch()
186
-
 
71
  # Quiz logic to analyze learning style
72
  def learning_style_quiz(*answers):
73
  scores = {'visual': 0, 'auditory': 0, 'reading/writing': 0}
74
+ for ans in answers:
75
+ scores[ans] += 1
 
 
76
  best = max(scores, key=scores.get)
77
  return best.capitalize()
78
 
 
108
  ]
109
  }
110
 
111
+ # Generators for output summaries
112
+ def generate_learning_plan(info):
113
+ level = info.get("Grade_Level", "unknown")
114
+ courses = info.get("Courses", [])
115
+ gpa = info.get("GPA", "N/A")
116
+ return f"""
117
+ 📘 **Personalized Learning Plan**
118
+ - Grade Level: {level}
119
+ - GPA: {gpa}
120
+ - Suggested Focus Areas: {', '.join(courses[:3]) if courses else 'N/A'}
121
+ - Goals: Strengthen key subjects, explore interests, and build study habits.
122
+ """
123
+
124
+ def generate_learning_style_summary(style):
125
+ return f"""
126
+ 🧠 **Learning Style Summary**
127
+ You are a **{style}** learner. That means you learn best through {"visual aids like charts and images" if style == "Visual" else "listening and verbal instruction" if style == "Auditory" else "reading and writing-based methods"}.
128
+ """
129
+
130
+ def generate_motivation_section(responses):
131
+ hopes = [ans for q, ans in responses.items() if "hope" in q.lower() or "dream" in q.lower()]
132
+ return f"""
133
+ 💡 **Motivational Summary**
134
+ Your dreams are powerful: {'; '.join(hopes) if hopes else 'You are filled with potential!'}.
135
+ Believe in yourself and keep moving forward.
136
+ """
137
+
138
  # Save all answers into profile
139
  def save_profile(file, *inputs):
140
  if not file:
 
144
  if any(ans is None for ans in quiz_answers):
145
  return "⚠️ Please answer all the learning style questions."
146
 
147
+ blog_checkbox = inputs[len(learning_style_questions)]
148
  blog_text = inputs[len(learning_style_questions)+1]
149
  category_answers = inputs[len(learning_style_questions)+2:]
150
 
151
  if any(ans.strip() == "" for ans in category_answers):
152
  return "⚠️ Please complete all 'Get to Know You' sections before saving."
153
 
154
+ if blog_checkbox and blog_text.strip() == "":
155
+ return "⚠️ You checked the blog option but didn’t write anything. Please write your mini blog or uncheck the option."
156
+
157
  df = parse_transcript(file)
158
  transcript_info = extract_transcript_info(df)
159
  learning_type = learning_style_quiz(*quiz_answers)
160
 
 
 
 
161
  question_texts = [q for cat in get_to_know_categories.values() for q, _ in cat]
162
  responses = dict(zip(question_texts, category_answers))
163
 
 
166
  "transcript_info": transcript_info,
167
  "learning_style": learning_type,
168
  "get_to_know_answers": responses,
169
+ "blog": blog_text if blog_checkbox else "[User chose to skip this section]"
170
+ }
171
+
172
+ summary = {
173
+ "Learning_Plan": generate_learning_plan(transcript_info),
174
+ "Style_Summary": generate_learning_style_summary(learning_type),
175
+ "Motivation": generate_motivation_section(responses)
176
  }
177
 
178
  with open("student_profile.json", "w") as f:
179
  json.dump(profile, f, indent=4)
180
 
181
+ with open("student_summary.md", "w") as f:
182
+ f.write(summary["Learning_Plan"] + '\n' + summary["Style_Summary"] + '\n' + summary["Motivation"])
183
+
184
  return f"✅ Profile saved! Your learning style is: {learning_type}"
185
 
186
  # Build Gradio UI
 
195
  quiz_components = []
196
  for i, (question, options) in enumerate(zip(learning_style_questions, learning_style_answers)):
197
  quiz_components.append(gr.Radio(
198
+ choices=["visual", "auditory", "reading/writing"],
199
  label=f"{i+1}. {question}"
200
  ))
201
 
 
205
  for q_text, _ in questions:
206
  category_inputs.append(gr.Textbox(label=q_text))
207
 
208
+ blog_checkbox = gr.Checkbox(label="📝 I'd like to write a mini blog about myself")
209
+ blog_text = gr.Textbox(lines=5, label="✍️ Mini Blog", visible=True)
210
 
211
  submit = gr.Button("📥 Save My Profile")
212
  output = gr.Textbox(label="Status")
213
 
214
  submit.click(fn=save_profile,
215
+ inputs=[file, *quiz_components, blog_checkbox, blog_text, *category_inputs],
216
  outputs=[output])
217
 
218
  if __name__ == '__main__':
219
+ demo.launch()