Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -66,7 +66,6 @@ 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]
|
@@ -74,13 +73,10 @@ def learning_style_quiz(*answers):
|
|
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,7 +112,6 @@ get_to_know_categories = {
|
|
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", [])
|
@@ -143,32 +138,25 @@ Your dreams are powerful: {'; '.join(hopes) if hopes else 'You are filled with p
|
|
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,
|
@@ -176,25 +164,28 @@ def save_profile(file, *inputs):
|
|
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 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
|
@@ -215,7 +206,6 @@ with gr.Blocks() as demo:
|
|
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")
|
@@ -223,7 +213,11 @@ with gr.Blocks() as demo:
|
|
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()
|
|
|
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 |
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 |
]
|
113 |
}
|
114 |
|
|
|
115 |
def generate_learning_plan(info):
|
116 |
level = info.get("Grade_Level", "unknown")
|
117 |
courses = info.get("Courses", [])
|
|
|
138 |
Believe in yourself and keep moving forward.
|
139 |
"""
|
140 |
|
|
|
141 |
def save_profile(file, *inputs):
|
142 |
if not file:
|
143 |
+
return "⚠️ Please upload your transcript.", False
|
|
|
144 |
quiz_answers = inputs[:len(learning_style_questions)]
|
145 |
if any(ans is None for ans in quiz_answers):
|
146 |
+
return "⚠️ Please answer all the learning style questions.", False
|
|
|
147 |
blog_checkbox = inputs[len(learning_style_questions)]
|
148 |
blog_text = inputs[len(learning_style_questions)+1]
|
149 |
category_answers = inputs[len(learning_style_questions)+2:]
|
|
|
150 |
if any(ans.strip() == "" for ans in category_answers):
|
151 |
+
return "⚠️ Please complete all 'Get to Know You' sections before saving.", False
|
|
|
152 |
if blog_checkbox and blog_text.strip() == "":
|
153 |
+
return "⚠️ You checked the blog option but didn’t write anything. Please write your mini blog or uncheck the option.", False
|
154 |
|
155 |
df = parse_transcript(file)
|
156 |
transcript_info = extract_transcript_info(df)
|
157 |
learning_type = learning_style_quiz(*quiz_answers)
|
|
|
158 |
question_texts = [q for cat in get_to_know_categories.values() for q, _ in cat]
|
159 |
responses = dict(zip(question_texts, category_answers))
|
|
|
160 |
profile = {
|
161 |
"transcript": df.to_dict(orient='records'),
|
162 |
"transcript_info": transcript_info,
|
|
|
164 |
"get_to_know_answers": responses,
|
165 |
"blog": blog_text if blog_checkbox else "[User chose to skip this section]"
|
166 |
}
|
|
|
167 |
summary = {
|
168 |
"Learning_Plan": generate_learning_plan(transcript_info),
|
169 |
"Style_Summary": generate_learning_style_summary(learning_type),
|
170 |
"Motivation": generate_motivation_section(responses)
|
171 |
}
|
|
|
172 |
with open("student_profile.json", "w") as f:
|
173 |
json.dump(profile, f, indent=4)
|
|
|
174 |
with open("student_summary.md", "w") as f:
|
175 |
f.write(summary["Learning_Plan"] + '\n' + summary["Style_Summary"] + '\n' + summary["Motivation"])
|
176 |
+
return f"✅ Profile saved! Your learning style is: {learning_type}", True
|
177 |
|
178 |
+
def hide_ui():
|
179 |
+
updates = []
|
180 |
+
updates.append(gr.update(visible=False)) # for file upload
|
181 |
+
updates.extend([gr.update(visible=False) for _ in range(len(learning_style_questions))])
|
182 |
+
updates.append(gr.update(visible=False)) # blog checkbox
|
183 |
+
updates.append(gr.update(visible=False)) # blog text
|
184 |
+
updates.extend([gr.update(visible=False) for _ in range(sum(len(v) for v in get_to_know_categories.values()))])
|
185 |
+
return updates
|
186 |
|
|
|
187 |
with gr.Blocks() as demo:
|
188 |
gr.Markdown("## 🎓 Personalized AI Student Assistant")
|
|
|
189 |
with gr.Row():
|
190 |
file = gr.File(label="📄 Upload Your Transcript (.csv, .xlsx, .pdf)")
|
191 |
|
|
|
206 |
|
207 |
blog_checkbox = gr.Checkbox(label="📝 I'd like to write a mini blog about myself")
|
208 |
blog_text = gr.Textbox(lines=5, label="✍️ Mini Blog", visible=False)
|
|
|
209 |
blog_checkbox.change(fn=lambda x: gr.update(visible=x), inputs=blog_checkbox, outputs=blog_text)
|
210 |
|
211 |
submit = gr.Button("🗕️ Save My Profile")
|
|
|
213 |
|
214 |
submit.click(fn=save_profile,
|
215 |
inputs=[file, *quiz_components, blog_checkbox, blog_text, *category_inputs],
|
216 |
+
outputs=[output, gr.State()])
|
217 |
+
|
218 |
+
submit.click(fn=hide_ui,
|
219 |
+
inputs=[],
|
220 |
+
outputs=[file, *quiz_components, blog_checkbox, blog_text, *category_inputs])
|
221 |
|
222 |
if __name__ == '__main__':
|
223 |
+
demo.launch()
|