Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,25 +1,144 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
# ========== LEARNING STYLE QUIZ ==========
|
| 2 |
learning_style_questions = [
|
| 3 |
"When you study for a test, you prefer to:",
|
| 4 |
"When you need directions to a new place, you prefer:",
|
| 5 |
"When you learn a new skill, you prefer to:",
|
| 6 |
"When you're trying to concentrate, you:",
|
| 7 |
-
"When you meet new people, you remember them by:"
|
| 8 |
-
"When you're assembling furniture or a gadget, you:",
|
| 9 |
-
"When choosing a restaurant, you rely most on:",
|
| 10 |
-
"When you're in a waiting room, you typically:",
|
| 11 |
-
"When giving someone instructions, you tend to:",
|
| 12 |
-
"When you're trying to recall information, you:",
|
| 13 |
-
"When you're at a museum or exhibit, you:",
|
| 14 |
-
"When you're learning a new language, you prefer:",
|
| 15 |
-
"When you're taking notes in class, you:",
|
| 16 |
-
"When you're explaining something complex, you:",
|
| 17 |
-
"When you're at a party, you enjoy:",
|
| 18 |
-
"When you're trying to remember a phone number, you:",
|
| 19 |
-
"When you're relaxing, you prefer to:",
|
| 20 |
-
"When you're learning to use new software, you:",
|
| 21 |
-
"When you're giving a presentation, you rely on:",
|
| 22 |
-
"When you're solving a difficult problem, you:"
|
| 23 |
]
|
| 24 |
|
| 25 |
learning_style_options = [
|
|
@@ -27,22 +146,7 @@ learning_style_options = [
|
|
| 27 |
["Look at a map (Visual)", "Have someone tell you (Auditory)", "Write down directions (Reading/Writing)", "Try walking/driving there (Kinesthetic)"],
|
| 28 |
["Read instructions (Reading/Writing)", "Have someone show you (Visual)", "Listen to explanations (Auditory)", "Try it yourself (Kinesthetic)"],
|
| 29 |
["Need quiet (Reading/Writing)", "Need background noise (Auditory)", "Need to move around (Kinesthetic)", "Need visual stimulation (Visual)"],
|
| 30 |
-
["Their face (Visual)", "Their name (Auditory)", "What you talked about (Reading/Writing)", "What you did together (Kinesthetic)"]
|
| 31 |
-
["Read the instructions carefully (Reading/Writing)", "Look at the diagrams (Visual)", "Ask someone to explain (Auditory)", "Start putting pieces together (Kinesthetic)"],
|
| 32 |
-
["Online photos of the food (Visual)", "Recommendations from friends (Auditory)", "Reading the menu online (Reading/Writing)", "Remembering how it felt to eat there (Kinesthetic)"],
|
| 33 |
-
["Read magazines (Reading/Writing)", "Listen to music (Auditory)", "Watch TV (Visual)", "Fidget or move around (Kinesthetic)"],
|
| 34 |
-
["Write them down (Reading/Writing)", "Explain verbally (Auditory)", "Demonstrate (Visual)", "Guide them physically (Kinesthetic)"],
|
| 35 |
-
["See written words in your mind (Visual)", "Hear the information in your head (Auditory)", "Write it down to remember (Reading/Writing)", "Associate it with physical actions (Kinesthetic)"],
|
| 36 |
-
["Read all the descriptions (Reading/Writing)", "Listen to audio guides (Auditory)", "Look at the displays (Visual)", "Touch interactive exhibits (Kinesthetic)"],
|
| 37 |
-
["Study grammar rules (Reading/Writing)", "Listen to native speakers (Auditory)", "Use flashcards with images (Visual)", "Practice conversations (Kinesthetic)"],
|
| 38 |
-
["Write detailed paragraphs (Reading/Writing)", "Record the lecture (Auditory)", "Draw diagrams and charts (Visual)", "Doodle while listening (Kinesthetic)"],
|
| 39 |
-
["Write detailed steps (Reading/Writing)", "Explain verbally with examples (Auditory)", "Draw diagrams (Visual)", "Use physical objects to demonstrate (Kinesthetic)"],
|
| 40 |
-
["Conversations with people (Auditory)", "Watching others or the environment (Visual)", "Writing notes or texting (Reading/Writing)", "Dancing or physical activities (Kinesthetic)"],
|
| 41 |
-
["See the numbers in your head (Visual)", "Say them aloud (Auditory)", "Write them down (Reading/Writing)", "Dial them on a keypad (Kinesthetic)"],
|
| 42 |
-
["Read a book (Reading/Writing)", "Listen to music (Auditory)", "Watch TV/movies (Visual)", "Do something physical (Kinesthetic)"],
|
| 43 |
-
["Read the manual (Reading/Writing)", "Ask someone to show you (Visual)", "Call tech support (Auditory)", "Experiment with the software (Kinesthetic)"],
|
| 44 |
-
["Detailed notes (Reading/Writing)", "Verbal explanations (Auditory)", "Visual slides (Visual)", "Physical demonstrations (Kinesthetic)"],
|
| 45 |
-
["Write out possible solutions (Reading/Writing)", "Talk through it with someone (Auditory)", "Draw diagrams (Visual)", "Build a model or prototype (Kinesthetic)"]
|
| 46 |
]
|
| 47 |
|
| 48 |
def learning_style_quiz(*answers):
|
|
@@ -64,54 +168,228 @@ def learning_style_quiz(*answers):
|
|
| 64 |
scores["Kinesthetic"] += 1
|
| 65 |
|
| 66 |
max_score = max(scores.values())
|
| 67 |
-
|
| 68 |
|
| 69 |
-
|
| 70 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 71 |
|
| 72 |
-
|
| 73 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 74 |
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 79 |
|
| 80 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 81 |
|
| 82 |
-
#
|
| 83 |
-
|
|
|
|
|
|
|
|
|
|
| 84 |
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
elif
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 115 |
|
| 116 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 117 |
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import pandas as pd
|
| 3 |
+
import json
|
| 4 |
+
import os
|
| 5 |
+
import re
|
| 6 |
+
from PyPDF2 import PdfReader
|
| 7 |
+
from collections import defaultdict
|
| 8 |
+
|
| 9 |
+
# ========== TRANSCRIPT PARSING FUNCTIONS ==========
|
| 10 |
+
def extract_courses_with_grade_levels(text):
|
| 11 |
+
grade_level_pattern = r"(Grade|Year)\s*[:]?\s*(\d+|Freshman|Sophomore|Junior|Senior)"
|
| 12 |
+
grade_match = re.search(grade_level_pattern, text, re.IGNORECASE)
|
| 13 |
+
current_grade_level = grade_match.group(2) if grade_match else "Unknown"
|
| 14 |
+
|
| 15 |
+
course_pattern = r"""
|
| 16 |
+
(?:^|\n)
|
| 17 |
+
(?: (Grade|Year)\s*[:]?\s*(\d+|Freshman|Sophomore|Junior|Senior)\s*[\n-]* )?
|
| 18 |
+
(
|
| 19 |
+
(?:[A-Z]{2,}\s?\d{3})
|
| 20 |
+
|
|
| 21 |
+
[A-Z][a-z]+(?:\s[A-Z][a-z]+)*
|
| 22 |
+
)
|
| 23 |
+
\s*
|
| 24 |
+
(?: [:\-]?\s* ([A-F][+-]?|\d{2,3}%)? )?
|
| 25 |
+
"""
|
| 26 |
+
|
| 27 |
+
courses_by_grade = defaultdict(list)
|
| 28 |
+
current_grade = current_grade_level
|
| 29 |
+
|
| 30 |
+
for match in re.finditer(course_pattern, text, re.VERBOSE | re.MULTILINE):
|
| 31 |
+
grade_context, grade_level, course, grade = match.groups()
|
| 32 |
+
|
| 33 |
+
if grade_context:
|
| 34 |
+
current_grade = grade_level
|
| 35 |
+
|
| 36 |
+
if course:
|
| 37 |
+
course_info = {"course": course.strip()}
|
| 38 |
+
if grade:
|
| 39 |
+
course_info["grade"] = grade.strip()
|
| 40 |
+
courses_by_grade[current_grade].append(course_info)
|
| 41 |
+
|
| 42 |
+
return dict(courses_by_grade)
|
| 43 |
+
|
| 44 |
+
def parse_transcript(file):
|
| 45 |
+
if file.name.endswith('.csv'):
|
| 46 |
+
df = pd.read_csv(file)
|
| 47 |
+
elif file.name.endswith('.xlsx'):
|
| 48 |
+
df = pd.read_excel(file)
|
| 49 |
+
elif file.name.endswith('.pdf'):
|
| 50 |
+
text = ''
|
| 51 |
+
reader = PdfReader(file)
|
| 52 |
+
for page in reader.pages:
|
| 53 |
+
page_text = page.extract_text()
|
| 54 |
+
if page_text:
|
| 55 |
+
text += page_text + '\n'
|
| 56 |
+
|
| 57 |
+
# Grade level extraction
|
| 58 |
+
grade_match = re.search(r'(Grade|Year)[\s:]*(\d+|Freshman|Sophomore|Junior|Senior)', text, re.IGNORECASE)
|
| 59 |
+
grade_level = grade_match.group(2) if grade_match else "Unknown"
|
| 60 |
+
|
| 61 |
+
# Enhanced GPA extraction
|
| 62 |
+
gpa_data = {'weighted': "N/A", 'unweighted': "N/A"}
|
| 63 |
+
gpa_patterns = [
|
| 64 |
+
r'Weighted GPA[\s:]*(\d\.\d{1,2})',
|
| 65 |
+
r'GPA \(Weighted\)[\s:]*(\d\.\d{1,2})',
|
| 66 |
+
r'Cumulative GPA \(Weighted\)[\s:]*(\d\.\d{1,2})',
|
| 67 |
+
r'Unweighted GPA[\s:]*(\d\.\d{1,2})',
|
| 68 |
+
r'GPA \(Unweighted\)[\s:]*(\d\.\d{1,2})',
|
| 69 |
+
r'Cumulative GPA \(Unweighted\)[\s:]*(\d\.\d{1,2})',
|
| 70 |
+
r'GPA[\s:]*(\d\.\d{1,2})'
|
| 71 |
+
]
|
| 72 |
+
for pattern in gpa_patterns:
|
| 73 |
+
for match in re.finditer(pattern, text, re.IGNORECASE):
|
| 74 |
+
gpa_value = match.group(1)
|
| 75 |
+
if 'weighted' in pattern.lower():
|
| 76 |
+
gpa_data['weighted'] = gpa_value
|
| 77 |
+
elif 'unweighted' in pattern.lower():
|
| 78 |
+
gpa_data['unweighted'] = gpa_value
|
| 79 |
+
else:
|
| 80 |
+
if gpa_data['unweighted'] == "N/A":
|
| 81 |
+
gpa_data['unweighted'] = gpa_value
|
| 82 |
+
if gpa_data['weighted'] == "N/A":
|
| 83 |
+
gpa_data['weighted'] = gpa_value
|
| 84 |
+
|
| 85 |
+
courses_by_grade = extract_courses_with_grade_levels(text)
|
| 86 |
+
|
| 87 |
+
output_text = f"Grade Level: {grade_level}\n\n"
|
| 88 |
+
if gpa_data['weighted'] != "N/A" or gpa_data['unweighted'] != "N/A":
|
| 89 |
+
output_text += "GPA Information:\n"
|
| 90 |
+
if gpa_data['unweighted'] != "N/A":
|
| 91 |
+
output_text += f"- Unweighted GPA: {gpa_data['unweighted']}\n"
|
| 92 |
+
if gpa_data['weighted'] != "N/A":
|
| 93 |
+
output_text += f"- Weighted GPA: {gpa_data['weighted']}\n"
|
| 94 |
+
else:
|
| 95 |
+
output_text += "No GPA information found\n"
|
| 96 |
+
|
| 97 |
+
output_text += "\n(Courses not shown here)"
|
| 98 |
+
|
| 99 |
+
return output_text, {
|
| 100 |
+
"gpa": gpa_data,
|
| 101 |
+
"grade_level": grade_level,
|
| 102 |
+
"courses": courses_by_grade
|
| 103 |
+
}
|
| 104 |
+
else:
|
| 105 |
+
return "Unsupported file format", None
|
| 106 |
+
|
| 107 |
+
# For CSV/XLSX fallback
|
| 108 |
+
gpa = "N/A"
|
| 109 |
+
for col in ['GPA', 'Grade Point Average', 'Cumulative GPA']:
|
| 110 |
+
if col in df.columns:
|
| 111 |
+
gpa = df[col].iloc[0] if isinstance(df[col].iloc[0], (float, int)) else "N/A"
|
| 112 |
+
break
|
| 113 |
+
|
| 114 |
+
grade_level = "N/A"
|
| 115 |
+
for col in ['Grade Level', 'Grade', 'Class', 'Year']:
|
| 116 |
+
if col in df.columns:
|
| 117 |
+
grade_level = df[col].iloc[0]
|
| 118 |
+
break
|
| 119 |
+
|
| 120 |
+
courses = []
|
| 121 |
+
for col in ['Course', 'Subject', 'Course Name', 'Class']:
|
| 122 |
+
if col in df.columns:
|
| 123 |
+
courses = df[col].tolist()
|
| 124 |
+
break
|
| 125 |
+
|
| 126 |
+
output_text = f"Grade Level: {grade_level}\nGPA: {gpa}\n\nCourses:\n"
|
| 127 |
+
output_text += "\n".join(f"- {course}" for course in courses)
|
| 128 |
+
|
| 129 |
+
return output_text, {
|
| 130 |
+
"gpa": {"unweighted": gpa, "weighted": "N/A"},
|
| 131 |
+
"grade_level": grade_level,
|
| 132 |
+
"courses": courses
|
| 133 |
+
}
|
| 134 |
+
|
| 135 |
# ========== LEARNING STYLE QUIZ ==========
|
| 136 |
learning_style_questions = [
|
| 137 |
"When you study for a test, you prefer to:",
|
| 138 |
"When you need directions to a new place, you prefer:",
|
| 139 |
"When you learn a new skill, you prefer to:",
|
| 140 |
"When you're trying to concentrate, you:",
|
| 141 |
+
"When you meet new people, you remember them by:"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 142 |
]
|
| 143 |
|
| 144 |
learning_style_options = [
|
|
|
|
| 146 |
["Look at a map (Visual)", "Have someone tell you (Auditory)", "Write down directions (Reading/Writing)", "Try walking/driving there (Kinesthetic)"],
|
| 147 |
["Read instructions (Reading/Writing)", "Have someone show you (Visual)", "Listen to explanations (Auditory)", "Try it yourself (Kinesthetic)"],
|
| 148 |
["Need quiet (Reading/Writing)", "Need background noise (Auditory)", "Need to move around (Kinesthetic)", "Need visual stimulation (Visual)"],
|
| 149 |
+
["Their face (Visual)", "Their name (Auditory)", "What you talked about (Reading/Writing)", "What you did together (Kinesthetic)"]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 150 |
]
|
| 151 |
|
| 152 |
def learning_style_quiz(*answers):
|
|
|
|
| 168 |
scores["Kinesthetic"] += 1
|
| 169 |
|
| 170 |
max_score = max(scores.values())
|
| 171 |
+
dominant_styles = [style for style, score in scores.items() if score == max_score]
|
| 172 |
|
| 173 |
+
if len(dominant_styles) == 1:
|
| 174 |
+
return f"Your primary learning style is: {dominant_styles[0]}"
|
| 175 |
+
else:
|
| 176 |
+
return f"You have multiple strong learning styles: {', '.join(dominant_styles)}"
|
| 177 |
+
|
| 178 |
+
# ========== SAVE STUDENT PROFILE FUNCTION ==========
|
| 179 |
+
def save_profile(name, age, interests, transcript, learning_style, movie, movie_reason, show, show_reason, book, book_reason, character, character_reason, blog):
|
| 180 |
+
# Convert age to int if it's a numpy number (from gradio Number input)
|
| 181 |
+
age = int(age) if age else 0
|
| 182 |
|
| 183 |
+
favorites = {
|
| 184 |
+
"movie": movie,
|
| 185 |
+
"movie_reason": movie_reason,
|
| 186 |
+
"show": show,
|
| 187 |
+
"show_reason": show_reason,
|
| 188 |
+
"book": book,
|
| 189 |
+
"book_reason": book_reason,
|
| 190 |
+
"character": character,
|
| 191 |
+
"character_reason": character_reason
|
| 192 |
+
}
|
| 193 |
|
| 194 |
+
data = {
|
| 195 |
+
"name": name,
|
| 196 |
+
"age": age,
|
| 197 |
+
"interests": interests,
|
| 198 |
+
"transcript": transcript,
|
| 199 |
+
"learning_style": learning_style,
|
| 200 |
+
"favorites": favorites,
|
| 201 |
+
"blog": blog
|
| 202 |
+
}
|
| 203 |
|
| 204 |
+
os.makedirs("student_profiles", exist_ok=True)
|
| 205 |
+
json_path = os.path.join("student_profiles", f"{name.replace(' ', '_')}_profile.json")
|
| 206 |
+
with open(json_path, "w") as f:
|
| 207 |
+
json.dump(data, f, indent=2)
|
| 208 |
+
|
| 209 |
+
markdown_summary = f"""### Student Profile: {name}
|
| 210 |
+
**Age:** {age}
|
| 211 |
+
**Interests:** {interests}
|
| 212 |
+
**Learning Style:** {learning_style}
|
| 213 |
+
#### Transcript:
|
| 214 |
+
{transcript_display(transcript)}
|
| 215 |
+
#### Favorites:
|
| 216 |
+
- Movie: {favorites['movie']} ({favorites['movie_reason']})
|
| 217 |
+
- Show: {favorites['show']} ({favorites['show_reason']})
|
| 218 |
+
- Book: {favorites['book']} ({favorites['book_reason']})
|
| 219 |
+
- Character: {favorites['character']} ({favorites['character_reason']})
|
| 220 |
+
#### Blog:
|
| 221 |
+
{blog if blog else "_No blog provided_"}
|
| 222 |
+
"""
|
| 223 |
+
return markdown_summary
|
| 224 |
+
|
| 225 |
+
def transcript_display(transcript_dict):
|
| 226 |
+
if not transcript_dict:
|
| 227 |
+
return "No transcript uploaded."
|
| 228 |
+
if isinstance(transcript_dict, dict) and "courses" in transcript_dict:
|
| 229 |
+
if isinstance(transcript_dict["courses"], dict):
|
| 230 |
+
display = ""
|
| 231 |
+
for grade_level, courses in transcript_dict["courses"].items():
|
| 232 |
+
display += f"\n**Grade {grade_level}**\n"
|
| 233 |
+
for course in courses:
|
| 234 |
+
display += f"- {course['course']}"
|
| 235 |
+
if 'grade' in course:
|
| 236 |
+
display += f" (Grade: {course['grade']})"
|
| 237 |
+
display += "\n"
|
| 238 |
+
return display
|
| 239 |
+
elif isinstance(transcript_dict["courses"], list):
|
| 240 |
+
return "\n".join([f"- {course}" for course in transcript_dict["courses"]])
|
| 241 |
+
return "No course information available"
|
| 242 |
+
|
| 243 |
+
# ========== AI TEACHING ASSISTANT ==========
|
| 244 |
+
def load_profile():
|
| 245 |
+
if not os.path.exists("student_profiles"):
|
| 246 |
+
return {}
|
| 247 |
+
files = [f for f in os.listdir("student_profiles") if f.endswith('.json')]
|
| 248 |
+
if files:
|
| 249 |
+
with open(os.path.join("student_profiles", files[0]), "r") as f:
|
| 250 |
+
return json.load(f)
|
| 251 |
+
return {}
|
| 252 |
+
|
| 253 |
+
def generate_response(message, history):
|
| 254 |
+
profile = load_profile()
|
| 255 |
+
if not profile:
|
| 256 |
+
return "Please complete and save your profile first using the previous tabs."
|
| 257 |
|
| 258 |
+
# Get profile data
|
| 259 |
+
learning_style = profile.get("learning_style", "")
|
| 260 |
+
grade_level = profile.get("transcript", {}).get("grade_level", "unknown")
|
| 261 |
+
gpa = profile.get("transcript", {}).get("gpa", {})
|
| 262 |
+
interests = profile.get("interests", "")
|
| 263 |
|
| 264 |
+
# Common responses
|
| 265 |
+
greetings = ["hi", "hello", "hey"]
|
| 266 |
+
study_help = ["study", "learn", "prepare", "exam"]
|
| 267 |
+
grade_help = ["grade", "gpa", "score"]
|
| 268 |
+
interest_help = ["interest", "hobby", "passion"]
|
| 269 |
+
|
| 270 |
+
if any(greet in message.lower() for greet in greetings):
|
| 271 |
+
return f"Hello {profile.get('name', 'there')}! How can I help you today?"
|
| 272 |
+
|
| 273 |
+
elif any(word in message.lower() for word in study_help):
|
| 274 |
+
if "Visual" in learning_style:
|
| 275 |
+
response = ("Based on your visual learning style, I recommend:\n"
|
| 276 |
+
"- Creating mind maps or diagrams\n"
|
| 277 |
+
"- Using color-coded notes\n"
|
| 278 |
+
"- Watching educational videos")
|
| 279 |
+
elif "Auditory" in learning_style:
|
| 280 |
+
response = ("Based on your auditory learning style, I recommend:\n"
|
| 281 |
+
"- Recording lectures and listening to them\n"
|
| 282 |
+
"- Participating in study groups\n"
|
| 283 |
+
"- Explaining concepts out loud")
|
| 284 |
+
elif "Reading/Writing" in learning_style:
|
| 285 |
+
response = ("Based on your reading/writing learning style, I recommend:\n"
|
| 286 |
+
"- Writing detailed notes\n"
|
| 287 |
+
"- Creating summaries in your own words\n"
|
| 288 |
+
"- Reading textbooks and articles")
|
| 289 |
+
elif "Kinesthetic" in learning_style:
|
| 290 |
+
response = ("Based on your kinesthetic learning style, I recommend:\n"
|
| 291 |
+
"- Hands-on practice\n"
|
| 292 |
+
"- Creating physical models\n"
|
| 293 |
+
"- Taking frequent movement breaks")
|
| 294 |
+
else:
|
| 295 |
+
response = ("Here are some general study tips:\n"
|
| 296 |
+
"- Break study sessions into 25-minute chunks\n"
|
| 297 |
+
"- Review material regularly\n"
|
| 298 |
+
"- Teach concepts to someone else")
|
| 299 |
+
|
| 300 |
+
return response
|
| 301 |
|
| 302 |
+
elif any(word in message.lower() for word in grade_help):
|
| 303 |
+
return (f"Your GPA information:\n"
|
| 304 |
+
f"- Unweighted: {gpa.get('unweighted', 'N/A')}\n"
|
| 305 |
+
f"- Weighted: {gpa.get('weighted', 'N/A')}\n\n"
|
| 306 |
+
"To improve your grades, try:\n"
|
| 307 |
+
"- Setting specific goals\n"
|
| 308 |
+
"- Meeting with teachers\n"
|
| 309 |
+
"- Developing a study schedule")
|
| 310 |
+
|
| 311 |
+
elif any(word in message.lower() for word in interest_help):
|
| 312 |
+
return (f"I see you're interested in: {interests}\n\n"
|
| 313 |
+
"You might want to:\n"
|
| 314 |
+
"- Find clubs or activities related to these interests\n"
|
| 315 |
+
"- Explore career paths that align with them")
|
| 316 |
+
|
| 317 |
+
elif "help" in message.lower():
|
| 318 |
+
return ("I can help with:\n"
|
| 319 |
+
"- Study tips based on your learning style\n"
|
| 320 |
+
"- GPA and grade information\n"
|
| 321 |
+
"- General academic advice\n\n"
|
| 322 |
+
"Try asking about study strategies or your grades!")
|
| 323 |
+
|
| 324 |
+
else:
|
| 325 |
+
return ("I'm your personalized teaching assistant. "
|
| 326 |
+
"I can help with study tips, grade information, and academic advice. "
|
| 327 |
+
"Try asking about how to study for your classes!")
|
| 328 |
+
|
| 329 |
+
# ========== GRADIO INTERFACE ==========
|
| 330 |
+
with gr.Blocks() as app:
|
| 331 |
+
with gr.Tab("Step 1: Upload Transcript"):
|
| 332 |
+
transcript_file = gr.File(label="Upload your transcript (CSV, Excel, or PDF)")
|
| 333 |
+
transcript_output = gr.Textbox(label="Transcript Output")
|
| 334 |
+
transcript_data = gr.State()
|
| 335 |
+
transcript_file.change(fn=parse_transcript, inputs=transcript_file, outputs=[transcript_output, transcript_data])
|
| 336 |
+
|
| 337 |
+
with gr.Tab("Step 2: Learning Style Quiz"):
|
| 338 |
+
gr.Markdown("### Learning Style Quiz")
|
| 339 |
+
quiz_components = []
|
| 340 |
+
for i, (question, options) in enumerate(zip(learning_style_questions, learning_style_options)):
|
| 341 |
+
quiz_components.append(
|
| 342 |
+
gr.Radio(options, label=f"{i+1}. {question}")
|
| 343 |
+
)
|
| 344 |
+
|
| 345 |
+
learning_output = gr.Textbox(label="Learning Style Result")
|
| 346 |
+
gr.Button("Submit Quiz").click(
|
| 347 |
+
learning_style_quiz,
|
| 348 |
+
inputs=quiz_components,
|
| 349 |
+
outputs=learning_output
|
| 350 |
+
)
|
| 351 |
+
|
| 352 |
+
with gr.Tab("Step 3: Personal Questions"):
|
| 353 |
+
name = gr.Textbox(label="What's your name?")
|
| 354 |
+
age = gr.Number(label="How old are you?", precision=0)
|
| 355 |
+
interests = gr.Textbox(label="What are your interests?")
|
| 356 |
+
movie = gr.Textbox(label="Favorite movie?")
|
| 357 |
+
movie_reason = gr.Textbox(label="Why do you like that movie?")
|
| 358 |
+
show = gr.Textbox(label="Favorite TV show?")
|
| 359 |
+
show_reason = gr.Textbox(label="Why do you like that show?")
|
| 360 |
+
book = gr.Textbox(label="Favorite book?")
|
| 361 |
+
book_reason = gr.Textbox(label="Why do you like that book?")
|
| 362 |
+
character = gr.Textbox(label="Favorite character?")
|
| 363 |
+
character_reason = gr.Textbox(label="Why do you like that character?")
|
| 364 |
+
blog_checkbox = gr.Checkbox(label="Do you want to write a blog?", value=False)
|
| 365 |
+
blog_text = gr.Textbox(label="Write your blog here", visible=False, lines=5)
|
| 366 |
+
blog_checkbox.change(lambda x: gr.update(visible=x), inputs=blog_checkbox, outputs=blog_text)
|
| 367 |
+
|
| 368 |
+
with gr.Tab("Step 4: Save & Review"):
|
| 369 |
+
output_summary = gr.Markdown()
|
| 370 |
+
save_btn = gr.Button("Save Profile")
|
| 371 |
+
|
| 372 |
+
save_btn.click(
|
| 373 |
+
fn=save_profile,
|
| 374 |
+
inputs=[name, age, interests, transcript_data, learning_output,
|
| 375 |
+
movie, movie_reason, show, show_reason,
|
| 376 |
+
book, book_reason, character, character_reason, blog_text],
|
| 377 |
+
outputs=output_summary
|
| 378 |
+
)
|
| 379 |
+
|
| 380 |
+
# AI Teaching Assistant Tab
|
| 381 |
+
with gr.Tab("🤖 AI Teaching Assistant"):
|
| 382 |
+
gr.Markdown("## Your Personalized Learning Assistant")
|
| 383 |
+
chatbot = gr.ChatInterface(
|
| 384 |
+
fn=generate_response,
|
| 385 |
+
examples=[
|
| 386 |
+
"How should I study for my next test?",
|
| 387 |
+
"What's my GPA information?",
|
| 388 |
+
"Help me with study strategies",
|
| 389 |
+
"How can I improve my grades?"
|
| 390 |
+
]
|
| 391 |
+
)
|
| 392 |
+
|
| 393 |
+
if __name__ == "__main__":
|
| 394 |
+
app.launch()
|
| 395 |
|