Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -24,16 +24,9 @@ def parse_transcript(file):
|
|
24 |
def extract_transcript_info(df):
|
25 |
transcript_text = df['Transcript_Text'].iloc[0] if 'Transcript_Text' in df.columns else ''
|
26 |
info = {}
|
27 |
-
|
28 |
-
if name_match:
|
29 |
-
info['Name'] = name_match.group(1)
|
30 |
-
gpa_match = re.findall(r'(GPA|Grade Point Average)[^\d]*(\d+\.\d+)', transcript_text, re.IGNORECASE)
|
31 |
if gpa_match:
|
32 |
-
|
33 |
-
info['GPA'] = gpa_match[0][1]
|
34 |
-
elif len(gpa_match) >= 2:
|
35 |
-
info['Unweighted_GPA'] = gpa_match[0][1]
|
36 |
-
info['Weighted_GPA'] = gpa_match[1][1]
|
37 |
grade_match = re.search(r'Grade:?[\s]*(\d{1,2})', transcript_text, re.IGNORECASE)
|
38 |
if grade_match:
|
39 |
info['Grade_Level'] = grade_match.group(1)
|
@@ -42,7 +35,7 @@ def extract_transcript_info(df):
|
|
42 |
info['Courses'] = list(set([c[0].strip() for c in courses]))
|
43 |
return info
|
44 |
|
45 |
-
# Learning style questions
|
46 |
learning_style_questions = [
|
47 |
"When you are learning something new, you prefer to:",
|
48 |
"When you are at home, you like to:",
|
@@ -87,58 +80,116 @@ def learning_style_quiz(*answers):
|
|
87 |
|
88 |
return ", ".join(best_styles)
|
89 |
|
90 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
91 |
def save_profile(file, *inputs):
|
92 |
-
|
93 |
-
|
94 |
-
return "⚠️ Please upload your transcript."
|
95 |
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
|
104 |
-
|
105 |
-
|
106 |
|
107 |
-
|
108 |
-
|
109 |
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
|
114 |
-
|
115 |
-
|
116 |
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
|
131 |
-
|
132 |
-
|
133 |
|
134 |
-
|
135 |
-
|
136 |
|
137 |
-
|
138 |
-
return f"✅ Profile saved! Your learning style is: {learning_type}", *[gr.update(value="") for _ in inputs] + [gr.update(value=None) for _ in inputs]
|
139 |
-
|
140 |
-
except Exception as e:
|
141 |
-
return f"❌ Error: {str(e)}"
|
142 |
|
143 |
# Build Gradio UI
|
144 |
with gr.Blocks() as demo:
|
|
|
24 |
def extract_transcript_info(df):
|
25 |
transcript_text = df['Transcript_Text'].iloc[0] if 'Transcript_Text' in df.columns else ''
|
26 |
info = {}
|
27 |
+
gpa_match = re.search(r'(GPA|Grade Point Average)[^\d]*(\d+\.\d+)', transcript_text, re.IGNORECASE)
|
|
|
|
|
|
|
28 |
if gpa_match:
|
29 |
+
info['GPA'] = gpa_match.group(2)
|
|
|
|
|
|
|
|
|
30 |
grade_match = re.search(r'Grade:?[\s]*(\d{1,2})', transcript_text, re.IGNORECASE)
|
31 |
if grade_match:
|
32 |
info['Grade_Level'] = grade_match.group(1)
|
|
|
35 |
info['Courses'] = list(set([c[0].strip() for c in courses]))
|
36 |
return info
|
37 |
|
38 |
+
# Learning style questions - from educationplanner.org
|
39 |
learning_style_questions = [
|
40 |
"When you are learning something new, you prefer to:",
|
41 |
"When you are at home, you like to:",
|
|
|
80 |
|
81 |
return ", ".join(best_styles)
|
82 |
|
83 |
+
# PanoramaEd categories and multiple choice questions
|
84 |
+
get_to_know_categories = {
|
85 |
+
"All About Me": [
|
86 |
+
("What’s your favorite way to spend a day off?", []),
|
87 |
+
("If you could only eat one food for the rest of your life, what would it be?", []),
|
88 |
+
("Do you have any pets? If so, what are their names?", []),
|
89 |
+
("If you could travel anywhere in the world, where would you go?", []),
|
90 |
+
("What’s your favorite holiday or tradition?", []),
|
91 |
+
("What are some of your favorite movies or shows?", []),
|
92 |
+
("Do you have a favorite book or book series? Why?", []),
|
93 |
+
("Who is a character from a show, book, or movie that you relate to? Why?", []),
|
94 |
+
("If you could be any fictional character, who would you be and why?", [])
|
95 |
+
],
|
96 |
+
"Hopes and Dreams": [
|
97 |
+
("What do you want to be when you grow up?", []),
|
98 |
+
("What’s something you hope to achieve this year?", []),
|
99 |
+
("If you could change the world in one way, what would you do?", []),
|
100 |
+
("What are you most proud of?", []),
|
101 |
+
("What’s a big dream you have for your future?", [])
|
102 |
+
],
|
103 |
+
"School Life": [
|
104 |
+
("What’s your favorite subject in school?", []),
|
105 |
+
("What’s something that makes learning easier for you?", []),
|
106 |
+
("Do you prefer working alone or in groups?", []),
|
107 |
+
("What helps you feel confident in class?", []),
|
108 |
+
("What’s something you’re good at in school?", [])
|
109 |
+
],
|
110 |
+
"Relationships": [
|
111 |
+
("Who do you look up to and why?", []),
|
112 |
+
("Who is someone that makes you feel safe and supported?", []),
|
113 |
+
("Do you have a best friend? What do you like to do together?", []),
|
114 |
+
("What’s one thing you wish people knew about you?", []),
|
115 |
+
("What’s something kind you’ve done for someone else?", [])
|
116 |
+
]
|
117 |
+
}
|
118 |
+
|
119 |
+
# Generators for output summaries
|
120 |
+
def generate_learning_plan(info):
|
121 |
+
level = info.get("Grade_Level", "unknown")
|
122 |
+
courses = info.get("Courses", [])
|
123 |
+
gpa = info.get("GPA", "N/A")
|
124 |
+
return f"""
|
125 |
+
📘 **Personalized Learning Plan**
|
126 |
+
- Grade Level: {level}
|
127 |
+
- GPA: {gpa}
|
128 |
+
- Suggested Focus Areas: {', '.join(courses[:3]) if courses else 'N/A'}
|
129 |
+
- Goals: Strengthen key subjects, explore interests, and build study habits.
|
130 |
+
"""
|
131 |
+
|
132 |
+
def generate_learning_style_summary(style):
|
133 |
+
return f"""
|
134 |
+
🧠 **Learning Style Summary**
|
135 |
+
You are a **{style}** learner. That means you learn best through {"visual aids like charts and images" if "Visual" in style else "listening and verbal instruction" if "Auditory" in style else "reading and writing-based methods"}.
|
136 |
+
"""
|
137 |
+
|
138 |
+
def generate_motivation_section(responses):
|
139 |
+
hopes = [ans for q, ans in responses.items() if "hope" in q.lower() or "dream" in q.lower()]
|
140 |
+
return f"""
|
141 |
+
💡 **Motivational Summary**
|
142 |
+
Your dreams are powerful: {'; '.join(hopes) if hopes else 'You are filled with potential!'}.
|
143 |
+
Believe in yourself and keep moving forward.
|
144 |
+
"""
|
145 |
+
|
146 |
+
# Save all answers into profile
|
147 |
def save_profile(file, *inputs):
|
148 |
+
if not file:
|
149 |
+
return "⚠️ Please upload your transcript."
|
|
|
150 |
|
151 |
+
quiz_answers = inputs[:len(learning_style_questions)]
|
152 |
+
if any(ans is None for ans in quiz_answers):
|
153 |
+
return "⚠️ Please answer all the learning style questions."
|
154 |
|
155 |
+
blog_checkbox = inputs[len(learning_style_questions)]
|
156 |
+
blog_text = inputs[len(learning_style_questions)+1]
|
157 |
+
category_answers = inputs[len(learning_style_questions)+2:]
|
158 |
|
159 |
+
if any(ans.strip() == "" for ans in category_answers):
|
160 |
+
return "⚠️ Please complete all 'Get to Know You' sections before saving."
|
161 |
|
162 |
+
if blog_checkbox and blog_text.strip() == "":
|
163 |
+
return "⚠️ You checked the blog option but didn’t write anything. Please write your mini blog or uncheck the option."
|
164 |
|
165 |
+
df = parse_transcript(file)
|
166 |
+
transcript_info = extract_transcript_info(df)
|
167 |
+
learning_type = learning_style_quiz(*quiz_answers)
|
168 |
|
169 |
+
question_texts = [q for cat in get_to_know_categories.values() for q, _ in cat]
|
170 |
+
responses = dict(zip(question_texts, category_answers))
|
171 |
|
172 |
+
profile = {
|
173 |
+
"transcript": df.to_dict(orient='records'),
|
174 |
+
"transcript_info": transcript_info,
|
175 |
+
"learning_style": learning_type,
|
176 |
+
"get_to_know_answers": responses,
|
177 |
+
"blog": blog_text if blog_checkbox else "[User chose to skip this section]"
|
178 |
+
}
|
179 |
|
180 |
+
summary = {
|
181 |
+
"Learning_Plan": generate_learning_plan(transcript_info),
|
182 |
+
"Style_Summary": generate_learning_style_summary(learning_type),
|
183 |
+
"Motivation": generate_motivation_section(responses)
|
184 |
+
}
|
185 |
|
186 |
+
with open("student_profile.json", "w") as f:
|
187 |
+
json.dump(profile, f, indent=4)
|
188 |
|
189 |
+
with open("student_summary.md", "w") as f:
|
190 |
+
f.write(summary["Learning_Plan"] + '\n' + summary["Style_Summary"] + '\n' + summary["Motivation"])
|
191 |
|
192 |
+
return f"✅ Profile saved! Your learning style is: {learning_type}", *[gr.update(value="") for _ in inputs] + [gr.update(value=None) for _ in inputs]
|
|
|
|
|
|
|
|
|
193 |
|
194 |
# Build Gradio UI
|
195 |
with gr.Blocks() as demo:
|