Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -116,114 +116,78 @@ get_to_know_categories = {
|
|
116 |
]
|
117 |
}
|
118 |
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
127 |
- GPA: {gpa}
|
128 |
-
-
|
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 |
-
|
156 |
-
|
157 |
-
category_answers = inputs[len(learning_style_questions)+2:]
|
158 |
|
159 |
-
|
160 |
-
|
161 |
|
162 |
-
|
163 |
-
|
164 |
|
165 |
-
|
166 |
-
transcript_info = extract_transcript_info(df)
|
167 |
-
learning_type = learning_style_quiz(*quiz_answers)
|
168 |
|
169 |
-
|
170 |
-
|
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 |
-
|
202 |
-
|
203 |
-
|
204 |
-
|
205 |
-
|
206 |
-
|
207 |
-
|
208 |
-
))
|
209 |
|
210 |
-
|
211 |
-
|
212 |
-
gr.Markdown(f"### π {category}")
|
213 |
-
for q_text, _ in questions:
|
214 |
-
category_inputs.append(gr.Textbox(label=q_text))
|
215 |
|
216 |
-
|
217 |
-
|
218 |
|
219 |
-
|
|
|
220 |
|
221 |
-
|
222 |
-
|
|
|
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()
|
|
|
116 |
]
|
117 |
}
|
118 |
|
119 |
+
def display_saved_profile():
|
120 |
+
try:
|
121 |
+
with open("student_profile.json", "r") as f:
|
122 |
+
profile = json.load(f)
|
123 |
+
except FileNotFoundError:
|
124 |
+
return "β οΈ No profile data found."
|
125 |
+
|
126 |
+
transcript_info = profile.get("transcript_info", {})
|
127 |
+
gpa = transcript_info.get("GPA", "N/A")
|
128 |
+
grade = transcript_info.get("Grade_Level", "N/A")
|
129 |
+
courses = transcript_info.get("Courses", [])
|
130 |
+
|
131 |
+
past_classes = [{'Course': course, 'Grade': 'A'} for course in courses[:max(len(courses)-2, 0)]]
|
132 |
+
current_classes = [{'Course': course, 'Grade': 'IP'} for course in courses[-2:]]
|
133 |
+
|
134 |
+
all_classes_df = pd.DataFrame(past_classes + current_classes)
|
135 |
+
|
136 |
+
learning_type = profile.get("learning_style", "N/A")
|
137 |
+
responses = profile.get("get_to_know_answers", {})
|
138 |
+
blog = profile.get("blog", "[User skipped this section]")
|
139 |
+
|
140 |
+
comments = [f"β I love how you spend your free time: {responses.get('Whatβs your favorite way to spend a day off?', 'N/A')}.",
|
141 |
+
f"π {responses.get('If you could only eat one food for the rest of your life, what would it be?', 'N/A')} sounds delicious!",
|
142 |
+
f"π¬ You mentioned {responses.get('What are some of your favorite movies or shows?', 'N/A')}. Great picks!"]
|
143 |
+
|
144 |
+
blog_comment = ""
|
145 |
+
if blog and blog != "[User chose to skip this section]":
|
146 |
+
blog_comment = f"π Your blog was very thoughtful! You wrote: \"{blog[:150]}...\""
|
147 |
+
|
148 |
+
summary_text = f"""
|
149 |
+
π€ **Student Overview**
|
150 |
+
- Name: Extracted from transcript (if available)
|
151 |
- GPA: {gpa}
|
152 |
+
- Grade Level: {grade}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
153 |
|
154 |
+
π **Courses**
|
155 |
+
{all_classes_df.to_markdown(index=False)}
|
|
|
156 |
|
157 |
+
π§ **Learning Type**
|
158 |
+
Based on your answers, your learning style is: **{learning_type}**
|
159 |
|
160 |
+
π¬ **Personal Reflections**
|
161 |
+
{chr(10).join(comments)}
|
162 |
|
163 |
+
{blog_comment}
|
|
|
|
|
164 |
|
165 |
+
β Is all this information correct?
|
166 |
+
"""
|
167 |
+
return summary_text
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
168 |
|
|
|
|
|
169 |
|
170 |
+
# Gradio confirmation block
|
171 |
+
with gr.Blocks() as review_block:
|
172 |
+
gr.Markdown("## β
Profile Review & Confirmation")
|
173 |
+
summary_output = gr.Markdown()
|
174 |
+
confirm_btn = gr.Button("Yes, everything is correct")
|
175 |
+
correct_btn = gr.Button("No, I need to make changes")
|
176 |
+
final_status = gr.Textbox(label="Final Status")
|
|
|
177 |
|
178 |
+
def confirm_review():
|
179 |
+
return display_saved_profile()
|
|
|
|
|
|
|
180 |
|
181 |
+
def finalize():
|
182 |
+
return "π All set! You're ready to move forward."
|
183 |
|
184 |
+
def ask_to_correct():
|
185 |
+
return "π Okay! Please update the necessary information and save again."
|
186 |
|
187 |
+
confirm_btn.click(fn=finalize, outputs=[final_status])
|
188 |
+
correct_btn.click(fn=ask_to_correct, outputs=[final_status])
|
189 |
+
demo.load(fn=confirm_review, outputs=[summary_output]) # Automatically load profile on page reload
|
190 |
|
|
|
|
|
|
|
191 |
|
192 |
if __name__ == '__main__':
|
193 |
demo.launch()
|