Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -27,7 +27,7 @@ def extract_transcript_info(df):
|
|
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
|
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)
|
@@ -110,17 +110,28 @@ get_to_know_categories = {
|
|
110 |
|
111 |
# Save all answers into profile
|
112 |
def save_profile(file, *inputs):
|
|
|
|
|
|
|
113 |
quiz_answers = inputs[:len(learning_style_questions)]
|
114 |
-
|
115 |
-
|
|
|
|
|
|
|
|
|
|
|
116 |
|
117 |
-
if
|
118 |
-
return "
|
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,14 +139,15 @@ def save_profile(file, *inputs):
|
|
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
|
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:
|
@@ -149,26 +161,28 @@ with gr.Blocks() as demo:
|
|
149 |
quiz_components = []
|
150 |
for i, (question, options) in enumerate(zip(learning_style_questions, learning_style_answers)):
|
151 |
quiz_components.append(gr.Radio(
|
152 |
-
choices=
|
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,
|
171 |
outputs=[output])
|
172 |
|
173 |
if __name__ == '__main__':
|
174 |
-
demo.launch()
|
|
|
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)
|
|
|
110 |
|
111 |
# Save all answers into profile
|
112 |
def save_profile(file, *inputs):
|
113 |
+
if not file:
|
114 |
+
return "β οΈ Please upload your transcript."
|
115 |
+
|
116 |
quiz_answers = inputs[:len(learning_style_questions)]
|
117 |
+
if any(ans is None for ans in quiz_answers):
|
118 |
+
return "β οΈ Please answer all the learning style questions."
|
119 |
+
|
120 |
+
about_me = inputs[len(learning_style_questions)]
|
121 |
+
blog_opt_in = inputs[len(learning_style_questions)+1]
|
122 |
+
blog_text = inputs[len(learning_style_questions)+2]
|
123 |
+
category_answers = inputs[len(learning_style_questions)+3:]
|
124 |
|
125 |
+
if any(ans.strip() == "" for ans in category_answers):
|
126 |
+
return "β οΈ Please complete all 'Get to Know You' sections before saving."
|
127 |
|
128 |
df = parse_transcript(file)
|
129 |
transcript_info = extract_transcript_info(df)
|
130 |
learning_type = learning_style_quiz(*quiz_answers)
|
131 |
|
132 |
+
if not blog_opt_in and blog_text.strip() == "":
|
133 |
+
blog_text = "[User chose to skip this section]"
|
134 |
+
|
135 |
question_texts = [q for cat in get_to_know_categories.values() for q, _ in cat]
|
136 |
responses = dict(zip(question_texts, category_answers))
|
137 |
|
|
|
139 |
"transcript": df.to_dict(orient='records'),
|
140 |
"transcript_info": transcript_info,
|
141 |
"learning_style": learning_type,
|
142 |
+
"about_me": about_me,
|
143 |
"get_to_know_answers": responses,
|
144 |
+
"blog": blog_text
|
145 |
}
|
146 |
|
147 |
with open("student_profile.json", "w") as f:
|
148 |
json.dump(profile, f, indent=4)
|
149 |
|
150 |
+
return f"β
Profile saved! Your learning style is: {learning_type}"
|
151 |
|
152 |
# Build Gradio UI
|
153 |
with gr.Blocks() as demo:
|
|
|
161 |
quiz_components = []
|
162 |
for i, (question, options) in enumerate(zip(learning_style_questions, learning_style_answers)):
|
163 |
quiz_components.append(gr.Radio(
|
164 |
+
choices=["visual", "auditory", "reading/writing"],
|
165 |
+
label=f"{i+1}. {question}"
|
|
|
166 |
))
|
167 |
|
168 |
+
with gr.Column():
|
169 |
+
gr.Markdown("### β€οΈ About You")
|
170 |
+
about_me = gr.Textbox(lines=6, label="About Me")
|
171 |
+
blog_opt_in = gr.Checkbox(label="I want to write a personal blog for better personalization")
|
172 |
+
blog_text = gr.Textbox(lines=5, label="βοΈ Optional: Write a mini blog about your life", visible=True)
|
173 |
+
|
174 |
category_inputs = []
|
175 |
for category, questions in get_to_know_categories.items():
|
176 |
gr.Markdown(f"### π {category}")
|
177 |
for q_text, _ in questions:
|
178 |
category_inputs.append(gr.Textbox(label=q_text))
|
179 |
|
|
|
|
|
|
|
180 |
submit = gr.Button("π₯ Save My Profile")
|
181 |
output = gr.Textbox(label="Status")
|
182 |
|
183 |
submit.click(fn=save_profile,
|
184 |
+
inputs=[file, *quiz_components, about_me, blog_opt_in, blog_text, *category_inputs],
|
185 |
outputs=[output])
|
186 |
|
187 |
if __name__ == '__main__':
|
188 |
+
demo.launch()
|