Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -6,7 +6,7 @@ import re
|
|
6 |
from PyPDF2 import PdfReader
|
7 |
from collections import defaultdict
|
8 |
|
9 |
-
# ========== TRANSCRIPT PARSING FUNCTIONS
|
10 |
def extract_courses_with_grade_levels(text):
|
11 |
grade_level_pattern = r"(Grade|Year)\s*[:]?\s*(\d+|Freshman|Sophomore|Junior|Senior)"
|
12 |
grade_match = re.search(grade_level_pattern, text, re.IGNORECASE)
|
@@ -132,8 +132,90 @@ def parse_transcript(file):
|
|
132 |
"courses": courses
|
133 |
}
|
134 |
|
135 |
-
# ==========
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
136 |
|
|
|
137 |
def save_profile(name, age, interests, transcript, learning_style, favorites, blog):
|
138 |
data = {
|
139 |
"name": name,
|
@@ -150,20 +232,16 @@ def save_profile(name, age, interests, transcript, learning_style, favorites, bl
|
|
150 |
json.dump(data, f, indent=2)
|
151 |
|
152 |
markdown_summary = f"""### Student Profile: {name}
|
153 |
-
|
154 |
**Age:** {age}
|
155 |
**Interests:** {interests}
|
156 |
**Learning Style:** {learning_style}
|
157 |
-
|
158 |
#### Transcript:
|
159 |
{transcript_display(transcript)}
|
160 |
-
|
161 |
#### Favorites:
|
162 |
- Movie: {favorites['movie']} ({favorites['movie_reason']})
|
163 |
- Show: {favorites['show']} ({favorites['show_reason']})
|
164 |
- Book: {favorites['book']} ({favorites['book_reason']})
|
165 |
- Character: {favorites['character']} ({favorites['character_reason']})
|
166 |
-
|
167 |
#### Blog:
|
168 |
{blog if blog else "_No blog provided_"}
|
169 |
"""
|
@@ -186,7 +264,6 @@ def transcript_display(transcript_dict):
|
|
186 |
[f"Grade Level: {transcript_dict['grade_level']}", f"GPA: {transcript_dict['gpa']}"])
|
187 |
|
188 |
# ========== GRADIO INTERFACE ==========
|
189 |
-
|
190 |
with gr.Blocks() as app:
|
191 |
with gr.Tab("Step 1: Upload Transcript"):
|
192 |
transcript_file = gr.File(label="Upload your transcript (CSV, Excel, or PDF)")
|
@@ -195,17 +272,19 @@ with gr.Blocks() as app:
|
|
195 |
transcript_file.change(fn=parse_transcript, inputs=transcript_file, outputs=[transcript_output, transcript_data])
|
196 |
|
197 |
with gr.Tab("Step 2: Learning Style Quiz"):
|
198 |
-
|
199 |
-
|
200 |
-
|
201 |
-
|
202 |
-
|
203 |
-
|
204 |
-
|
205 |
-
|
206 |
-
|
207 |
-
|
208 |
-
|
|
|
|
|
209 |
|
210 |
with gr.Tab("Step 3: Personal Questions"):
|
211 |
name = gr.Textbox(label="What's your name?")
|
@@ -228,7 +307,7 @@ with gr.Blocks() as app:
|
|
228 |
save_btn = gr.Button("Save Profile")
|
229 |
|
230 |
def gather_and_save(name, age, interests, movie, movie_reason, show, show_reason,
|
231 |
-
|
232 |
favorites = {
|
233 |
"movie": movie,
|
234 |
"movie_reason": movie_reason,
|
@@ -242,9 +321,9 @@ with gr.Blocks() as app:
|
|
242 |
return save_profile(name, age, interests, transcript, learning_style, favorites, blog)
|
243 |
|
244 |
save_btn.click(fn=gather_and_save,
|
245 |
-
|
246 |
-
|
247 |
-
|
248 |
-
|
249 |
|
250 |
app.launch()
|
|
|
6 |
from PyPDF2 import PdfReader
|
7 |
from collections import defaultdict
|
8 |
|
9 |
+
# ========== TRANSCRIPT PARSING FUNCTIONS ==========
|
10 |
def extract_courses_with_grade_levels(text):
|
11 |
grade_level_pattern = r"(Grade|Year)\s*[:]?\s*(\d+|Freshman|Sophomore|Junior|Senior)"
|
12 |
grade_match = re.search(grade_level_pattern, text, re.IGNORECASE)
|
|
|
132 |
"courses": courses
|
133 |
}
|
134 |
|
135 |
+
# ========== LEARNING STYLE QUIZ ==========
|
136 |
+
learning_style_questions = [
|
137 |
+
"When you study for a test, you prefer to:",
|
138 |
+
"When you need directions to a new place, you prefer:",
|
139 |
+
"When you learn a new skill, you prefer to:",
|
140 |
+
"When you're trying to concentrate, you:",
|
141 |
+
"When you meet new people, you remember them by:",
|
142 |
+
"When you're relaxing, you prefer to:",
|
143 |
+
"When you're explaining something to someone, you:",
|
144 |
+
"When you're trying to remember something, you:",
|
145 |
+
"When you're in a classroom, you learn best when:",
|
146 |
+
"When you're trying to solve a problem, you:",
|
147 |
+
"When you're taking notes, you:",
|
148 |
+
"When you're learning new software, you prefer to:",
|
149 |
+
"When you're at a museum, you spend the most time:",
|
150 |
+
"When you're assembling furniture, you:",
|
151 |
+
"When you're learning new vocabulary, you:",
|
152 |
+
"When you're giving a presentation, you prefer:",
|
153 |
+
"When you're at a party, you enjoy:",
|
154 |
+
"When you're taking a break from studying, you:",
|
155 |
+
"When you're learning dance moves, you:",
|
156 |
+
"When you're choosing a book, you prefer:"
|
157 |
+
]
|
158 |
+
|
159 |
+
learning_style_options = [
|
160 |
+
["Read the textbook (Reading/Writing)", "Listen to lectures (Auditory)", "Use diagrams/charts (Visual)", "Practice problems (Kinesthetic)"],
|
161 |
+
["Look at a map (Visual)", "Have someone tell you (Auditory)", "Write down directions (Reading/Writing)", "Try walking/driving there (Kinesthetic)"],
|
162 |
+
["Read instructions (Reading/Writing)", "Have someone show you (Visual)", "Listen to explanations (Auditory)", "Try it yourself (Kinesthetic)"],
|
163 |
+
["Need quiet (Reading/Writing)", "Need background noise (Auditory)", "Need to move around (Kinesthetic)", "Need visual stimulation (Visual)"],
|
164 |
+
["Their face (Visual)", "Their name (Auditory)", "What you talked about (Reading/Writing)", "What you did together (Kinesthetic)"],
|
165 |
+
["Read (Reading/Writing)", "Listen to music (Auditory)", "Watch TV (Visual)", "Do something active (Kinesthetic)"],
|
166 |
+
["Write it down (Reading/Writing)", "Tell them verbally (Auditory)", "Show them (Visual)", "Demonstrate physically (Kinesthetic)"],
|
167 |
+
["See it written down (Visual)", "Say it out loud (Auditory)", "Write it down (Reading/Writing)", "Do it physically (Kinesthetic)"],
|
168 |
+
["Reading materials (Reading/Writing)", "Listening to lectures (Auditory)", "Seeing diagrams (Visual)", "Doing hands-on activities (Kinesthetic)"],
|
169 |
+
["Write down steps (Reading/Writing)", "Talk through it (Auditory)", "Draw diagrams (Visual)", "Try different approaches (Kinesthetic)"],
|
170 |
+
["Write detailed notes (Reading/Writing)", "Record lectures (Auditory)", "Draw mind maps (Visual)", "Take minimal notes (Kinesthetic)"],
|
171 |
+
["Read the manual (Reading/Writing)", "Have someone explain it (Auditory)", "Watch tutorial videos (Visual)", "Just start using it (Kinesthetic)"],
|
172 |
+
["Reading descriptions (Reading/Writing)", "Listening to audio guides (Auditory)", "Looking at exhibits (Visual)", "Interactive displays (Kinesthetic)"],
|
173 |
+
["Read instructions first (Reading/Writing)", "Ask someone to help (Auditory)", "Look at diagrams (Visual)", "Start assembling (Kinesthetic)"],
|
174 |
+
["Write them repeatedly (Reading/Writing)", "Say them repeatedly (Auditory)", "Use flashcards (Visual)", "Use them in conversation (Kinesthetic)"],
|
175 |
+
["Having detailed notes (Reading/Writing)", "Speaking freely (Auditory)", "Using visual aids (Visual)", "Demonstrating something (Kinesthetic)"],
|
176 |
+
["Conversations (Auditory)", "People-watching (Visual)", "Dancing/games (Kinesthetic)", "Reading about people (Reading/Writing)"],
|
177 |
+
["Read for fun (Reading/Writing)", "Listen to music (Auditory)", "Watch videos (Visual)", "Exercise (Kinesthetic)"],
|
178 |
+
["Watch demonstrations (Visual)", "Listen to instructions (Auditory)", "Read choreography (Reading/Writing)", "Try the moves (Kinesthetic)"],
|
179 |
+
["Text-heavy books (Reading/Writing)", "Audiobooks (Auditory)", "Books with pictures (Visual)", "Interactive books (Kinesthetic)"]
|
180 |
+
]
|
181 |
+
|
182 |
+
def learning_style_quiz(*answers):
|
183 |
+
scores = {
|
184 |
+
"Visual": 0,
|
185 |
+
"Auditory": 0,
|
186 |
+
"Reading/Writing": 0,
|
187 |
+
"Kinesthetic": 0
|
188 |
+
}
|
189 |
+
|
190 |
+
# Map each answer to a learning style
|
191 |
+
for i, answer in enumerate(answers):
|
192 |
+
if answer in learning_style_options[i][0]:
|
193 |
+
scores["Reading/Writing"] += 1
|
194 |
+
elif answer in learning_style_options[i][1]:
|
195 |
+
scores["Auditory"] += 1
|
196 |
+
elif answer in learning_style_options[i][2]:
|
197 |
+
scores["Visual"] += 1
|
198 |
+
elif answer in learning_style_options[i][3]:
|
199 |
+
scores["Kinesthetic"] += 1
|
200 |
+
|
201 |
+
# Get the highest score(s)
|
202 |
+
max_score = max(scores.values())
|
203 |
+
dominant_styles = [style for style, score in scores.items() if score == max_score]
|
204 |
+
|
205 |
+
# Generate result
|
206 |
+
if len(dominant_styles) == 1:
|
207 |
+
result = f"Your primary learning style is: {dominant_styles[0]}"
|
208 |
+
else:
|
209 |
+
result = f"You have multiple strong learning styles: {', '.join(dominant_styles)}"
|
210 |
+
|
211 |
+
# Add detailed breakdown
|
212 |
+
result += "\n\nDetailed Scores:\n"
|
213 |
+
for style, score in sorted(scores.items(), key=lambda x: x[1], reverse=True):
|
214 |
+
result += f"{style}: {score}/20\n"
|
215 |
+
|
216 |
+
return result
|
217 |
|
218 |
+
# ========== SAVE STUDENT PROFILE FUNCTION ==========
|
219 |
def save_profile(name, age, interests, transcript, learning_style, favorites, blog):
|
220 |
data = {
|
221 |
"name": name,
|
|
|
232 |
json.dump(data, f, indent=2)
|
233 |
|
234 |
markdown_summary = f"""### Student Profile: {name}
|
|
|
235 |
**Age:** {age}
|
236 |
**Interests:** {interests}
|
237 |
**Learning Style:** {learning_style}
|
|
|
238 |
#### Transcript:
|
239 |
{transcript_display(transcript)}
|
|
|
240 |
#### Favorites:
|
241 |
- Movie: {favorites['movie']} ({favorites['movie_reason']})
|
242 |
- Show: {favorites['show']} ({favorites['show_reason']})
|
243 |
- Book: {favorites['book']} ({favorites['book_reason']})
|
244 |
- Character: {favorites['character']} ({favorites['character_reason']})
|
|
|
245 |
#### Blog:
|
246 |
{blog if blog else "_No blog provided_"}
|
247 |
"""
|
|
|
264 |
[f"Grade Level: {transcript_dict['grade_level']}", f"GPA: {transcript_dict['gpa']}"])
|
265 |
|
266 |
# ========== GRADIO INTERFACE ==========
|
|
|
267 |
with gr.Blocks() as app:
|
268 |
with gr.Tab("Step 1: Upload Transcript"):
|
269 |
transcript_file = gr.File(label="Upload your transcript (CSV, Excel, or PDF)")
|
|
|
272 |
transcript_file.change(fn=parse_transcript, inputs=transcript_file, outputs=[transcript_output, transcript_data])
|
273 |
|
274 |
with gr.Tab("Step 2: Learning Style Quiz"):
|
275 |
+
gr.Markdown("### Complete this 20-question quiz to determine your learning style")
|
276 |
+
quiz_components = []
|
277 |
+
for i, (question, options) in enumerate(zip(learning_style_questions, learning_style_options)):
|
278 |
+
quiz_components.append(
|
279 |
+
gr.Radio(choices=options, label=f"{i+1}. {question}")
|
280 |
+
)
|
281 |
+
|
282 |
+
learning_output = gr.Textbox(label="Learning Style Result", lines=5)
|
283 |
+
gr.Button("Submit Quiz").click(
|
284 |
+
learning_style_quiz,
|
285 |
+
inputs=quiz_components,
|
286 |
+
outputs=learning_output
|
287 |
+
)
|
288 |
|
289 |
with gr.Tab("Step 3: Personal Questions"):
|
290 |
name = gr.Textbox(label="What's your name?")
|
|
|
307 |
save_btn = gr.Button("Save Profile")
|
308 |
|
309 |
def gather_and_save(name, age, interests, movie, movie_reason, show, show_reason,
|
310 |
+
book, book_reason, character, character_reason, blog, transcript, learning_style):
|
311 |
favorites = {
|
312 |
"movie": movie,
|
313 |
"movie_reason": movie_reason,
|
|
|
321 |
return save_profile(name, age, interests, transcript, learning_style, favorites, blog)
|
322 |
|
323 |
save_btn.click(fn=gather_and_save,
|
324 |
+
inputs=[name, age, interests, movie, movie_reason, show, show_reason,
|
325 |
+
book, book_reason, character, character_reason, blog_text,
|
326 |
+
transcript_data, learning_output],
|
327 |
+
outputs=output_summary)
|
328 |
|
329 |
app.launch()
|