Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -35,7 +35,7 @@ def extract_transcript_info(df):
|
|
35 |
info['Courses'] = list(set([c[0].strip() for c in courses]))
|
36 |
return info
|
37 |
|
38 |
-
# Learning style
|
39 |
learning_style_questions = [
|
40 |
"When you are learning something new, you prefer to:",
|
41 |
"When you are at home, you like to:",
|
@@ -66,6 +66,7 @@ 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 |
for i, ans in enumerate(answers):
|
70 |
if i < len(learning_style_answers):
|
71 |
options = learning_style_answers[i]
|
@@ -73,10 +74,13 @@ def learning_style_quiz(*answers):
|
|
73 |
index = options.index(ans)
|
74 |
style = style_count_map[index]
|
75 |
scores[style] += 1
|
|
|
76 |
max_score = max(scores.values())
|
77 |
best_styles = [style.capitalize() for style, score in scores.items() if score == max_score]
|
|
|
78 |
return ", ".join(best_styles)
|
79 |
|
|
|
80 |
get_to_know_categories = {
|
81 |
"All About Me": [
|
82 |
("Whatโs your favorite way to spend a day off?", []),
|
@@ -112,103 +116,114 @@ get_to_know_categories = {
|
|
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 |
-
|
139 |
|
140 |
-
|
141 |
-
|
142 |
-
blog_comment = f"๐ Your blog was very thoughtful! You wrote: \"{blog[:150]}...\""
|
143 |
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
๐ฌ **Personal Reflections**
|
154 |
-
{chr(10).join(comments)}
|
155 |
-
{blog_comment}
|
156 |
-
โ Is all this information correct?
|
157 |
-
"""
|
158 |
-
return summary_text
|
159 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
160 |
|
161 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
162 |
with gr.Blocks() as demo:
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
for
|
172 |
-
gr.
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
gr.Markdown("
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
-
|
193 |
-
|
194 |
-
"learning_style": learning_result,
|
195 |
-
"get_to_know_answers": personal_responses,
|
196 |
-
"blog": blog_text or "[User chose to skip this section]"
|
197 |
-
}
|
198 |
-
|
199 |
-
with open("student_profile.json", "w") as f:
|
200 |
-
json.dump(student_data, f, indent=2)
|
201 |
-
|
202 |
-
return gr.update(visible=False), gr.update(visible=True), display_saved_profile()
|
203 |
-
|
204 |
-
save_btn.click(
|
205 |
-
fn=save_profile,
|
206 |
-
inputs=[transcript_input] + ls_dropdowns + list(get_to_know_inputs.values()) + [blog_input],
|
207 |
-
outputs=[profile_interface, confirmation_interface, summary_output]
|
208 |
-
)
|
209 |
-
|
210 |
-
confirm_btn.click(fn=lambda: "๐ All set! You're ready to move forward.", outputs=[final_status])
|
211 |
-
correct_btn.click(fn=lambda: "๐ Okay! Please update the necessary information and save again.", outputs=[final_status])
|
212 |
|
213 |
if __name__ == '__main__':
|
214 |
demo.launch()
|
|
|
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:",
|
|
|
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]
|
|
|
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?", []),
|
|
|
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}"
|
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 |
+
category_inputs = []
|
211 |
+
for category, questions in get_to_know_categories.items():
|
212 |
+
gr.Markdown(f"### ๐ {category}")
|
213 |
+
for q_text, _ in questions:
|
214 |
+
category_inputs.append(gr.Textbox(label=q_text))
|
215 |
+
|
216 |
+
blog_checkbox = gr.Checkbox(label="๐ I'd like to write a mini blog about myself")
|
217 |
+
blog_text = gr.Textbox(lines=5, label="โ๏ธ Mini Blog", visible=False)
|
218 |
+
|
219 |
+
blog_checkbox.change(fn=lambda x: gr.update(visible=x), inputs=blog_checkbox, outputs=blog_text)
|
220 |
+
|
221 |
+
submit = gr.Button("๐๏ธ Save My Profile")
|
222 |
+
output = gr.Textbox(label="Status")
|
223 |
+
|
224 |
+
submit.click(fn=save_profile,
|
225 |
+
inputs=[file, *quiz_components, blog_checkbox, blog_text, *category_inputs],
|
226 |
+
outputs=[output])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
227 |
|
228 |
if __name__ == '__main__':
|
229 |
demo.launch()
|