Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -291,11 +291,17 @@ def parse_transcript(file):
|
|
| 291 |
if 'courses' in parsed_data:
|
| 292 |
courses_by_grade = parsed_data['courses']
|
| 293 |
|
| 294 |
-
#
|
| 295 |
-
|
| 296 |
-
|
| 297 |
-
|
| 298 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 299 |
|
| 300 |
for grade in grades_sorted:
|
| 301 |
output_text += f"\nGrade {grade}:\n{'-'*30}\n"
|
|
@@ -313,6 +319,46 @@ def parse_transcript(file):
|
|
| 313 |
else:
|
| 314 |
return "Unsupported file format (PDF only for transcript parsing)", None
|
| 315 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 316 |
# ========== LEARNING STYLE QUIZ ==========
|
| 317 |
learning_style_questions = [
|
| 318 |
"When you study for a test, you prefer to:",
|
|
@@ -479,40 +525,6 @@ def save_profile(name, age, interests, transcript, learning_style,
|
|
| 479 |
"""
|
| 480 |
return markdown_summary
|
| 481 |
|
| 482 |
-
def transcript_display(transcript_dict):
|
| 483 |
-
if not transcript_dict or "courses" not in transcript_dict:
|
| 484 |
-
return "No course information available"
|
| 485 |
-
|
| 486 |
-
display = "### Detailed Course History\n"
|
| 487 |
-
courses_by_grade = transcript_dict["courses"]
|
| 488 |
-
|
| 489 |
-
if isinstance(courses_by_grade, dict):
|
| 490 |
-
# Sort grades numerically
|
| 491 |
-
try:
|
| 492 |
-
grades_sorted = sorted(courses_by_grade.keys(), key=int)
|
| 493 |
-
except:
|
| 494 |
-
grades_sorted = sorted(courses_by_grade.keys())
|
| 495 |
-
|
| 496 |
-
for grade in grades_sorted:
|
| 497 |
-
display += f"\n**Grade {grade}**\n"
|
| 498 |
-
for course in courses_by_grade[grade]:
|
| 499 |
-
display += f"- {course.get('name', 'Unnamed Course')}"
|
| 500 |
-
if 'grade' in course and course['grade']:
|
| 501 |
-
display += f" (Grade: {course['grade']})"
|
| 502 |
-
if 'credits' in course:
|
| 503 |
-
display += f" | Credits: {course['credits']}"
|
| 504 |
-
if 'school_year' in course:
|
| 505 |
-
display += f" | Year: {course['school_year']}"
|
| 506 |
-
display += "\n"
|
| 507 |
-
|
| 508 |
-
if 'gpa' in transcript_dict:
|
| 509 |
-
gpa = transcript_dict['gpa']
|
| 510 |
-
display += "\n**GPA Information**\n"
|
| 511 |
-
display += f"- Unweighted: {gpa.get('unweighted', 'N/A')}\n"
|
| 512 |
-
display += f"- Weighted: {gpa.get('weighted', 'N/A')}\n"
|
| 513 |
-
|
| 514 |
-
return display
|
| 515 |
-
|
| 516 |
# ========== AI TEACHING ASSISTANT ==========
|
| 517 |
def load_profile():
|
| 518 |
if not os.path.exists("student_profiles"):
|
|
@@ -592,11 +604,16 @@ def generate_response(message, history):
|
|
| 592 |
elif any(word in message.lower() for word in course_help):
|
| 593 |
response = "Here's a summary of your courses:\n"
|
| 594 |
if isinstance(courses, dict):
|
| 595 |
-
|
| 596 |
-
|
| 597 |
-
|
| 598 |
-
|
| 599 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 600 |
for grade in grades_sorted:
|
| 601 |
response += f"\nGrade {grade}:\n"
|
| 602 |
for course in courses[grade]:
|
|
@@ -687,5 +704,4 @@ with gr.Blocks() as app:
|
|
| 687 |
)
|
| 688 |
|
| 689 |
if __name__ == "__main__":
|
| 690 |
-
app.launch()
|
| 691 |
-
|
|
|
|
| 291 |
if 'courses' in parsed_data:
|
| 292 |
courses_by_grade = parsed_data['courses']
|
| 293 |
|
| 294 |
+
# Improved grade sorting that handles both numeric and text grades
|
| 295 |
+
def grade_sort_key(grade):
|
| 296 |
+
try:
|
| 297 |
+
# Extract numeric part from strings like "9th Grade" or "Grade 9"
|
| 298 |
+
num = int(re.search(r'\d+', grade).group())
|
| 299 |
+
return num
|
| 300 |
+
except (AttributeError, ValueError):
|
| 301 |
+
# For non-numeric grades like "All", sort them last
|
| 302 |
+
return float('inf')
|
| 303 |
+
|
| 304 |
+
grades_sorted = sorted(courses_by_grade.keys(), key=grade_sort_key)
|
| 305 |
|
| 306 |
for grade in grades_sorted:
|
| 307 |
output_text += f"\nGrade {grade}:\n{'-'*30}\n"
|
|
|
|
| 319 |
else:
|
| 320 |
return "Unsupported file format (PDF only for transcript parsing)", None
|
| 321 |
|
| 322 |
+
def transcript_display(transcript_dict):
|
| 323 |
+
if not transcript_dict or "courses" not in transcript_dict:
|
| 324 |
+
return "No course information available"
|
| 325 |
+
|
| 326 |
+
display = "### Detailed Course History\n"
|
| 327 |
+
courses_by_grade = transcript_dict["courses"]
|
| 328 |
+
|
| 329 |
+
if isinstance(courses_by_grade, dict):
|
| 330 |
+
# Improved grade sorting that handles both numeric and text grades
|
| 331 |
+
def grade_sort_key(grade):
|
| 332 |
+
try:
|
| 333 |
+
# Extract numeric part from strings like "9th Grade" or "Grade 9"
|
| 334 |
+
num = int(re.search(r'\d+', grade).group())
|
| 335 |
+
return num
|
| 336 |
+
except (AttributeError, ValueError):
|
| 337 |
+
# For non-numeric grades like "All", sort them last
|
| 338 |
+
return float('inf')
|
| 339 |
+
|
| 340 |
+
grades_sorted = sorted(courses_by_grade.keys(), key=grade_sort_key)
|
| 341 |
+
|
| 342 |
+
for grade in grades_sorted:
|
| 343 |
+
display += f"\n**Grade {grade}**\n"
|
| 344 |
+
for course in courses_by_grade[grade]:
|
| 345 |
+
display += f"- {course.get('name', 'Unnamed Course')}"
|
| 346 |
+
if 'grade' in course and course['grade']:
|
| 347 |
+
display += f" (Grade: {course['grade']})"
|
| 348 |
+
if 'credits' in course:
|
| 349 |
+
display += f" | Credits: {course['credits']}"
|
| 350 |
+
if 'school_year' in course:
|
| 351 |
+
display += f" | Year: {course['school_year']}"
|
| 352 |
+
display += "\n"
|
| 353 |
+
|
| 354 |
+
if 'gpa' in transcript_dict:
|
| 355 |
+
gpa = transcript_dict['gpa']
|
| 356 |
+
display += "\n**GPA Information**\n"
|
| 357 |
+
display += f"- Unweighted: {gpa.get('unweighted', 'N/A')}\n"
|
| 358 |
+
display += f"- Weighted: {gpa.get('weighted', 'N/A')}\n"
|
| 359 |
+
|
| 360 |
+
return display
|
| 361 |
+
|
| 362 |
# ========== LEARNING STYLE QUIZ ==========
|
| 363 |
learning_style_questions = [
|
| 364 |
"When you study for a test, you prefer to:",
|
|
|
|
| 525 |
"""
|
| 526 |
return markdown_summary
|
| 527 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 528 |
# ========== AI TEACHING ASSISTANT ==========
|
| 529 |
def load_profile():
|
| 530 |
if not os.path.exists("student_profiles"):
|
|
|
|
| 604 |
elif any(word in message.lower() for word in course_help):
|
| 605 |
response = "Here's a summary of your courses:\n"
|
| 606 |
if isinstance(courses, dict):
|
| 607 |
+
# Use the same grade sorting logic as in transcript display
|
| 608 |
+
def grade_sort_key(grade):
|
| 609 |
+
try:
|
| 610 |
+
num = int(re.search(r'\d+', grade).group())
|
| 611 |
+
return num
|
| 612 |
+
except (AttributeError, ValueError):
|
| 613 |
+
return float('inf')
|
| 614 |
+
|
| 615 |
+
grades_sorted = sorted(courses.keys(), key=grade_sort_key)
|
| 616 |
+
|
| 617 |
for grade in grades_sorted:
|
| 618 |
response += f"\nGrade {grade}:\n"
|
| 619 |
for course in courses[grade]:
|
|
|
|
| 704 |
)
|
| 705 |
|
| 706 |
if __name__ == "__main__":
|
| 707 |
+
app.launch()
|
|
|