Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -24,28 +24,22 @@ 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 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
|
|
|
|
36 |
if grade_match:
|
37 |
info['Grade_Level'] = grade_match.group(1)
|
38 |
-
|
39 |
-
# Full Name
|
40 |
-
name_match = re.search(r'(Student Name|Name):?\s*([A-Z][a-z]+\s+[A-Z][a-z]+)', transcript_text)
|
41 |
-
if name_match:
|
42 |
-
info['Full_Name'] = name_match.group(2)
|
43 |
-
|
44 |
-
# Courses
|
45 |
courses = re.findall(r'(?i)\b([A-Z][a-zA-Z\s&/]+)\s+(\d{1,3})\b', transcript_text)
|
46 |
if courses:
|
47 |
info['Courses'] = list(set([c[0].strip() for c in courses]))
|
48 |
-
|
49 |
return info
|
50 |
|
51 |
# Learning style questions - from educationplanner.org
|
@@ -93,6 +87,7 @@ def learning_style_quiz(*answers):
|
|
93 |
|
94 |
return ", ".join(best_styles)
|
95 |
|
|
|
96 |
get_to_know_categories = {
|
97 |
"All About Me": [
|
98 |
("Whatโs your favorite way to spend a day off?", []),
|
@@ -131,7 +126,7 @@ get_to_know_categories = {
|
|
131 |
def generate_learning_plan(info):
|
132 |
level = info.get("Grade_Level", "unknown")
|
133 |
courses = info.get("Courses", [])
|
134 |
-
gpa = info.get("GPA", info.get("
|
135 |
return f"""
|
136 |
๐ **Personalized Learning Plan**
|
137 |
- Grade Level: {level}
|
@@ -154,63 +149,58 @@ Your dreams are powerful: {'; '.join(hopes) if hopes else 'You are filled with p
|
|
154 |
Believe in yourself and keep moving forward.
|
155 |
"""
|
156 |
|
157 |
-
def show_basic_info():
|
158 |
-
with open("student_profile.json") as f:
|
159 |
-
profile = json.load(f)
|
160 |
-
info = profile["transcript_info"]
|
161 |
-
name = info.get("Full_Name", "Name not found")
|
162 |
-
grade = info.get("Grade_Level", "N/A")
|
163 |
-
gpa = info.get("GPA", info.get("Unweighted", "N/A"))
|
164 |
-
weighted = info.get("Weighted", "Not provided")
|
165 |
-
return f"๐ค Name: {name}\n๐ Grade Level: {grade}\n๐ GPA: {gpa}\n๐ Weighted GPA: {weighted}"
|
166 |
-
|
167 |
def save_profile(file, *inputs):
|
168 |
-
|
169 |
-
|
|
|
170 |
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
|
179 |
-
|
180 |
-
|
181 |
|
182 |
-
|
183 |
-
|
184 |
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
|
189 |
-
|
190 |
-
|
191 |
|
192 |
-
|
193 |
-
|
194 |
-
|
195 |
-
|
196 |
-
|
197 |
-
|
198 |
-
|
199 |
|
200 |
-
|
201 |
-
|
202 |
-
|
203 |
-
|
204 |
-
|
205 |
|
206 |
-
|
207 |
-
|
208 |
|
209 |
-
|
210 |
-
|
211 |
|
212 |
-
|
|
|
|
|
|
|
213 |
|
|
|
214 |
with gr.Blocks() as demo:
|
215 |
gr.Markdown("## ๐ Personalized AI Student Assistant")
|
216 |
|
@@ -234,15 +224,15 @@ with gr.Blocks() as demo:
|
|
234 |
|
235 |
blog_checkbox = gr.Checkbox(label="๐ I'd like to write a mini blog about myself")
|
236 |
blog_text = gr.Textbox(lines=5, label="โ๏ธ Mini Blog", visible=False)
|
|
|
237 |
blog_checkbox.change(fn=lambda x: gr.update(visible=x), inputs=blog_checkbox, outputs=blog_text)
|
238 |
|
239 |
submit = gr.Button("๐๏ธ Save My Profile")
|
240 |
-
|
241 |
-
user_info_output = gr.Textbox(label="๐ค Your Info", visible=False)
|
242 |
|
243 |
submit.click(fn=save_profile,
|
244 |
inputs=[file, *quiz_components, blog_checkbox, blog_text, *category_inputs],
|
245 |
-
outputs=[
|
246 |
|
247 |
if __name__ == '__main__':
|
248 |
-
demo.launch()
|
|
|
24 |
def extract_transcript_info(df):
|
25 |
transcript_text = df['Transcript_Text'].iloc[0] if 'Transcript_Text' in df.columns else ''
|
26 |
info = {}
|
27 |
+
name_match = re.search(r"Name[:\s]+([A-Z][a-z]+\s[A-Z][a-z]+)", transcript_text)
|
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 |
+
if len(gpa_match) == 1:
|
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)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
40 |
courses = re.findall(r'(?i)\b([A-Z][a-zA-Z\s&/]+)\s+(\d{1,3})\b', transcript_text)
|
41 |
if courses:
|
42 |
info['Courses'] = list(set([c[0].strip() for c in courses]))
|
|
|
43 |
return info
|
44 |
|
45 |
# Learning style questions - from educationplanner.org
|
|
|
87 |
|
88 |
return ", ".join(best_styles)
|
89 |
|
90 |
+
# PanoramaEd categories and multiple choice questions
|
91 |
get_to_know_categories = {
|
92 |
"All About Me": [
|
93 |
("Whatโs your favorite way to spend a day off?", []),
|
|
|
126 |
def generate_learning_plan(info):
|
127 |
level = info.get("Grade_Level", "unknown")
|
128 |
courses = info.get("Courses", [])
|
129 |
+
gpa = info.get("GPA", info.get("Unweighted_GPA", "N/A"))
|
130 |
return f"""
|
131 |
๐ **Personalized Learning Plan**
|
132 |
- Grade Level: {level}
|
|
|
149 |
Believe in yourself and keep moving forward.
|
150 |
"""
|
151 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
152 |
def save_profile(file, *inputs):
|
153 |
+
try:
|
154 |
+
if not file:
|
155 |
+
return "โ ๏ธ Please upload your transcript."
|
156 |
|
157 |
+
quiz_answers = inputs[:len(learning_style_questions)]
|
158 |
+
if any(ans is None for ans in quiz_answers):
|
159 |
+
return "โ ๏ธ Please answer all the learning style questions."
|
160 |
|
161 |
+
blog_checkbox = inputs[len(learning_style_questions)]
|
162 |
+
blog_text = inputs[len(learning_style_questions)+1]
|
163 |
+
category_answers = inputs[len(learning_style_questions)+2:]
|
164 |
|
165 |
+
if any(ans.strip() == "" for ans in category_answers):
|
166 |
+
return "โ ๏ธ Please complete all 'Get to Know You' sections before saving."
|
167 |
|
168 |
+
if blog_checkbox and blog_text.strip() == "":
|
169 |
+
return "โ ๏ธ You checked the blog option but didnโt write anything. Please write your mini blog or uncheck the option."
|
170 |
|
171 |
+
df = parse_transcript(file)
|
172 |
+
transcript_info = extract_transcript_info(df)
|
173 |
+
learning_type = learning_style_quiz(*quiz_answers)
|
174 |
|
175 |
+
question_texts = [q for cat in get_to_know_categories.values() for q, _ in cat]
|
176 |
+
responses = dict(zip(question_texts, category_answers))
|
177 |
|
178 |
+
profile = {
|
179 |
+
"transcript": df.to_dict(orient='records'),
|
180 |
+
"transcript_info": transcript_info,
|
181 |
+
"learning_style": learning_type,
|
182 |
+
"get_to_know_answers": responses,
|
183 |
+
"blog": blog_text if blog_checkbox else "[User chose to skip this section]"
|
184 |
+
}
|
185 |
|
186 |
+
summary = {
|
187 |
+
"Learning_Plan": generate_learning_plan(transcript_info),
|
188 |
+
"Style_Summary": generate_learning_style_summary(learning_type),
|
189 |
+
"Motivation": generate_motivation_section(responses)
|
190 |
+
}
|
191 |
|
192 |
+
with open("student_profile.json", "w") as f:
|
193 |
+
json.dump(profile, f, indent=4)
|
194 |
|
195 |
+
with open("student_summary.md", "w") as f:
|
196 |
+
f.write(summary["Learning_Plan"] + '\n' + summary["Style_Summary"] + '\n' + summary["Motivation"])
|
197 |
|
198 |
+
return f"โ
Profile saved! Your learning style is: {learning_type}"
|
199 |
+
|
200 |
+
except Exception as e:
|
201 |
+
return f"โ Error: {str(e)}"
|
202 |
|
203 |
+
# Build Gradio UI
|
204 |
with gr.Blocks() as demo:
|
205 |
gr.Markdown("## ๐ Personalized AI Student Assistant")
|
206 |
|
|
|
224 |
|
225 |
blog_checkbox = gr.Checkbox(label="๐ I'd like to write a mini blog about myself")
|
226 |
blog_text = gr.Textbox(lines=5, label="โ๏ธ Mini Blog", visible=False)
|
227 |
+
|
228 |
blog_checkbox.change(fn=lambda x: gr.update(visible=x), inputs=blog_checkbox, outputs=blog_text)
|
229 |
|
230 |
submit = gr.Button("๐๏ธ Save My Profile")
|
231 |
+
output = gr.Textbox(label="Status")
|
|
|
232 |
|
233 |
submit.click(fn=save_profile,
|
234 |
inputs=[file, *quiz_components, blog_checkbox, blog_text, *category_inputs],
|
235 |
+
outputs=[output])
|
236 |
|
237 |
if __name__ == '__main__':
|
238 |
+
demo.launch()
|