Dannyar608 commited on
Commit
9a20088
ยท
verified ยท
1 Parent(s): ef2f775

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +56 -66
app.py CHANGED
@@ -24,28 +24,22 @@ def parse_transcript(file):
24
  def extract_transcript_info(df):
25
  transcript_text = df['Transcript_Text'].iloc[0] if 'Transcript_Text' in df.columns else ''
26
  info = {}
27
-
28
- # GPA extraction
29
- gpa_matches = re.findall(r'(weighted|unweighted)?\s*GPA[:\s-]*([0-4]\.?\d{0,2})', transcript_text, re.IGNORECASE)
30
- for gpa_type, gpa_value in gpa_matches:
31
- key = f"{gpa_type.strip().capitalize() if gpa_type else 'GPA'}"
32
- info[key] = gpa_value
33
-
34
- # Grade Level
35
- grade_match = re.search(r'Grade:?\s*(\d{1,2})', transcript_text, re.IGNORECASE)
 
 
36
  if grade_match:
37
  info['Grade_Level'] = grade_match.group(1)
38
-
39
- # Full Name
40
- name_match = re.search(r'(Student Name|Name):?\s*([A-Z][a-z]+\s+[A-Z][a-z]+)', transcript_text)
41
- if name_match:
42
- info['Full_Name'] = name_match.group(2)
43
-
44
- # Courses
45
  courses = re.findall(r'(?i)\b([A-Z][a-zA-Z\s&/]+)\s+(\d{1,3})\b', transcript_text)
46
  if courses:
47
  info['Courses'] = list(set([c[0].strip() for c in courses]))
48
-
49
  return info
50
 
51
  # Learning style questions - from educationplanner.org
@@ -93,6 +87,7 @@ def learning_style_quiz(*answers):
93
 
94
  return ", ".join(best_styles)
95
 
 
96
  get_to_know_categories = {
97
  "All About Me": [
98
  ("Whatโ€™s your favorite way to spend a day off?", []),
@@ -131,7 +126,7 @@ get_to_know_categories = {
131
  def generate_learning_plan(info):
132
  level = info.get("Grade_Level", "unknown")
133
  courses = info.get("Courses", [])
134
- gpa = info.get("GPA", info.get("Unweighted", "N/A"))
135
  return f"""
136
  ๐Ÿ“˜ **Personalized Learning Plan**
137
  - Grade Level: {level}
@@ -154,63 +149,58 @@ Your dreams are powerful: {'; '.join(hopes) if hopes else 'You are filled with p
154
  Believe in yourself and keep moving forward.
155
  """
156
 
157
- def show_basic_info():
158
- with open("student_profile.json") as f:
159
- profile = json.load(f)
160
- info = profile["transcript_info"]
161
- name = info.get("Full_Name", "Name not found")
162
- grade = info.get("Grade_Level", "N/A")
163
- gpa = info.get("GPA", info.get("Unweighted", "N/A"))
164
- weighted = info.get("Weighted", "Not provided")
165
- return f"๐Ÿ‘ค Name: {name}\n๐ŸŽ“ Grade Level: {grade}\n๐Ÿ“Š GPA: {gpa}\n๐Ÿ“ˆ Weighted GPA: {weighted}"
166
-
167
  def save_profile(file, *inputs):
168
- if not file:
169
- return gr.Textbox.update(value="โš ๏ธ Please upload your transcript."), gr.Textbox.update(visible=False)
 
170
 
171
- quiz_answers = inputs[:len(learning_style_questions)]
172
- if any(ans is None for ans in quiz_answers):
173
- return gr.Textbox.update(value="โš ๏ธ Please answer all the learning style questions."), gr.Textbox.update(visible=False)
174
 
175
- blog_checkbox = inputs[len(learning_style_questions)]
176
- blog_text = inputs[len(learning_style_questions)+1]
177
- category_answers = inputs[len(learning_style_questions)+2:]
178
 
179
- if any(ans.strip() == "" for ans in category_answers):
180
- return gr.Textbox.update(value="โš ๏ธ Please complete all 'Get to Know You' sections before saving."), gr.Textbox.update(visible=False)
181
 
182
- if blog_checkbox and blog_text.strip() == "":
183
- return gr.Textbox.update(value="โš ๏ธ You checked the blog option but didnโ€™t write anything. Please write your mini blog or uncheck the option."), gr.Textbox.update(visible=False)
184
 
185
- df = parse_transcript(file)
186
- transcript_info = extract_transcript_info(df)
187
- learning_type = learning_style_quiz(*quiz_answers)
188
 
189
- question_texts = [q for cat in get_to_know_categories.values() for q, _ in cat]
190
- responses = dict(zip(question_texts, category_answers))
191
 
192
- profile = {
193
- "transcript": df.to_dict(orient='records'),
194
- "transcript_info": transcript_info,
195
- "learning_style": learning_type,
196
- "get_to_know_answers": responses,
197
- "blog": blog_text if blog_checkbox else "[User chose to skip this section]"
198
- }
199
 
200
- summary = {
201
- "Learning_Plan": generate_learning_plan(transcript_info),
202
- "Style_Summary": generate_learning_style_summary(learning_type),
203
- "Motivation": generate_motivation_section(responses)
204
- }
205
 
206
- with open("student_profile.json", "w") as f:
207
- json.dump(profile, f, indent=4)
208
 
209
- with open("student_summary.md", "w") as f:
210
- f.write(summary["Learning_Plan"] + '\n' + summary["Style_Summary"] + '\n' + summary["Motivation"])
211
 
212
- return gr.Textbox.update(value="โœ… Profile saved!"), gr.Textbox.update(value=show_basic_info(), visible=True)
 
 
 
213
 
 
214
  with gr.Blocks() as demo:
215
  gr.Markdown("## ๐ŸŽ“ Personalized AI Student Assistant")
216
 
@@ -234,15 +224,15 @@ with gr.Blocks() as demo:
234
 
235
  blog_checkbox = gr.Checkbox(label="๐Ÿ“ I'd like to write a mini blog about myself")
236
  blog_text = gr.Textbox(lines=5, label="โœ๏ธ Mini Blog", visible=False)
 
237
  blog_checkbox.change(fn=lambda x: gr.update(visible=x), inputs=blog_checkbox, outputs=blog_text)
238
 
239
  submit = gr.Button("๐Ÿ—•๏ธ Save My Profile")
240
- status_output = gr.Textbox(label="Status")
241
- user_info_output = gr.Textbox(label="๐Ÿ‘ค Your Info", visible=False)
242
 
243
  submit.click(fn=save_profile,
244
  inputs=[file, *quiz_components, blog_checkbox, blog_text, *category_inputs],
245
- outputs=[status_output, user_info_output])
246
 
247
  if __name__ == '__main__':
248
- demo.launch()
 
24
  def extract_transcript_info(df):
25
  transcript_text = df['Transcript_Text'].iloc[0] if 'Transcript_Text' in df.columns else ''
26
  info = {}
27
+ name_match = re.search(r"Name[:\s]+([A-Z][a-z]+\s[A-Z][a-z]+)", transcript_text)
28
+ if name_match:
29
+ info['Name'] = name_match.group(1)
30
+ gpa_match = re.findall(r'(GPA|Grade Point Average)[^\d]*(\d+\.\d+)', transcript_text, re.IGNORECASE)
31
+ if gpa_match:
32
+ if len(gpa_match) == 1:
33
+ info['GPA'] = gpa_match[0][1]
34
+ elif len(gpa_match) >= 2:
35
+ info['Unweighted_GPA'] = gpa_match[0][1]
36
+ info['Weighted_GPA'] = gpa_match[1][1]
37
+ grade_match = re.search(r'Grade:?[\s]*(\d{1,2})', transcript_text, re.IGNORECASE)
38
  if grade_match:
39
  info['Grade_Level'] = grade_match.group(1)
 
 
 
 
 
 
 
40
  courses = re.findall(r'(?i)\b([A-Z][a-zA-Z\s&/]+)\s+(\d{1,3})\b', transcript_text)
41
  if courses:
42
  info['Courses'] = list(set([c[0].strip() for c in courses]))
 
43
  return info
44
 
45
  # Learning style questions - from educationplanner.org
 
87
 
88
  return ", ".join(best_styles)
89
 
90
+ # PanoramaEd categories and multiple choice questions
91
  get_to_know_categories = {
92
  "All About Me": [
93
  ("Whatโ€™s your favorite way to spend a day off?", []),
 
126
  def generate_learning_plan(info):
127
  level = info.get("Grade_Level", "unknown")
128
  courses = info.get("Courses", [])
129
+ gpa = info.get("GPA", info.get("Unweighted_GPA", "N/A"))
130
  return f"""
131
  ๐Ÿ“˜ **Personalized Learning Plan**
132
  - Grade Level: {level}
 
149
  Believe in yourself and keep moving forward.
150
  """
151
 
 
 
 
 
 
 
 
 
 
 
152
  def save_profile(file, *inputs):
153
+ try:
154
+ if not file:
155
+ return "โš ๏ธ Please upload your transcript."
156
 
157
+ quiz_answers = inputs[:len(learning_style_questions)]
158
+ if any(ans is None for ans in quiz_answers):
159
+ return "โš ๏ธ Please answer all the learning style questions."
160
 
161
+ blog_checkbox = inputs[len(learning_style_questions)]
162
+ blog_text = inputs[len(learning_style_questions)+1]
163
+ category_answers = inputs[len(learning_style_questions)+2:]
164
 
165
+ if any(ans.strip() == "" for ans in category_answers):
166
+ return "โš ๏ธ Please complete all 'Get to Know You' sections before saving."
167
 
168
+ if blog_checkbox and blog_text.strip() == "":
169
+ return "โš ๏ธ You checked the blog option but didnโ€™t write anything. Please write your mini blog or uncheck the option."
170
 
171
+ df = parse_transcript(file)
172
+ transcript_info = extract_transcript_info(df)
173
+ learning_type = learning_style_quiz(*quiz_answers)
174
 
175
+ question_texts = [q for cat in get_to_know_categories.values() for q, _ in cat]
176
+ responses = dict(zip(question_texts, category_answers))
177
 
178
+ profile = {
179
+ "transcript": df.to_dict(orient='records'),
180
+ "transcript_info": transcript_info,
181
+ "learning_style": learning_type,
182
+ "get_to_know_answers": responses,
183
+ "blog": blog_text if blog_checkbox else "[User chose to skip this section]"
184
+ }
185
 
186
+ summary = {
187
+ "Learning_Plan": generate_learning_plan(transcript_info),
188
+ "Style_Summary": generate_learning_style_summary(learning_type),
189
+ "Motivation": generate_motivation_section(responses)
190
+ }
191
 
192
+ with open("student_profile.json", "w") as f:
193
+ json.dump(profile, f, indent=4)
194
 
195
+ with open("student_summary.md", "w") as f:
196
+ f.write(summary["Learning_Plan"] + '\n' + summary["Style_Summary"] + '\n' + summary["Motivation"])
197
 
198
+ return f"โœ… Profile saved! Your learning style is: {learning_type}"
199
+
200
+ except Exception as e:
201
+ return f"โŒ Error: {str(e)}"
202
 
203
+ # Build Gradio UI
204
  with gr.Blocks() as demo:
205
  gr.Markdown("## ๐ŸŽ“ Personalized AI Student Assistant")
206
 
 
224
 
225
  blog_checkbox = gr.Checkbox(label="๐Ÿ“ I'd like to write a mini blog about myself")
226
  blog_text = gr.Textbox(lines=5, label="โœ๏ธ Mini Blog", visible=False)
227
+
228
  blog_checkbox.change(fn=lambda x: gr.update(visible=x), inputs=blog_checkbox, outputs=blog_text)
229
 
230
  submit = gr.Button("๐Ÿ—•๏ธ Save My Profile")
231
+ output = gr.Textbox(label="Status")
 
232
 
233
  submit.click(fn=save_profile,
234
  inputs=[file, *quiz_components, blog_checkbox, blog_text, *category_inputs],
235
+ outputs=[output])
236
 
237
  if __name__ == '__main__':
238
+ demo.launch()