Dannyar608 commited on
Commit
aa96e64
ยท
verified ยท
1 Parent(s): 53b63a7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +103 -88
app.py CHANGED
@@ -35,7 +35,7 @@ def extract_transcript_info(df):
35
  info['Courses'] = list(set([c[0].strip() for c in courses]))
36
  return info
37
 
38
- # Learning style quiz
39
  learning_style_questions = [
40
  "When you are learning something new, you prefer to:",
41
  "When you are at home, you like to:",
@@ -66,6 +66,7 @@ style_count_map = {0: "visual", 1: "auditory", 2: "reading/writing"}
66
 
67
  def learning_style_quiz(*answers):
68
  scores = {'visual': 0, 'auditory': 0, 'reading/writing': 0}
 
69
  for i, ans in enumerate(answers):
70
  if i < len(learning_style_answers):
71
  options = learning_style_answers[i]
@@ -73,10 +74,13 @@ def learning_style_quiz(*answers):
73
  index = options.index(ans)
74
  style = style_count_map[index]
75
  scores[style] += 1
 
76
  max_score = max(scores.values())
77
  best_styles = [style.capitalize() for style, score in scores.items() if score == max_score]
 
78
  return ", ".join(best_styles)
79
 
 
80
  get_to_know_categories = {
81
  "All About Me": [
82
  ("Whatโ€™s your favorite way to spend a day off?", []),
@@ -112,103 +116,114 @@ get_to_know_categories = {
112
  ]
113
  }
114
 
115
- def display_saved_profile():
116
- try:
117
- with open("student_profile.json", "r") as f:
118
- profile = json.load(f)
119
- except FileNotFoundError:
120
- return "โš ๏ธ No profile data found."
 
 
 
 
 
 
121
 
122
- transcript_info = profile.get("transcript_info", {})
123
- gpa = transcript_info.get("GPA", "N/A")
124
- grade = transcript_info.get("Grade_Level", "N/A")
125
- courses = transcript_info.get("Courses", [])
 
126
 
127
- past_classes = [{'Course': course, 'Grade': 'A'} for course in courses[:max(len(courses)-2, 0)]]
128
- current_classes = [{'Course': course, 'Grade': 'IP'} for course in courses[-2:]]
 
 
 
 
 
129
 
130
- all_classes_df = pd.DataFrame(past_classes + current_classes)
 
 
 
131
 
132
- learning_type = profile.get("learning_style", "N/A")
133
- responses = profile.get("get_to_know_answers", {})
134
- blog = profile.get("blog", "[User skipped this section]")
135
 
136
- comments = [f"โญ I love how you spend your free time: {responses.get('Whatโ€™s your favorite way to spend a day off?', 'N/A')}.",
137
- f"๐Ÿ• {responses.get('If you could only eat one food for the rest of your life, what would it be?', 'N/A')} sounds delicious!",
138
- f"๐ŸŽฌ You mentioned {responses.get('What are some of your favorite movies or shows?', 'N/A')}. Great picks!"]
139
 
140
- blog_comment = ""
141
- if blog and blog != "[User chose to skip this section]":
142
- blog_comment = f"๐Ÿ“ Your blog was very thoughtful! You wrote: \"{blog[:150]}...\""
143
 
144
- summary_text = f"""
145
- ๐Ÿ‘ค **Student Overview**
146
- - Name: Extracted from transcript (if available)
147
- - GPA: {gpa}
148
- - Grade Level: {grade}
149
- ๐Ÿ“š **Courses**
150
- {all_classes_df.to_markdown(index=False)}
151
- ๐Ÿง  **Learning Type**
152
- Based on your answers, your learning style is: **{learning_type}**
153
- ๐Ÿ’ฌ **Personal Reflections**
154
- {chr(10).join(comments)}
155
- {blog_comment}
156
- โ“ Is all this information correct?
157
- """
158
- return summary_text
159
 
 
 
 
 
 
 
 
160
 
161
- # Interface
 
 
 
 
 
 
 
 
 
 
 
 
 
 
162
  with gr.Blocks() as demo:
163
- profile_interface = gr.Column(visible=True)
164
- confirmation_interface = gr.Column(visible=False)
165
-
166
- with profile_interface:
167
- gr.Markdown("## โœ๏ธ Create Your Profile")
168
- transcript_input = gr.File(label="Upload Transcript (.csv, .xlsx, or .pdf)")
169
- ls_dropdowns = [gr.Dropdown(choices=learning_style_answers[i], label=learning_style_questions[i]) for i in range(10)]
170
- get_to_know_inputs = {}
171
- for section, questions in get_to_know_categories.items():
172
- gr.Markdown(f"### {section}")
173
- for q, _ in questions:
174
- get_to_know_inputs[q] = gr.Textbox(label=q)
175
- blog_input = gr.Textbox(label="Write a short blog about yourself (optional)", lines=5)
176
- save_btn = gr.Button("Save Profile")
177
-
178
- with confirmation_interface:
179
- gr.Markdown("## โœ… Profile Review & Confirmation")
180
- summary_output = gr.Markdown()
181
- confirm_btn = gr.Button("Yes, everything is correct")
182
- correct_btn = gr.Button("No, I need to make changes")
183
- final_status = gr.Textbox(label="Final Status")
184
-
185
- def save_profile(transcript_file, *answers):
186
- df = parse_transcript(transcript_file)
187
- transcript_info = extract_transcript_info(df)
188
- learning_result = learning_style_quiz(*answers[:10])
189
- personal_responses = {q: ans for q, ans in zip(get_to_know_inputs.keys(), answers[10:-1])}
190
- blog_text = answers[-1]
191
-
192
- student_data = {
193
- "transcript_info": transcript_info,
194
- "learning_style": learning_result,
195
- "get_to_know_answers": personal_responses,
196
- "blog": blog_text or "[User chose to skip this section]"
197
- }
198
-
199
- with open("student_profile.json", "w") as f:
200
- json.dump(student_data, f, indent=2)
201
-
202
- return gr.update(visible=False), gr.update(visible=True), display_saved_profile()
203
-
204
- save_btn.click(
205
- fn=save_profile,
206
- inputs=[transcript_input] + ls_dropdowns + list(get_to_know_inputs.values()) + [blog_input],
207
- outputs=[profile_interface, confirmation_interface, summary_output]
208
- )
209
-
210
- confirm_btn.click(fn=lambda: "๐ŸŽ‰ All set! You're ready to move forward.", outputs=[final_status])
211
- correct_btn.click(fn=lambda: "๐Ÿ” Okay! Please update the necessary information and save again.", outputs=[final_status])
212
 
213
  if __name__ == '__main__':
214
  demo.launch()
 
35
  info['Courses'] = list(set([c[0].strip() for c in courses]))
36
  return info
37
 
38
+ # Learning style questions - from educationplanner.org
39
  learning_style_questions = [
40
  "When you are learning something new, you prefer to:",
41
  "When you are at home, you like to:",
 
66
 
67
  def learning_style_quiz(*answers):
68
  scores = {'visual': 0, 'auditory': 0, 'reading/writing': 0}
69
+
70
  for i, ans in enumerate(answers):
71
  if i < len(learning_style_answers):
72
  options = learning_style_answers[i]
 
74
  index = options.index(ans)
75
  style = style_count_map[index]
76
  scores[style] += 1
77
+
78
  max_score = max(scores.values())
79
  best_styles = [style.capitalize() for style, score in scores.items() if score == max_score]
80
+
81
  return ", ".join(best_styles)
82
 
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?", []),
 
116
  ]
117
  }
118
 
119
+ # Generators for output summaries
120
+ def generate_learning_plan(info):
121
+ level = info.get("Grade_Level", "unknown")
122
+ courses = info.get("Courses", [])
123
+ gpa = info.get("GPA", "N/A")
124
+ return f"""
125
+ ๐Ÿ“˜ **Personalized Learning Plan**
126
+ - Grade Level: {level}
127
+ - GPA: {gpa}
128
+ - Suggested Focus Areas: {', '.join(courses[:3]) if courses else 'N/A'}
129
+ - Goals: Strengthen key subjects, explore interests, and build study habits.
130
+ """
131
 
132
+ def generate_learning_style_summary(style):
133
+ return f"""
134
+ ๐Ÿง  **Learning Style Summary**
135
+ You are a **{style}** learner. That means you learn best through {"visual aids like charts and images" if "Visual" in style else "listening and verbal instruction" if "Auditory" in style else "reading and writing-based methods"}.
136
+ """
137
 
138
+ def generate_motivation_section(responses):
139
+ hopes = [ans for q, ans in responses.items() if "hope" in q.lower() or "dream" in q.lower()]
140
+ return f"""
141
+ ๐Ÿ’ก **Motivational Summary**
142
+ Your dreams are powerful: {'; '.join(hopes) if hopes else 'You are filled with potential!'}.
143
+ Believe in yourself and keep moving forward.
144
+ """
145
 
146
+ # Save all answers into profile
147
+ def save_profile(file, *inputs):
148
+ if not file:
149
+ return "โš ๏ธ Please upload your transcript."
150
 
151
+ quiz_answers = inputs[:len(learning_style_questions)]
152
+ if any(ans is None for ans in quiz_answers):
153
+ return "โš ๏ธ Please answer all the learning style questions."
154
 
155
+ blog_checkbox = inputs[len(learning_style_questions)]
156
+ blog_text = inputs[len(learning_style_questions)+1]
157
+ category_answers = inputs[len(learning_style_questions)+2:]
158
 
159
+ if any(ans.strip() == "" for ans in category_answers):
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)
167
+ learning_type = learning_style_quiz(*quiz_answers)
168
+
169
+ question_texts = [q for cat in get_to_know_categories.values() for q, _ in cat]
170
+ responses = dict(zip(question_texts, category_answers))
 
 
 
 
 
 
171
 
172
+ profile = {
173
+ "transcript": df.to_dict(orient='records'),
174
+ "transcript_info": transcript_info,
175
+ "learning_style": learning_type,
176
+ "get_to_know_answers": responses,
177
+ "blog": blog_text if blog_checkbox else "[User chose to skip this section]"
178
+ }
179
 
180
+ summary = {
181
+ "Learning_Plan": generate_learning_plan(transcript_info),
182
+ "Style_Summary": generate_learning_style_summary(learning_type),
183
+ "Motivation": generate_motivation_section(responses)
184
+ }
185
+
186
+ with open("student_profile.json", "w") as f:
187
+ json.dump(profile, f, indent=4)
188
+
189
+ with open("student_summary.md", "w") as f:
190
+ f.write(summary["Learning_Plan"] + '\n' + summary["Style_Summary"] + '\n' + summary["Motivation"])
191
+
192
+ return f"โœ… Profile saved! Your learning style is: {learning_type}"
193
+
194
+ # Build Gradio UI
195
  with gr.Blocks() as demo:
196
+ gr.Markdown("## ๐ŸŽ“ Personalized AI Student Assistant")
197
+
198
+ with gr.Row():
199
+ file = gr.File(label="๐Ÿ“„ Upload Your Transcript (.csv, .xlsx, .pdf)")
200
+
201
+ with gr.Column():
202
+ gr.Markdown("### ๐Ÿง  Learning Style Discovery")
203
+ quiz_components = []
204
+ for i, (question, options) in enumerate(zip(learning_style_questions, learning_style_answers)):
205
+ quiz_components.append(gr.Radio(
206
+ choices=options,
207
+ label=f"{i+1}. {question}"
208
+ ))
209
+
210
+ category_inputs = []
211
+ for category, questions in get_to_know_categories.items():
212
+ gr.Markdown(f"### ๐Ÿ“˜ {category}")
213
+ for q_text, _ in questions:
214
+ category_inputs.append(gr.Textbox(label=q_text))
215
+
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")
223
+
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()