Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -118,12 +118,13 @@ class UniversalTranscriptParser:
|
|
118 |
gpa_data = {}
|
119 |
gpa_match = re.search(r'Cum\. GPA\s*\|\s*([\d\.]+)', text)
|
120 |
if gpa_match:
|
121 |
-
|
122 |
-
gpa_data['
|
|
|
123 |
|
124 |
return {
|
125 |
'student_info': student_info,
|
126 |
-
'courses': {'All': courses},
|
127 |
'gpa': gpa_data,
|
128 |
'grade_level': current_grade.replace('th Grade', '') if current_grade else "Unknown"
|
129 |
}
|
@@ -234,8 +235,8 @@ class UniversalTranscriptParser:
|
|
234 |
|
235 |
# Extract GPA information
|
236 |
gpa_data = {
|
237 |
-
'weighted':
|
238 |
-
'unweighted':
|
239 |
}
|
240 |
|
241 |
# Extract current grade level
|
@@ -248,6 +249,12 @@ class UniversalTranscriptParser:
|
|
248 |
'grade_level': grade_level
|
249 |
}
|
250 |
|
|
|
|
|
|
|
|
|
|
|
|
|
251 |
def _compile_miami_dade_patterns(self):
|
252 |
return {
|
253 |
'student': re.compile(r'Current Grade:\s*(\d+).*YOG\s*(\d{4})'),
|
@@ -274,11 +281,6 @@ class UniversalTranscriptParser:
|
|
274 |
)
|
275 |
}
|
276 |
|
277 |
-
def extract_gpa(text, gpa_type):
|
278 |
-
pattern = rf'{gpa_type}\s*([\d\.]+)'
|
279 |
-
match = re.search(pattern, text)
|
280 |
-
return match.group(1) if match else "N/A"
|
281 |
-
|
282 |
def parse_transcript(file):
|
283 |
parser = UniversalTranscriptParser()
|
284 |
|
@@ -290,11 +292,15 @@ def parse_transcript(file):
|
|
290 |
|
291 |
parsed_data = parser.parse_transcript(text)
|
292 |
|
293 |
-
#
|
294 |
-
|
295 |
-
|
296 |
-
|
297 |
-
|
|
|
|
|
|
|
|
|
298 |
|
299 |
return output_text, parsed_data
|
300 |
else:
|
@@ -449,18 +455,23 @@ def save_profile(name, age, interests, transcript, learning_style,
|
|
449 |
with open(json_path, "w") as f:
|
450 |
json.dump(data, f, indent=2)
|
451 |
|
|
|
|
|
452 |
markdown_summary = f"""### Student Profile: {name}
|
453 |
**Age:** {age}
|
454 |
**Interests:** {interests}
|
455 |
**Learning Style:** {learning_style}
|
|
|
456 |
#### GPA Information:
|
457 |
-
- Weighted: {
|
458 |
-
- Unweighted: {
|
|
|
459 |
#### Favorites:
|
460 |
- Movie: {favorites['movie']} ({favorites['movie_reason']})
|
461 |
- Show: {favorites['show']} ({favorites['show_reason']})
|
462 |
- Book: {favorites['book']} ({favorites['book_reason']})
|
463 |
- Character: {favorites['character']} ({favorites['character_reason']})
|
|
|
464 |
#### Blog:
|
465 |
{blog if blog else "_No blog provided_"}
|
466 |
"""
|
@@ -498,16 +509,29 @@ def generate_response(message, history):
|
|
498 |
# Common responses
|
499 |
greetings = ["hi", "hello", "hey"]
|
500 |
study_help = ["study", "learn", "prepare", "exam"]
|
501 |
-
grade_help = ["gpa", "grade
|
502 |
course_help = ["courses", "classes", "subjects"]
|
503 |
|
504 |
if any(greet in message.lower() for greet in greetings):
|
505 |
return f"Hello {profile.get('name', 'there')}! How can I help you today?"
|
506 |
|
507 |
elif any(word in message.lower() for word in grade_help):
|
508 |
-
|
509 |
-
|
510 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
511 |
|
512 |
elif any(word in message.lower() for word in study_help):
|
513 |
# Analyze course performance to give personalized advice
|
@@ -631,5 +655,4 @@ with gr.Blocks() as app:
|
|
631 |
|
632 |
if __name__ == "__main__":
|
633 |
app.launch()
|
634 |
-
|
635 |
|
|
|
118 |
gpa_data = {}
|
119 |
gpa_match = re.search(r'Cum\. GPA\s*\|\s*([\d\.]+)', text)
|
120 |
if gpa_match:
|
121 |
+
gpa_value = gpa_match.group(1)
|
122 |
+
gpa_data['unweighted'] = gpa_value
|
123 |
+
gpa_data['weighted'] = gpa_value # Homeschool often has same weighted/unweighted
|
124 |
|
125 |
return {
|
126 |
'student_info': student_info,
|
127 |
+
'courses': {'All': courses},
|
128 |
'gpa': gpa_data,
|
129 |
'grade_level': current_grade.replace('th Grade', '') if current_grade else "Unknown"
|
130 |
}
|
|
|
235 |
|
236 |
# Extract GPA information
|
237 |
gpa_data = {
|
238 |
+
'weighted': self._extract_gpa(text, 'Weighted GPA'),
|
239 |
+
'unweighted': self._extract_gpa(text, 'Un-weighted GPA')
|
240 |
}
|
241 |
|
242 |
# Extract current grade level
|
|
|
249 |
'grade_level': grade_level
|
250 |
}
|
251 |
|
252 |
+
def _extract_gpa(self, text: str, gpa_type: str) -> str:
|
253 |
+
"""Helper method to extract GPA values"""
|
254 |
+
pattern = rf'{gpa_type}\s*([\d\.]+)'
|
255 |
+
match = re.search(pattern, text)
|
256 |
+
return match.group(1) if match else "Not Available"
|
257 |
+
|
258 |
def _compile_miami_dade_patterns(self):
|
259 |
return {
|
260 |
'student': re.compile(r'Current Grade:\s*(\d+).*YOG\s*(\d{4})'),
|
|
|
281 |
)
|
282 |
}
|
283 |
|
|
|
|
|
|
|
|
|
|
|
284 |
def parse_transcript(file):
|
285 |
parser = UniversalTranscriptParser()
|
286 |
|
|
|
292 |
|
293 |
parsed_data = parser.parse_transcript(text)
|
294 |
|
295 |
+
# Create clear GPA output
|
296 |
+
gpa_data = parsed_data.get('gpa', {})
|
297 |
+
weighted_gpa = gpa_data.get('weighted', 'Not Available')
|
298 |
+
unweighted_gpa = gpa_data.get('unweighted', 'Not Available')
|
299 |
+
|
300 |
+
output_text = "Transcript Processed Successfully!\n\n"
|
301 |
+
output_text += "GPA Information:\n"
|
302 |
+
output_text += f"- Weighted GPA: {weighted_gpa}\n"
|
303 |
+
output_text += f"- Unweighted GPA: {unweighted_gpa}\n"
|
304 |
|
305 |
return output_text, parsed_data
|
306 |
else:
|
|
|
455 |
with open(json_path, "w") as f:
|
456 |
json.dump(data, f, indent=2)
|
457 |
|
458 |
+
# Create profile summary with clear GPA display
|
459 |
+
gpa = transcript.get('gpa', {})
|
460 |
markdown_summary = f"""### Student Profile: {name}
|
461 |
**Age:** {age}
|
462 |
**Interests:** {interests}
|
463 |
**Learning Style:** {learning_style}
|
464 |
+
|
465 |
#### GPA Information:
|
466 |
+
- Weighted GPA: {gpa.get('weighted', 'Not Available')}
|
467 |
+
- Unweighted GPA: {gpa.get('unweighted', 'Not Available')}
|
468 |
+
|
469 |
#### Favorites:
|
470 |
- Movie: {favorites['movie']} ({favorites['movie_reason']})
|
471 |
- Show: {favorites['show']} ({favorites['show_reason']})
|
472 |
- Book: {favorites['book']} ({favorites['book_reason']})
|
473 |
- Character: {favorites['character']} ({favorites['character_reason']})
|
474 |
+
|
475 |
#### Blog:
|
476 |
{blog if blog else "_No blog provided_"}
|
477 |
"""
|
|
|
509 |
# Common responses
|
510 |
greetings = ["hi", "hello", "hey"]
|
511 |
study_help = ["study", "learn", "prepare", "exam"]
|
512 |
+
grade_help = ["gpa", "grade", "weighted", "unweighted", "grades"]
|
513 |
course_help = ["courses", "classes", "subjects"]
|
514 |
|
515 |
if any(greet in message.lower() for greet in greetings):
|
516 |
return f"Hello {profile.get('name', 'there')}! How can I help you today?"
|
517 |
|
518 |
elif any(word in message.lower() for word in grade_help):
|
519 |
+
response = "Your GPA Information:\n"
|
520 |
+
response += f"- Weighted GPA: {gpa.get('weighted', 'Not Available')}\n"
|
521 |
+
response += f"- Unweighted GPA: {gpa.get('unweighted', 'Not Available')}\n"
|
522 |
+
|
523 |
+
# Add interpretation if available
|
524 |
+
weighted = gpa.get('weighted')
|
525 |
+
if weighted and weighted.replace('.', '').isdigit():
|
526 |
+
weighted_num = float(weighted)
|
527 |
+
if weighted_num >= 3.5:
|
528 |
+
response += "\nExcellent GPA! You're doing great!"
|
529 |
+
elif weighted_num >= 3.0:
|
530 |
+
response += "\nGood GPA! Keep up the good work!"
|
531 |
+
else:
|
532 |
+
response += "\nConsider focusing on improving your grades."
|
533 |
+
|
534 |
+
return response
|
535 |
|
536 |
elif any(word in message.lower() for word in study_help):
|
537 |
# Analyze course performance to give personalized advice
|
|
|
655 |
|
656 |
if __name__ == "__main__":
|
657 |
app.launch()
|
|
|
658 |
|