Dannyar608 commited on
Commit
794a977
·
verified ·
1 Parent(s): f809b13

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +58 -30
app.py CHANGED
@@ -5,7 +5,7 @@ import os
5
  import re
6
  from PyPDF2 import PdfReader
7
 
8
- # ========== TRANSCRIPT PARSING FUNCTIONS ==========
9
 
10
  def parse_transcript(file):
11
  if file.name.endswith('.csv'):
@@ -21,29 +21,62 @@ def parse_transcript(file):
21
  else:
22
  return "Unsupported file format", None
23
 
24
- courses = df['Course'].tolist() if 'Course' in df.columns else []
25
- grades = df['Grade'].tolist() if 'Grade' in df.columns else []
26
- gpa = df['GPA'].mean() if 'GPA' in df.columns else "N/A"
27
-
28
- course_info = "\n".join([f"{c}: {g}" for c, g in zip(courses, grades)])
29
- return f"Transcript Parsed:\n\n{course_info}\n\nGPA: {gpa}", {
30
- "courses": courses,
31
- "grades": grades,
32
- "gpa": gpa
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
33
  }
34
 
35
  def extract_info_from_pdf(text):
36
- course_lines = re.findall(r"([A-Za-z &]+):\s*([A-F][+-]?)", text)
37
- gpa_match = re.search(r"GPA[:\s]+(\d\.\d+)", text)
38
- courses = [course.strip() for course, _ in course_lines]
39
- grades = [grade for _, grade in course_lines]
40
- gpa = float(gpa_match.group(1)) if gpa_match else "N/A"
41
-
42
- course_info = "\n".join([f"{c}: {g}" for c, g in zip(courses, grades)])
43
- return f"Transcript Parsed (PDF):\n\n{course_info}\n\nGPA: {gpa}", {
44
- "courses": courses,
45
- "grades": grades,
46
- "gpa": gpa
 
 
 
 
 
 
 
 
 
 
 
 
 
47
  }
48
 
49
  # ========== LEARNING STYLE QUIZ FUNCTION ==========
@@ -98,7 +131,8 @@ def save_profile(name, age, interests, transcript, learning_style, favorites, bl
98
  def transcript_display(transcript_dict):
99
  if not transcript_dict:
100
  return "No transcript uploaded."
101
- return "\n".join([f"{c}: {g}" for c, g in zip(transcript_dict["courses"], transcript_dict["grades"])] + [f"GPA: {transcript_dict['gpa']}"])
 
102
 
103
  # ========== GRADIO INTERFACE ==========
104
 
@@ -141,7 +175,7 @@ with gr.Blocks() as app:
141
  with gr.Tab("Step 4: Save & Review"):
142
  output_summary = gr.Markdown()
143
  save_btn = gr.Button("Save Profile")
144
-
145
  def gather_and_save(name, age, interests, movie, movie_reason, show, show_reason,
146
  book, book_reason, character, character_reason, blog, transcript, learning_style):
147
  favorites = {
@@ -162,10 +196,4 @@ with gr.Blocks() as app:
162
  transcript_data, learning_output],
163
  outputs=output_summary)
164
 
165
- app.launch()
166
-
167
-
168
-
169
-
170
-
171
-
 
5
  import re
6
  from PyPDF2 import PdfReader
7
 
8
+ # ========== TRANSCRIPT PARSING FUNCTIONS (UPDATED) ==========
9
 
10
  def parse_transcript(file):
11
  if file.name.endswith('.csv'):
 
21
  else:
22
  return "Unsupported file format", None
23
 
24
+ # Extract GPA (try multiple possible column names)
25
+ gpa = "N/A"
26
+ for col in ['GPA', 'Grade Point Average', 'Cumulative GPA']:
27
+ if col in df.columns:
28
+ gpa = df[col].iloc[0] if isinstance(df[col].iloc[0], (float, int)) else "N/A"
29
+ break
30
+
31
+ # Extract grade level (try multiple possible column names)
32
+ grade_level = "N/A"
33
+ for col in ['Grade Level', 'Grade', 'Class', 'Year']:
34
+ if col in df.columns:
35
+ grade_level = df[col].iloc[0]
36
+ break
37
+
38
+ # Extract courses (current and past)
39
+ courses = []
40
+ for col in ['Course', 'Subject', 'Course Name', 'Class']:
41
+ if col in df.columns:
42
+ courses = df[col].tolist()
43
+ break
44
+
45
+ # Create output display
46
+ output_text = f"Grade Level: {grade_level}\nGPA: {gpa}\n\nCourses:\n"
47
+ output_text += "\n".join(f"- {course}" for course in courses)
48
+
49
+ return output_text, {
50
+ "gpa": gpa,
51
+ "grade_level": grade_level,
52
+ "courses": courses
53
  }
54
 
55
  def extract_info_from_pdf(text):
56
+ # Extract GPA
57
+ gpa_match = re.search(r"(GPA|Grade Point Average)[:\s]+(\d\.\d+)", text, re.IGNORECASE)
58
+ gpa = float(gpa_match.group(2)) if gpa_match else "N/A"
59
+
60
+ # Extract grade level
61
+ grade_match = re.search(r"(Grade|Year)[:\s]+(\d+|Freshman|Sophomore|Junior|Senior)", text, re.IGNORECASE)
62
+ grade_level = grade_match.group(2) if grade_match else "N/A"
63
+
64
+ # Extract courses - improved pattern to catch more course formats
65
+ course_pattern = r"""
66
+ (?:[A-Z]{2,}\s?\d{3}) # Course codes like 'MATH 101' or 'ENG101'
67
+ |[A-Z][a-z]+(?:\s[A-Z][a-z]+)* # Or full course names
68
+ """
69
+ courses = re.findall(course_pattern, text, re.VERBOSE)
70
+ courses = list(set(courses)) # Remove duplicates
71
+
72
+ # Create output display
73
+ output_text = f"Grade Level: {grade_level}\nGPA: {gpa}\n\nCourses:\n"
74
+ output_text += "\n".join(f"- {course}" for course in courses)
75
+
76
+ return output_text, {
77
+ "gpa": gpa,
78
+ "grade_level": grade_level,
79
+ "courses": courses
80
  }
81
 
82
  # ========== LEARNING STYLE QUIZ FUNCTION ==========
 
131
  def transcript_display(transcript_dict):
132
  if not transcript_dict:
133
  return "No transcript uploaded."
134
+ return "\n".join([f"- {course}" for course in transcript_dict["courses"]] +
135
+ [f"Grade Level: {transcript_dict['grade_level']}", f"GPA: {transcript_dict['gpa']}"])
136
 
137
  # ========== GRADIO INTERFACE ==========
138
 
 
175
  with gr.Tab("Step 4: Save & Review"):
176
  output_summary = gr.Markdown()
177
  save_btn = gr.Button("Save Profile")
178
+
179
  def gather_and_save(name, age, interests, movie, movie_reason, show, show_reason,
180
  book, book_reason, character, character_reason, blog, transcript, learning_style):
181
  favorites = {
 
196
  transcript_data, learning_output],
197
  outputs=output_summary)
198
 
199
+ app.launch()