Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -14,7 +14,7 @@ except Exception as e:
|
|
14 |
print(f"Could not load NER model: {e}")
|
15 |
ner_pipeline = None
|
16 |
|
17 |
-
# ========== TRANSCRIPT PARSING
|
18 |
def extract_gpa(text, gpa_type):
|
19 |
pattern = rf'{gpa_type}\s*([\d\.]+)'
|
20 |
match = re.search(pattern, text)
|
@@ -42,6 +42,8 @@ def extract_courses_from_table(text):
|
|
42 |
course_name = course_name.strip()
|
43 |
if 'DE:' in course_name:
|
44 |
course_name = course_name.replace('DE:', 'Dual Enrollment:')
|
|
|
|
|
45 |
|
46 |
course_info = {
|
47 |
'name': f"{course_code} {course_name}",
|
@@ -76,19 +78,23 @@ def parse_transcript(file):
|
|
76 |
# Extract all courses with grades and year taken
|
77 |
courses_by_grade = extract_courses_from_table(text)
|
78 |
|
79 |
-
# Prepare output
|
80 |
-
output_text = f"
|
|
|
81 |
output_text += f"Weighted GPA: {gpa_data['weighted']}\n"
|
82 |
output_text += f"Unweighted GPA: {gpa_data['unweighted']}\n\n"
|
83 |
-
output_text += "Course History:\n"
|
84 |
|
85 |
-
|
86 |
-
|
87 |
-
|
|
|
88 |
output_text += f"- {course['name']}"
|
89 |
-
if 'grade' in course:
|
90 |
output_text += f" (Grade: {course['grade']})"
|
91 |
-
|
|
|
|
|
92 |
|
93 |
return output_text, {
|
94 |
"gpa": gpa_data,
|
@@ -268,18 +274,20 @@ def transcript_display(transcript_dict):
|
|
268 |
if not transcript_dict or "courses" not in transcript_dict:
|
269 |
return "No course information available"
|
270 |
|
271 |
-
display = "### Course History\n
|
272 |
courses_by_grade = transcript_dict["courses"]
|
273 |
|
274 |
if isinstance(courses_by_grade, dict):
|
275 |
-
|
276 |
-
|
277 |
-
|
|
|
278 |
display += f"- {course['name']}"
|
279 |
-
if 'grade' in course:
|
280 |
display += f" (Grade: {course['grade']})"
|
281 |
-
|
282 |
-
|
|
|
283 |
|
284 |
if 'gpa' in transcript_dict:
|
285 |
gpa = transcript_dict['gpa']
|
@@ -309,12 +317,14 @@ def generate_response(message, history):
|
|
309 |
grade_level = profile.get("transcript", {}).get("grade_level", "unknown")
|
310 |
gpa = profile.get("transcript", {}).get("gpa", {})
|
311 |
interests = profile.get("interests", "")
|
|
|
312 |
|
313 |
# Common responses
|
314 |
greetings = ["hi", "hello", "hey"]
|
315 |
study_help = ["study", "learn", "prepare", "exam"]
|
316 |
grade_help = ["grade", "gpa", "score"]
|
317 |
interest_help = ["interest", "hobby", "passion"]
|
|
|
318 |
|
319 |
if any(greet in message.lower() for greet in greetings):
|
320 |
return f"Hello {profile.get('name', 'there')}! How can I help you today?"
|
@@ -363,10 +373,22 @@ def generate_response(message, history):
|
|
363 |
"- Find clubs or activities related to these interests\n"
|
364 |
"- Explore career paths that align with them")
|
365 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
366 |
elif "help" in message.lower():
|
367 |
return ("I can help with:\n"
|
368 |
"- Study tips based on your learning style\n"
|
369 |
"- GPA and grade information\n"
|
|
|
370 |
"- General academic advice\n\n"
|
371 |
"Try asking about study strategies or your grades!")
|
372 |
|
@@ -380,7 +402,7 @@ with gr.Blocks() as app:
|
|
380 |
with gr.Tab("Step 1: Upload Transcript"):
|
381 |
gr.Markdown("### Upload your transcript (PDF recommended for best results)")
|
382 |
transcript_file = gr.File(label="Transcript file", file_types=[".pdf"])
|
383 |
-
transcript_output = gr.Textbox(label="Transcript Results", lines=
|
384 |
transcript_data = gr.State()
|
385 |
transcript_file.change(
|
386 |
fn=parse_transcript,
|
@@ -394,7 +416,7 @@ with gr.Blocks() as app:
|
|
394 |
for i, (question, options) in enumerate(zip(learning_style_questions, learning_style_options)):
|
395 |
quiz_components.append(gr.Radio(options, label=f"{i+1}. {question}"))
|
396 |
|
397 |
-
learning_output = gr.Textbox(label="Your Learning Style", lines=
|
398 |
gr.Button("Submit Quiz").click(
|
399 |
fn=learning_style_quiz,
|
400 |
inputs=quiz_components,
|
@@ -435,11 +457,11 @@ with gr.Blocks() as app:
|
|
435 |
examples=[
|
436 |
"How should I study for my next test?",
|
437 |
"What's my GPA information?",
|
438 |
-
"
|
439 |
"How can I improve my grades?"
|
440 |
]
|
441 |
)
|
442 |
|
443 |
if __name__ == "__main__":
|
444 |
app.launch()
|
445 |
-
|
|
|
14 |
print(f"Could not load NER model: {e}")
|
15 |
ner_pipeline = None
|
16 |
|
17 |
+
# ========== IMPROVED TRANSCRIPT PARSING ==========
|
18 |
def extract_gpa(text, gpa_type):
|
19 |
pattern = rf'{gpa_type}\s*([\d\.]+)'
|
20 |
match = re.search(pattern, text)
|
|
|
42 |
course_name = course_name.strip()
|
43 |
if 'DE:' in course_name:
|
44 |
course_name = course_name.replace('DE:', 'Dual Enrollment:')
|
45 |
+
if 'AP' in course_name:
|
46 |
+
course_name = course_name.replace('AP', 'AP ')
|
47 |
|
48 |
course_info = {
|
49 |
'name': f"{course_code} {course_name}",
|
|
|
78 |
# Extract all courses with grades and year taken
|
79 |
courses_by_grade = extract_courses_from_table(text)
|
80 |
|
81 |
+
# Prepare detailed output
|
82 |
+
output_text = f"Student Transcript Summary\n{'='*40}\n"
|
83 |
+
output_text += f"Current Grade Level: {grade_level}\n"
|
84 |
output_text += f"Weighted GPA: {gpa_data['weighted']}\n"
|
85 |
output_text += f"Unweighted GPA: {gpa_data['unweighted']}\n\n"
|
86 |
+
output_text += "Course History:\n{'='*40}\n"
|
87 |
|
88 |
+
# Sort grades numerically (09, 10, 11, 12)
|
89 |
+
for grade in sorted(courses_by_grade.keys(), key=int):
|
90 |
+
output_text += f"\nGrade {grade}:\n{'-'*30}\n"
|
91 |
+
for course in courses_by_grade[grade]:
|
92 |
output_text += f"- {course['name']}"
|
93 |
+
if 'grade' in course and course['grade']:
|
94 |
output_text += f" (Grade: {course['grade']})"
|
95 |
+
if 'credits' in course:
|
96 |
+
output_text += f" | Credits: {course['credits']}"
|
97 |
+
output_text += f" | Year: {course['year']}\n"
|
98 |
|
99 |
return output_text, {
|
100 |
"gpa": gpa_data,
|
|
|
274 |
if not transcript_dict or "courses" not in transcript_dict:
|
275 |
return "No course information available"
|
276 |
|
277 |
+
display = "### Detailed Course History\n"
|
278 |
courses_by_grade = transcript_dict["courses"]
|
279 |
|
280 |
if isinstance(courses_by_grade, dict):
|
281 |
+
# Sort grades numerically
|
282 |
+
for grade in sorted(courses_by_grade.keys(), key=int):
|
283 |
+
display += f"\n**Grade {grade}**\n"
|
284 |
+
for course in courses_by_grade[grade]:
|
285 |
display += f"- {course['name']}"
|
286 |
+
if 'grade' in course and course['grade']:
|
287 |
display += f" (Grade: {course['grade']})"
|
288 |
+
if 'credits' in course:
|
289 |
+
display += f" | Credits: {course['credits']}"
|
290 |
+
display += f" | Year: {course['year']}\n"
|
291 |
|
292 |
if 'gpa' in transcript_dict:
|
293 |
gpa = transcript_dict['gpa']
|
|
|
317 |
grade_level = profile.get("transcript", {}).get("grade_level", "unknown")
|
318 |
gpa = profile.get("transcript", {}).get("gpa", {})
|
319 |
interests = profile.get("interests", "")
|
320 |
+
courses = profile.get("transcript", {}).get("courses", {})
|
321 |
|
322 |
# Common responses
|
323 |
greetings = ["hi", "hello", "hey"]
|
324 |
study_help = ["study", "learn", "prepare", "exam"]
|
325 |
grade_help = ["grade", "gpa", "score"]
|
326 |
interest_help = ["interest", "hobby", "passion"]
|
327 |
+
course_help = ["courses", "classes", "transcript", "schedule"]
|
328 |
|
329 |
if any(greet in message.lower() for greet in greetings):
|
330 |
return f"Hello {profile.get('name', 'there')}! How can I help you today?"
|
|
|
373 |
"- Find clubs or activities related to these interests\n"
|
374 |
"- Explore career paths that align with them")
|
375 |
|
376 |
+
elif any(word in message.lower() for word in course_help):
|
377 |
+
response = "Here's a summary of your courses:\n"
|
378 |
+
for grade in sorted(courses.keys(), key=int):
|
379 |
+
response += f"\nGrade {grade}:\n"
|
380 |
+
for course in courses[grade]:
|
381 |
+
response += f"- {course['name']}"
|
382 |
+
if 'grade' in course:
|
383 |
+
response += f" (Grade: {course['grade']})"
|
384 |
+
response += "\n"
|
385 |
+
return response
|
386 |
+
|
387 |
elif "help" in message.lower():
|
388 |
return ("I can help with:\n"
|
389 |
"- Study tips based on your learning style\n"
|
390 |
"- GPA and grade information\n"
|
391 |
+
"- Course history and schedules\n"
|
392 |
"- General academic advice\n\n"
|
393 |
"Try asking about study strategies or your grades!")
|
394 |
|
|
|
402 |
with gr.Tab("Step 1: Upload Transcript"):
|
403 |
gr.Markdown("### Upload your transcript (PDF recommended for best results)")
|
404 |
transcript_file = gr.File(label="Transcript file", file_types=[".pdf"])
|
405 |
+
transcript_output = gr.Textbox(label="Transcript Results", lines=20)
|
406 |
transcript_data = gr.State()
|
407 |
transcript_file.change(
|
408 |
fn=parse_transcript,
|
|
|
416 |
for i, (question, options) in enumerate(zip(learning_style_questions, learning_style_options)):
|
417 |
quiz_components.append(gr.Radio(options, label=f"{i+1}. {question}"))
|
418 |
|
419 |
+
learning_output = gr.Textbox(label="Your Learning Style", lines=15)
|
420 |
gr.Button("Submit Quiz").click(
|
421 |
fn=learning_style_quiz,
|
422 |
inputs=quiz_components,
|
|
|
457 |
examples=[
|
458 |
"How should I study for my next test?",
|
459 |
"What's my GPA information?",
|
460 |
+
"Show me my course history",
|
461 |
"How can I improve my grades?"
|
462 |
]
|
463 |
)
|
464 |
|
465 |
if __name__ == "__main__":
|
466 |
app.launch()
|
467 |
+
|