Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,406 +1,171 @@
|
|
1 |
import gradio as gr
|
2 |
import pandas as pd
|
3 |
-
import PyPDF2
|
4 |
import json
|
|
|
5 |
import re
|
|
|
|
|
|
|
6 |
|
7 |
-
# Parse uploaded transcript file
|
8 |
def parse_transcript(file):
|
9 |
if file.name.endswith('.csv'):
|
10 |
-
df = pd.read_csv(file
|
11 |
-
elif file.name.endswith(
|
12 |
-
df = pd.read_excel(file
|
13 |
elif file.name.endswith('.pdf'):
|
14 |
-
|
15 |
-
|
16 |
for page in reader.pages:
|
17 |
-
text += page.extract_text()
|
18 |
-
|
19 |
else:
|
20 |
-
|
21 |
-
return df
|
22 |
-
|
23 |
-
# Extract student info
|
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)
|
33 |
-
courses = re.findall(r'(?i)\b([A-Z][a-zA-Z\s&/]+)\s+(\d{1,3})\b', transcript_text)
|
34 |
-
if courses:
|
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:",
|
42 |
-
"When you spell a word, you remember it by:",
|
43 |
-
"When you read, you:",
|
44 |
-
"When you write, you:",
|
45 |
-
"When you listen to music, you:",
|
46 |
-
"When you work at solving a problem, you:",
|
47 |
-
"When you give someone directions, you:",
|
48 |
-
"When you are concentrating, you:",
|
49 |
-
"When you meet someone new, you remember them by:"
|
50 |
-
]
|
51 |
-
|
52 |
-
learning_style_answers = [
|
53 |
-
["Watch someone do it", "Listen to someone explain it", "Read about it"],
|
54 |
-
["Watch TV or play video games", "Listen to music or talk to people", "Read books or write stories"],
|
55 |
-
["Seeing the word in your mind", "Saying the word out loud", "Writing the word down"],
|
56 |
-
["See the action in your mind", "Hear the characters talk", "Focus on the written words"],
|
57 |
-
["Use diagrams or doodles", "Talk about ideas", "Write detailed notes"],
|
58 |
-
["Appreciate the rhythm and melodies", "Easily remember lyrics", "Analyze the lyrics"],
|
59 |
-
["Visualize the solution", "Discuss the problem", "Write out the steps"],
|
60 |
-
["Draw a map", "Give spoken directions", "Write directions"],
|
61 |
-
["Picture things", "Say things out loud", "Write or read quietly"],
|
62 |
-
["Remember faces", "Remember names or voices", "Remember what you wrote about them"]
|
63 |
-
]
|
64 |
-
|
65 |
-
style_count_map = {0: "visual", 1: "auditory", 2: "reading/writing"}
|
66 |
-
|
67 |
-
def learning_style_quiz(*answers):
|
68 |
-
scores = {'visual': 0, 'auditory': 0, 'reading/writing': 0}
|
69 |
-
|
70 |
-
for i, ans in enumerate(answers):
|
71 |
-
if i < len(learning_style_answers):
|
72 |
-
options = learning_style_answers[i]
|
73 |
-
if ans in options:
|
74 |
-
index = options.index(ans)
|
75 |
-
style = style_count_map[index]
|
76 |
-
scores[style] += 1
|
77 |
-
|
78 |
-
max_score = max(scores.values())
|
79 |
-
best_styles = [style.capitalize() for style, score in scores.items() if score == max_score]
|
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 |
-
|
163 |
-
|
|
|
164 |
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
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 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
184 |
}
|
185 |
|
186 |
-
|
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}"
|
193 |
-
|
194 |
-
# Build Gradio UI
|
195 |
-
with gr.Blocks() as demo:
|
196 |
-
gr.Markdown("## 🎓 Personalized AI Student Assistant")
|
197 |
-
|
198 |
-
with gr.Row():
|
199 |
-
file = gr.File(label="📄 Upload Your Transcript (.csv, .xlsx, .pdf)")
|
200 |
-
|
201 |
-
with gr.Column():
|
202 |
-
gr.Markdown("### 🧠 Learning Style Discovery")
|
203 |
-
quiz_components = []
|
204 |
-
for i, (question, options) in enumerate(zip(learning_style_questions, learning_style_answers)):
|
205 |
-
quiz_components.append(gr.Radio(
|
206 |
-
choices=options,
|
207 |
-
label=f"{i+1}. {question}"
|
208 |
-
))
|
209 |
|
210 |
-
|
211 |
-
|
212 |
-
|
213 |
-
|
214 |
-
|
215 |
-
|
216 |
-
|
217 |
-
|
218 |
-
|
219 |
-
|
220 |
-
|
221 |
-
|
222 |
-
|
223 |
-
|
224 |
-
|
225 |
-
|
226 |
-
|
227 |
-
|
228 |
-
|
229 |
-
|
230 |
-
|
231 |
-
|
232 |
-
|
233 |
-
|
234 |
-
|
235 |
-
|
236 |
-
def generate_study_tips(learning_style):
|
237 |
-
tips = {
|
238 |
-
"Visual": [
|
239 |
-
"Use color-coding in your notes",
|
240 |
-
"Create mind maps or diagrams",
|
241 |
-
"Watch educational videos",
|
242 |
-
"Use flashcards with images",
|
243 |
-
"Draw pictures to represent concepts"
|
244 |
-
],
|
245 |
-
"Auditory": [
|
246 |
-
"Record lectures and listen to them",
|
247 |
-
"Explain concepts out loud to yourself",
|
248 |
-
"Participate in study groups",
|
249 |
-
"Use mnemonic devices with rhymes",
|
250 |
-
"Listen to educational podcasts"
|
251 |
-
],
|
252 |
-
"Reading/writing": [
|
253 |
-
"Rewrite your notes in your own words",
|
254 |
-
"Create detailed outlines",
|
255 |
-
"Write summaries of what you learn",
|
256 |
-
"Read textbooks and articles",
|
257 |
-
"Keep a learning journal"
|
258 |
-
]
|
259 |
-
}
|
260 |
-
return tips.get(learning_style.split(", ")[0], [])
|
261 |
-
|
262 |
-
def generate_subject_specific_advice(courses):
|
263 |
-
advice = {
|
264 |
-
"Math": [
|
265 |
-
"Practice problems daily",
|
266 |
-
"Focus on understanding concepts, not just memorization",
|
267 |
-
"Show all your work step-by-step",
|
268 |
-
"Relate math to real-world applications"
|
269 |
-
],
|
270 |
-
"Science": [
|
271 |
-
"Conduct simple experiments at home",
|
272 |
-
"Create concept maps of scientific processes",
|
273 |
-
"Relate concepts to everyday phenomena",
|
274 |
-
"Watch science documentaries"
|
275 |
-
],
|
276 |
-
"English": [
|
277 |
-
"Read diverse genres of literature",
|
278 |
-
"Keep a vocabulary journal",
|
279 |
-
"Practice writing in different styles",
|
280 |
-
"Analyze author's techniques"
|
281 |
-
],
|
282 |
-
"History": [
|
283 |
-
"Create timelines of events",
|
284 |
-
"Connect historical events to current affairs",
|
285 |
-
"Watch historical films (and fact-check them)",
|
286 |
-
"Debate different historical perspectives"
|
287 |
-
]
|
288 |
-
}
|
289 |
-
|
290 |
-
default_advice = [
|
291 |
-
"Break study sessions into 25-minute chunks",
|
292 |
-
"Review material regularly, not just before tests",
|
293 |
-
"Connect new information to what you already know",
|
294 |
-
"Teach the material to someone else"
|
295 |
-
]
|
296 |
-
|
297 |
-
course_advice = []
|
298 |
-
for course in courses:
|
299 |
-
for subject in advice:
|
300 |
-
if subject.lower() in course.lower():
|
301 |
-
course_advice.extend(advice[subject])
|
302 |
-
|
303 |
-
return course_advice if course_advice else default_advice
|
304 |
-
|
305 |
-
def generate_personalized_message(responses):
|
306 |
-
hobbies = [ans for q, ans in responses.items() if "favorite way to spend" in q.lower()]
|
307 |
-
goals = [ans for q, ans in responses.items() if "want to be when" in q.lower() or "hope to achieve" in q.lower()]
|
308 |
-
|
309 |
-
messages = []
|
310 |
-
if hobbies:
|
311 |
-
messages.append(f"I see you enjoy {hobbies[0].lower()}. Let's find ways to connect that to your learning!")
|
312 |
-
if goals:
|
313 |
-
messages.append(f"Your goal to {goals[0].lower()} is inspiring! Here's how we can work toward that:")
|
314 |
-
return "\n".join(messages) if messages else "I'm excited to help you achieve your learning goals!"
|
315 |
-
|
316 |
-
def assistant_response(message, history):
|
317 |
-
profile = load_student_profile()
|
318 |
-
if not profile:
|
319 |
-
return "Please complete and save your profile first using the previous tabs."
|
320 |
-
|
321 |
-
# Get profile data
|
322 |
-
learning_style = profile["learning_style"]
|
323 |
-
courses = profile["transcript_info"].get("Courses", [])
|
324 |
-
responses = profile["get_to_know_answers"]
|
325 |
-
|
326 |
-
# Generate personalized content
|
327 |
-
study_tips = generate_study_tips(learning_style)
|
328 |
-
subject_advice = generate_subject_specific_advice(courses)
|
329 |
-
personal_message = generate_personalized_message(responses)
|
330 |
-
|
331 |
-
# Common responses
|
332 |
-
if "help" in message.lower() or "support" in message.lower():
|
333 |
-
return f"""
|
334 |
-
{personal_message}
|
335 |
-
|
336 |
-
Here's how I can help:
|
337 |
-
1. Provide study tips matching your {learning_style} learning style
|
338 |
-
2. Offer subject-specific advice for {', '.join(courses[:3]) if courses else 'your courses'}
|
339 |
-
3. Answer questions about your learning plan
|
340 |
-
4. Help you stay motivated
|
341 |
-
|
342 |
-
What would you like to focus on today?
|
343 |
-
"""
|
344 |
-
elif "tip" in message.lower() or "advice" in message.lower():
|
345 |
-
return f"""
|
346 |
-
📚 **Personalized Study Advice**
|
347 |
-
|
348 |
-
🎨 For your {learning_style} learning style:
|
349 |
-
{'\n'.join(f'- {tip}' for tip in study_tips)}
|
350 |
|
351 |
-
|
352 |
-
{'\n'.join(f'- {advice}' for advice in subject_advice)}
|
353 |
-
"""
|
354 |
-
elif "plan" in message.lower() or "schedule" in message.lower():
|
355 |
-
return """
|
356 |
-
📅 **Suggested Study Schedule**
|
357 |
-
- Morning (30 min): Review previous material
|
358 |
-
- Afternoon (45 min): Practice new concepts
|
359 |
-
- Evening (20 min): Quick recap
|
360 |
-
- Weekend: Longer project work
|
361 |
|
362 |
-
|
363 |
-
|
364 |
-
|
365 |
-
return f"""
|
366 |
-
💪 **Motivation Boost**
|
367 |
-
{personal_message}
|
368 |
|
369 |
-
|
370 |
-
|
371 |
-
- Small steps add up to big achievements
|
372 |
-
- Your {learning_style} learning style is your superpower!
|
373 |
-
"""
|
374 |
-
else:
|
375 |
-
return f"""
|
376 |
-
{personal_message}
|
377 |
|
378 |
-
|
379 |
-
-
|
380 |
-
-
|
381 |
-
-
|
382 |
-
-
|
383 |
|
384 |
-
|
385 |
-
|
386 |
-
- "What's the best way to learn based on my style?"
|
387 |
-
- "Can you help me make a study plan?"
|
388 |
"""
|
389 |
-
|
390 |
-
|
391 |
-
|
392 |
-
|
393 |
-
|
394 |
-
|
395 |
-
|
396 |
-
|
397 |
-
|
398 |
-
|
399 |
-
|
400 |
-
|
401 |
-
|
402 |
-
)
|
403 |
-
|
404 |
-
|
405 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
406 |
|
|
|
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 |
+
|
8 |
+
# ========== TRANSCRIPT PARSING FUNCTIONS ==========
|
9 |
|
|
|
10 |
def parse_transcript(file):
|
11 |
if file.name.endswith('.csv'):
|
12 |
+
df = pd.read_csv(file)
|
13 |
+
elif file.name.endswith('.xlsx'):
|
14 |
+
df = pd.read_excel(file)
|
15 |
elif file.name.endswith('.pdf'):
|
16 |
+
text = ''
|
17 |
+
reader = PdfReader(file)
|
18 |
for page in reader.pages:
|
19 |
+
text += page.extract_text() + '\n'
|
20 |
+
return extract_info_from_pdf(text)
|
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 ==========
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
50 |
|
51 |
+
def learning_style_quiz(*answers):
|
52 |
+
visual = answers.count("I remember something better when I see it written down.")
|
53 |
+
auditory = answers.count("I remember best by listening to a lecture or a recording.")
|
54 |
+
reading = answers.count("I remember best by reading information on my own.")
|
55 |
+
|
56 |
+
styles = {"Visual": visual, "Auditory": auditory, "Reading/Writing": reading}
|
57 |
+
top_styles = [k for k, v in styles.items() if v == max(styles.values())]
|
58 |
+
result = ", ".join(top_styles)
|
59 |
+
return result
|
60 |
+
|
61 |
+
# ========== SAVE STUDENT PROFILE FUNCTION ==========
|
62 |
+
|
63 |
+
def save_profile(name, age, interests, transcript, learning_style, favorites, blog):
|
64 |
+
data = {
|
65 |
+
"name": name,
|
66 |
+
"age": age,
|
67 |
+
"interests": interests,
|
68 |
+
"transcript": transcript,
|
69 |
+
"learning_style": learning_style,
|
70 |
+
"favorites": favorites,
|
71 |
+
"blog": blog
|
72 |
+
}
|
73 |
+
os.makedirs("student_profiles", exist_ok=True)
|
74 |
+
json_path = os.path.join("student_profiles", f"{name.replace(' ', '_')}_profile.json")
|
75 |
+
with open(json_path, "w") as f:
|
76 |
+
json.dump(data, f, indent=2)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
77 |
|
78 |
+
markdown_summary = f"""### Student Profile: {name}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
79 |
|
80 |
+
**Age:** {age}
|
81 |
+
**Interests:** {interests}
|
82 |
+
**Learning Style:** {learning_style}
|
|
|
|
|
|
|
83 |
|
84 |
+
#### Transcript:
|
85 |
+
{transcript_display(transcript)}
|
|
|
|
|
|
|
|
|
|
|
|
|
86 |
|
87 |
+
#### Favorites:
|
88 |
+
- Movie: {favorites['movie']} ({favorites['movie_reason']})
|
89 |
+
- Show: {favorites['show']} ({favorites['show_reason']})
|
90 |
+
- Book: {favorites['book']} ({favorites['book_reason']})
|
91 |
+
- Character: {favorites['character']} ({favorites['character_reason']})
|
92 |
|
93 |
+
#### Blog:
|
94 |
+
{blog if blog else "_No blog provided_"}
|
|
|
|
|
95 |
"""
|
96 |
+
return markdown_summary
|
97 |
+
|
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 |
+
|
105 |
+
with gr.Blocks() as app:
|
106 |
+
with gr.Tab("Step 1: Upload Transcript"):
|
107 |
+
transcript_file = gr.File(label="Upload your transcript (CSV, Excel, or PDF)")
|
108 |
+
transcript_output = gr.Textbox(label="Transcript Output")
|
109 |
+
transcript_data = gr.State()
|
110 |
+
transcript_file.change(fn=parse_transcript, inputs=transcript_file, outputs=[transcript_output, transcript_data])
|
111 |
+
|
112 |
+
with gr.Tab("Step 2: Learning Style Quiz"):
|
113 |
+
q1 = gr.Radio(choices=[
|
114 |
+
"I remember something better when I see it written down.",
|
115 |
+
"I remember best by listening to a lecture or a recording.",
|
116 |
+
"I remember best by reading information on my own."
|
117 |
+
], label="1. How do you best remember information?")
|
118 |
+
q2 = gr.Radio(choices=q1.choices, label="2. What’s your preferred study method?")
|
119 |
+
q3 = gr.Radio(choices=q1.choices, label="3. What helps you understand new topics?")
|
120 |
+
q4 = gr.Radio(choices=q1.choices, label="4. How do you prefer to take notes?")
|
121 |
+
q5 = gr.Radio(choices=q1.choices, label="5. When you visualize concepts, what helps most?")
|
122 |
+
learning_output = gr.Textbox(label="Learning Style Result")
|
123 |
+
gr.Button("Submit Quiz").click(learning_style_quiz, inputs=[q1, q2, q3, q4, q5], outputs=learning_output)
|
124 |
+
|
125 |
+
with gr.Tab("Step 3: Personal Questions"):
|
126 |
+
name = gr.Textbox(label="What's your name?")
|
127 |
+
age = gr.Number(label="How old are you?")
|
128 |
+
interests = gr.Textbox(label="What are your interests?")
|
129 |
+
movie = gr.Textbox(label="Favorite movie?")
|
130 |
+
movie_reason = gr.Textbox(label="Why do you like that movie?")
|
131 |
+
show = gr.Textbox(label="Favorite TV show?")
|
132 |
+
show_reason = gr.Textbox(label="Why do you like that show?")
|
133 |
+
book = gr.Textbox(label="Favorite book?")
|
134 |
+
book_reason = gr.Textbox(label="Why do you like that book?")
|
135 |
+
character = gr.Textbox(label="Favorite character?")
|
136 |
+
character_reason = gr.Textbox(label="Why do you like that character?")
|
137 |
+
blog_checkbox = gr.Checkbox(label="Do you want to write a blog?", value=False)
|
138 |
+
blog_text = gr.Textbox(label="Write your blog here", visible=False, lines=5)
|
139 |
+
blog_checkbox.change(fn=lambda x: gr.update(visible=x), inputs=blog_checkbox, outputs=blog_text)
|
140 |
+
|
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 = {
|
148 |
+
"movie": movie,
|
149 |
+
"movie_reason": movie_reason,
|
150 |
+
"show": show,
|
151 |
+
"show_reason": show_reason,
|
152 |
+
"book": book,
|
153 |
+
"book_reason": book_reason,
|
154 |
+
"character": character,
|
155 |
+
"character_reason": character_reason,
|
156 |
+
}
|
157 |
+
return save_profile(name, age, interests, transcript, learning_style, favorites, blog)
|
158 |
+
|
159 |
+
save_btn.click(fn=gather_and_save,
|
160 |
+
inputs=[name, age, interests, movie, movie_reason, show, show_reason,
|
161 |
+
book, book_reason, character, character_reason, blog_text,
|
162 |
+
transcript_data, learning_output],
|
163 |
+
outputs=output_summary)
|
164 |
+
|
165 |
+
app.launch()
|
166 |
+
|
167 |
+
|
168 |
+
|
169 |
+
|
170 |
+
|
171 |
|