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,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?", []),
|
@@ -162,27 +158,57 @@ Based on your answers, your learning style is: **{learning_type}**
|
|
162 |
return summary_text
|
163 |
|
164 |
|
165 |
-
#
|
166 |
-
with gr.Blocks() as
|
167 |
-
gr.
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
186 |
|
187 |
if __name__ == '__main__':
|
188 |
-
|
|
|
35 |
info['Courses'] = list(set([c[0].strip() for c in courses]))
|
36 |
return info
|
37 |
|
38 |
+
# Learning style quiz
|
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 |
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?", []),
|
|
|
158 |
return summary_text
|
159 |
|
160 |
|
161 |
+
# Interface
|
162 |
+
with gr.Blocks() as demo:
|
163 |
+
profile_interface = gr.Column(visible=True)
|
164 |
+
confirmation_interface = gr.Column(visible=False)
|
165 |
+
|
166 |
+
with profile_interface:
|
167 |
+
gr.Markdown("## โ๏ธ Create Your Profile")
|
168 |
+
transcript_input = gr.File(label="Upload Transcript (.csv, .xlsx, or .pdf)")
|
169 |
+
ls_dropdowns = [gr.Dropdown(choices=learning_style_answers[i], label=learning_style_questions[i]) for i in range(10)]
|
170 |
+
get_to_know_inputs = {}
|
171 |
+
for section, questions in get_to_know_categories.items():
|
172 |
+
gr.Markdown(f"### {section}")
|
173 |
+
for q, _ in questions:
|
174 |
+
get_to_know_inputs[q] = gr.Textbox(label=q)
|
175 |
+
blog_input = gr.Textbox(label="Write a short blog about yourself (optional)", lines=5)
|
176 |
+
save_btn = gr.Button("Save Profile")
|
177 |
+
|
178 |
+
with confirmation_interface:
|
179 |
+
gr.Markdown("## โ
Profile Review & Confirmation")
|
180 |
+
summary_output = gr.Markdown()
|
181 |
+
confirm_btn = gr.Button("Yes, everything is correct")
|
182 |
+
correct_btn = gr.Button("No, I need to make changes")
|
183 |
+
final_status = gr.Textbox(label="Final Status")
|
184 |
+
|
185 |
+
def save_profile(transcript_file, *answers):
|
186 |
+
df = parse_transcript(transcript_file)
|
187 |
+
transcript_info = extract_transcript_info(df)
|
188 |
+
learning_result = learning_style_quiz(*answers[:10])
|
189 |
+
personal_responses = {q: ans for q, ans in zip(get_to_know_inputs.keys(), answers[10:-1])}
|
190 |
+
blog_text = answers[-1]
|
191 |
+
|
192 |
+
student_data = {
|
193 |
+
"transcript_info": transcript_info,
|
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()
|