Dannyar608 commited on
Commit
ba0cf2b
Β·
verified Β·
1 Parent(s): 84b76ed

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +59 -95
app.py CHANGED
@@ -116,114 +116,78 @@ 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", [])
123
- gpa = info.get("GPA", "N/A")
124
- return f"""
125
- πŸ“˜ **Personalized Learning Plan**
126
- - Grade Level: {level}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
127
  - GPA: {gpa}
128
- - Suggested Focus Areas: {', '.join(courses[:3]) if courses else 'N/A'}
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
- 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,
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
- with gr.Column():
202
- gr.Markdown("### 🧠 Learning Style Discovery")
203
- quiz_components = []
204
- for i, (question, options) in enumerate(zip(learning_style_questions, learning_style_answers)):
205
- quiz_components.append(gr.Radio(
206
- choices=options,
207
- label=f"{i+1}. {question}"
208
- ))
209
 
210
- category_inputs = []
211
- for category, questions in get_to_know_categories.items():
212
- gr.Markdown(f"### πŸ“˜ {category}")
213
- for q_text, _ in questions:
214
- category_inputs.append(gr.Textbox(label=q_text))
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")
222
- output = gr.Textbox(label="Status")
 
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()