Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -111,18 +111,16 @@ get_to_know_categories = {
|
|
111 |
# Save all answers into profile
|
112 |
def save_profile(file, *inputs):
|
113 |
quiz_answers = inputs[:len(learning_style_questions)]
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
|
|
118 |
|
119 |
df = parse_transcript(file)
|
120 |
transcript_info = extract_transcript_info(df)
|
121 |
learning_type = learning_style_quiz(*quiz_answers)
|
122 |
|
123 |
-
if not blog_opt_in and blog_text.strip() == "":
|
124 |
-
blog_text = "[User chose to skip this section]"
|
125 |
-
|
126 |
question_texts = [q for cat in get_to_know_categories.values() for q, _ in cat]
|
127 |
responses = dict(zip(question_texts, category_answers))
|
128 |
|
@@ -130,15 +128,14 @@ def save_profile(file, *inputs):
|
|
130 |
"transcript": df.to_dict(orient='records'),
|
131 |
"transcript_info": transcript_info,
|
132 |
"learning_style": learning_type,
|
133 |
-
"about_me": about_me,
|
134 |
"get_to_know_answers": responses,
|
135 |
-
"blog": blog_text
|
136 |
}
|
137 |
|
138 |
with open("student_profile.json", "w") as f:
|
139 |
json.dump(profile, f, indent=4)
|
140 |
|
141 |
-
return f"β
Profile saved! Your learning style is: {learning_type}"
|
142 |
|
143 |
# Build Gradio UI
|
144 |
with gr.Blocks() as demo:
|
@@ -153,26 +150,24 @@ with gr.Blocks() as demo:
|
|
153 |
for i, (question, options) in enumerate(zip(learning_style_questions, learning_style_answers)):
|
154 |
quiz_components.append(gr.Radio(
|
155 |
choices=options,
|
156 |
-
label=f"{i+1}. {question}"
|
|
|
157 |
))
|
158 |
|
159 |
-
with gr.Column():
|
160 |
-
gr.Markdown("### β€οΈ About You")
|
161 |
-
about_me = gr.Textbox(lines=6, label="Answer a few questions: \n1. Whatβs a fun fact about you? \n2. Favorite music/artist? \n3. Your dream job?")
|
162 |
-
blog_opt_in = gr.Checkbox(label="I want to write a personal blog for better personalization")
|
163 |
-
blog_text = gr.Textbox(lines=5, label="βοΈ Optional: Write a mini blog about your life", visible=True)
|
164 |
-
|
165 |
category_inputs = []
|
166 |
for category, questions in get_to_know_categories.items():
|
167 |
gr.Markdown(f"### π {category}")
|
168 |
for q_text, _ in questions:
|
169 |
category_inputs.append(gr.Textbox(label=q_text))
|
170 |
|
|
|
|
|
|
|
171 |
submit = gr.Button("π₯ Save My Profile")
|
172 |
output = gr.Textbox(label="Status")
|
173 |
|
174 |
submit.click(fn=save_profile,
|
175 |
-
inputs=[file, *quiz_components,
|
176 |
outputs=[output])
|
177 |
|
178 |
if __name__ == '__main__':
|
|
|
111 |
# Save all answers into profile
|
112 |
def save_profile(file, *inputs):
|
113 |
quiz_answers = inputs[:len(learning_style_questions)]
|
114 |
+
category_answers = inputs[len(learning_style_questions):-1]
|
115 |
+
blog_text = inputs[-1]
|
116 |
+
|
117 |
+
if None in inputs or file is None:
|
118 |
+
return "β Please complete all sections before saving."
|
119 |
|
120 |
df = parse_transcript(file)
|
121 |
transcript_info = extract_transcript_info(df)
|
122 |
learning_type = learning_style_quiz(*quiz_answers)
|
123 |
|
|
|
|
|
|
|
124 |
question_texts = [q for cat in get_to_know_categories.values() for q, _ in cat]
|
125 |
responses = dict(zip(question_texts, category_answers))
|
126 |
|
|
|
128 |
"transcript": df.to_dict(orient='records'),
|
129 |
"transcript_info": transcript_info,
|
130 |
"learning_style": learning_type,
|
|
|
131 |
"get_to_know_answers": responses,
|
132 |
+
"blog": blog_text.strip() if blog_text.strip() != "" else "[User skipped blog]"
|
133 |
}
|
134 |
|
135 |
with open("student_profile.json", "w") as f:
|
136 |
json.dump(profile, f, indent=4)
|
137 |
|
138 |
+
return f"β
Profile saved! Your learning style is: {learning_type}."
|
139 |
|
140 |
# Build Gradio UI
|
141 |
with gr.Blocks() as demo:
|
|
|
150 |
for i, (question, options) in enumerate(zip(learning_style_questions, learning_style_answers)):
|
151 |
quiz_components.append(gr.Radio(
|
152 |
choices=options,
|
153 |
+
label=f"{i+1}. {question}",
|
154 |
+
type="value"
|
155 |
))
|
156 |
|
|
|
|
|
|
|
|
|
|
|
|
|
157 |
category_inputs = []
|
158 |
for category, questions in get_to_know_categories.items():
|
159 |
gr.Markdown(f"### π {category}")
|
160 |
for q_text, _ in questions:
|
161 |
category_inputs.append(gr.Textbox(label=q_text))
|
162 |
|
163 |
+
gr.Markdown("### π Optional Blog")
|
164 |
+
blog_text = gr.Textbox(label="Would you like to share a bit more about yourself? Write a short blog.", lines=6)
|
165 |
+
|
166 |
submit = gr.Button("π₯ Save My Profile")
|
167 |
output = gr.Textbox(label="Status")
|
168 |
|
169 |
submit.click(fn=save_profile,
|
170 |
+
inputs=[file, *quiz_components, *category_inputs, blog_text],
|
171 |
outputs=[output])
|
172 |
|
173 |
if __name__ == '__main__':
|