Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,3 +1,43 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import pandas as pd
|
| 3 |
import json
|
|
@@ -9,700 +49,14 @@ from transformers import pipeline
|
|
| 9 |
from typing import List, Dict, Union
|
| 10 |
import pdfplumber
|
| 11 |
|
| 12 |
-
|
| 13 |
-
try:
|
| 14 |
-
ner_pipeline = pipeline("ner", model="dslim/bert-base-NER")
|
| 15 |
-
except Exception as e:
|
| 16 |
-
print(f"Could not load NER model: {e}")
|
| 17 |
-
ner_pipeline = None
|
| 18 |
-
|
| 19 |
-
# ========== IMPROVED TRANSCRIPT PARSING ==========
|
| 20 |
-
class UniversalTranscriptParser:
|
| 21 |
-
def __init__(self):
|
| 22 |
-
# Patterns for different transcript types
|
| 23 |
-
self.patterns = {
|
| 24 |
-
'miami_dade': self._compile_miami_dade_patterns(),
|
| 25 |
-
'homeschool': self._compile_homeschool_patterns(),
|
| 26 |
-
'doral_academy': self._compile_doral_academy_patterns()
|
| 27 |
-
}
|
| 28 |
-
|
| 29 |
-
# Grade level mappings
|
| 30 |
-
self.grade_level_map = {
|
| 31 |
-
'09': '9th Grade', '10': '10th Grade', '11': '11th Grade', '12': '12th Grade',
|
| 32 |
-
'07': '7th Grade', '08': '8th Grade', 'MA': 'Middle School'
|
| 33 |
-
}
|
| 34 |
-
|
| 35 |
-
def parse_transcript(self, text: str) -> Dict[str, Union[Dict, List[Dict]]]:
|
| 36 |
-
"""Determine transcript type and parse accordingly"""
|
| 37 |
-
transcript_type = self._identify_transcript_type(text)
|
| 38 |
-
|
| 39 |
-
if transcript_type == 'homeschool':
|
| 40 |
-
return self._parse_homeschool(text)
|
| 41 |
-
elif transcript_type == 'doral_academy':
|
| 42 |
-
return self._parse_doral_academy(text)
|
| 43 |
-
else: # Default to Miami-Dade pattern
|
| 44 |
-
return self._parse_miami_dade(text)
|
| 45 |
-
|
| 46 |
-
def _identify_transcript_type(self, text: str) -> str:
|
| 47 |
-
"""Identify which type of transcript we're processing"""
|
| 48 |
-
if re.search(r'Sample OFFICIAL HIGH SCHOOL TRANSCRIPT', text):
|
| 49 |
-
return 'homeschool'
|
| 50 |
-
elif re.search(r'DORAL ACADEMY HIGH SCHOOL', text):
|
| 51 |
-
return 'doral_academy'
|
| 52 |
-
return 'miami_dade'
|
| 53 |
-
|
| 54 |
-
def _parse_homeschool(self, text: str) -> Dict[str, Union[Dict, List[Dict]]]:
|
| 55 |
-
"""Parse homeschool transcript format"""
|
| 56 |
-
courses = []
|
| 57 |
-
current_grade = None
|
| 58 |
-
current_year = None
|
| 59 |
-
|
| 60 |
-
# Extract student info
|
| 61 |
-
student_info = {}
|
| 62 |
-
name_match = re.search(r'Student Name:\s*(.+)\s*SSN:', text)
|
| 63 |
-
if name_match:
|
| 64 |
-
student_info['name'] = name_match.group(1).strip()
|
| 65 |
-
|
| 66 |
-
# Process each line
|
| 67 |
-
for line in text.split('\n'):
|
| 68 |
-
# Check for grade level header
|
| 69 |
-
grade_match = re.match(r'^\|?\s*(\d+th Grade)\s*\|.*(\d{4}-\d{4})', line)
|
| 70 |
-
if grade_match:
|
| 71 |
-
current_grade = grade_match.group(1)
|
| 72 |
-
current_year = grade_match.group(2)
|
| 73 |
-
continue
|
| 74 |
-
|
| 75 |
-
# Course line pattern
|
| 76 |
-
course_match = re.match(
|
| 77 |
-
r'^\|?\s*([^\|]+?)\s*\|\s*([A-Z][+*]?)\s*\|\s*([^\|]+)\s*\|\s*(\d+\.?\d*)\s*\|\s*(\d+)',
|
| 78 |
-
line
|
| 79 |
-
)
|
| 80 |
-
|
| 81 |
-
if course_match and current_grade:
|
| 82 |
-
course_name = course_match.group(1).strip()
|
| 83 |
-
# Clean course names that start with | or have extra spaces
|
| 84 |
-
course_name = re.sub(r'^\|?\s*', '', course_name)
|
| 85 |
-
|
| 86 |
-
courses.append({
|
| 87 |
-
'name': course_name,
|
| 88 |
-
'grade_level': current_grade,
|
| 89 |
-
'school_year': current_year,
|
| 90 |
-
'grade': course_match.group(2),
|
| 91 |
-
'credit_type': course_match.group(3).strip(),
|
| 92 |
-
'credits': float(course_match.group(4)),
|
| 93 |
-
'quality_points': int(course_match.group(5)),
|
| 94 |
-
'transcript_type': 'homeschool'
|
| 95 |
-
})
|
| 96 |
-
|
| 97 |
-
# Extract GPA information from homeschool transcript
|
| 98 |
-
gpa_data = {}
|
| 99 |
-
gpa_match = re.search(r'Cum\. GPA\s*\|\s*([\d\.]+)', text)
|
| 100 |
-
if gpa_match:
|
| 101 |
-
gpa_data['unweighted'] = gpa_match.group(1)
|
| 102 |
-
gpa_data['weighted'] = gpa_match.group(1) # Homeschool often has same weighted/unweighted
|
| 103 |
-
|
| 104 |
-
return {
|
| 105 |
-
'student_info': student_info,
|
| 106 |
-
'courses': {'All': courses}, # Homeschool doesn't separate by grade in same way
|
| 107 |
-
'gpa': gpa_data,
|
| 108 |
-
'grade_level': current_grade.replace('th Grade', '') if current_grade else "Unknown"
|
| 109 |
-
}
|
| 110 |
-
|
| 111 |
-
def _parse_doral_academy(self, text: str) -> Dict[str, Union[Dict, List[Dict]]]:
|
| 112 |
-
"""Parse Doral Academy specific format"""
|
| 113 |
-
courses = []
|
| 114 |
-
|
| 115 |
-
# Extract student info
|
| 116 |
-
student_info = {}
|
| 117 |
-
name_match = re.search(r'LEGAL NAME:\s*([^\n]+)', text)
|
| 118 |
-
if name_match:
|
| 119 |
-
student_info['name'] = name_match.group(1).strip()
|
| 120 |
-
|
| 121 |
-
# Extract school year information
|
| 122 |
-
year_pattern = re.compile(r'YEAR:\s*(\d{4}-\d{4})\s*GRADE LEVEL:\s*(\d{2})', re.MULTILINE)
|
| 123 |
-
year_matches = year_pattern.finditer(text)
|
| 124 |
-
|
| 125 |
-
# Create mapping of grade levels to years
|
| 126 |
-
grade_year_map = {}
|
| 127 |
-
for match in year_matches:
|
| 128 |
-
grade_year_map[match.group(2)] = match.group(1)
|
| 129 |
-
|
| 130 |
-
# Course pattern for Doral Academy
|
| 131 |
-
course_pattern = re.compile(
|
| 132 |
-
r'(\d)\s+(\d{7})\s+([^\n]+?)\s+([A-Z]{2})\s+([A-Z])\s+([A-Z])\s+([A-Z])\s+(\d\.\d{2})\s+(\d\.\d{2})',
|
| 133 |
-
re.MULTILINE
|
| 134 |
-
)
|
| 135 |
-
|
| 136 |
-
courses_by_grade = defaultdict(list)
|
| 137 |
-
for match in course_pattern.finditer(text):
|
| 138 |
-
grade_level_num = match.group(1)
|
| 139 |
-
grade_level = self.grade_level_map.get(grade_level_num, f"Grade {grade_level_num}")
|
| 140 |
-
school_year = grade_year_map.get(grade_level_num, "Unknown")
|
| 141 |
-
|
| 142 |
-
course_info = {
|
| 143 |
-
'course_code': match.group(2),
|
| 144 |
-
'name': match.group(3).strip(),
|
| 145 |
-
'subject_area': match.group(4),
|
| 146 |
-
'grade': match.group(5),
|
| 147 |
-
'inclusion_status': match.group(6),
|
| 148 |
-
'credit_status': match.group(7),
|
| 149 |
-
'credits_attempted': float(match.group(8)),
|
| 150 |
-
'credits': float(match.group(9)),
|
| 151 |
-
'grade_level': grade_level,
|
| 152 |
-
'school_year': school_year,
|
| 153 |
-
'transcript_type': 'doral_academy'
|
| 154 |
-
}
|
| 155 |
-
|
| 156 |
-
courses_by_grade[grade_level_num].append(course_info)
|
| 157 |
-
|
| 158 |
-
# Extract GPA information from Doral Academy transcript
|
| 159 |
-
gpa_data = {}
|
| 160 |
-
unweighted_match = re.search(r'Un-weighted GPA\s*([\d\.]+)', text)
|
| 161 |
-
weighted_match = re.search(r'Weighted GPA\s*([\d\.]+)', text)
|
| 162 |
-
|
| 163 |
-
if unweighted_match:
|
| 164 |
-
gpa_data['unweighted'] = unweighted_match.group(1)
|
| 165 |
-
if weighted_match:
|
| 166 |
-
gpa_data['weighted'] = weighted_match.group(1)
|
| 167 |
-
|
| 168 |
-
# Extract current grade level
|
| 169 |
-
grade_match = re.search(r'GRADE LEVEL:\s*12', text) # Adjust as needed
|
| 170 |
-
grade_level = "12" if grade_match else "Unknown"
|
| 171 |
-
|
| 172 |
-
return {
|
| 173 |
-
'student_info': student_info,
|
| 174 |
-
'courses': dict(courses_by_grade),
|
| 175 |
-
'gpa': gpa_data,
|
| 176 |
-
'grade_level': grade_level
|
| 177 |
-
}
|
| 178 |
-
|
| 179 |
-
def _parse_miami_dade(self, text: str) -> Dict[str, Union[Dict, List[Dict]]]:
|
| 180 |
-
"""Parse standard Miami-Dade format"""
|
| 181 |
-
courses = []
|
| 182 |
-
courses_by_grade = defaultdict(list)
|
| 183 |
-
|
| 184 |
-
# Extract student info
|
| 185 |
-
student_info = {}
|
| 186 |
-
name_match = re.search(r'0783977 - ([^,]+),\s*([^\n]+)', text)
|
| 187 |
-
if name_match:
|
| 188 |
-
student_info['name'] = f"{name_match.group(2)} {name_match.group(1)}"
|
| 189 |
-
|
| 190 |
-
# Course pattern for Miami-Dade
|
| 191 |
-
course_pattern = re.compile(
|
| 192 |
-
r'([A-Z]-[A-Za-z\s&]+)\s*\|\s*(\d{4}-\d{4})\s*\|\s*(\d{2})\s*\|\s*([A-Z0-9]+)\s*\|\s*([^\|]+)\s*\|\s*([^\|]+)\s*\|\s*([^\|]+)\s*\|\s*([A-Z]?)\s*\|\s*([A-Z]?)\s*\|\s*([^\|]+)',
|
| 193 |
-
re.MULTILINE
|
| 194 |
-
)
|
| 195 |
-
|
| 196 |
-
for match in course_pattern.finditer(text):
|
| 197 |
-
grade_level = self.grade_level_map.get(match.group(3), match.group(3))
|
| 198 |
-
credits = match.group(10).strip()
|
| 199 |
-
|
| 200 |
-
course_info = {
|
| 201 |
-
'requirement_category': match.group(1).strip(),
|
| 202 |
-
'school_year': match.group(2),
|
| 203 |
-
'grade_level': grade_level if isinstance(grade_level, str) else f"Grade {match.group(3)}",
|
| 204 |
-
'course_code': match.group(4).strip(),
|
| 205 |
-
'name': match.group(5).strip(),
|
| 206 |
-
'term': match.group(6).strip(),
|
| 207 |
-
'district_number': match.group(7).strip(),
|
| 208 |
-
'grade': match.group(8),
|
| 209 |
-
'inclusion_status': match.group(9),
|
| 210 |
-
'credits': 0.0 if 'inProgress' in credits else float(credits.replace(' ', '')),
|
| 211 |
-
'transcript_type': 'miami_dade'
|
| 212 |
-
}
|
| 213 |
-
|
| 214 |
-
courses_by_grade[match.group(3)].append(course_info)
|
| 215 |
-
|
| 216 |
-
# Extract GPA information
|
| 217 |
-
gpa_data = {
|
| 218 |
-
'weighted': extract_gpa(text, 'Weighted GPA'),
|
| 219 |
-
'unweighted': extract_gpa(text, 'Un-weighted GPA')
|
| 220 |
-
}
|
| 221 |
-
|
| 222 |
-
# Extract current grade level
|
| 223 |
-
grade_match = re.search(r'Current Grade:\s*(\d+)', text)
|
| 224 |
-
grade_level = grade_match.group(1) if grade_match else "Unknown"
|
| 225 |
-
|
| 226 |
-
return {
|
| 227 |
-
'student_info': student_info,
|
| 228 |
-
'courses': dict(courses_by_grade),
|
| 229 |
-
'gpa': gpa_data,
|
| 230 |
-
'grade_level': grade_level
|
| 231 |
-
}
|
| 232 |
-
|
| 233 |
-
# Helper methods for pattern compilation
|
| 234 |
-
def _compile_miami_dade_patterns(self):
|
| 235 |
-
return {
|
| 236 |
-
'student': re.compile(r'Current Grade:\s*(\d+).*YOG\s*(\d{4})'),
|
| 237 |
-
'course': re.compile(
|
| 238 |
-
r'([A-Z]-[A-Za-z\s&]+)\s*\|\s*(\d{4}-\d{4})\s*\|\s*(\d{2})\s*\|\s*([A-Z0-9]+)\s*\|\s*([^\|]+)\s*\|\s*([^\|]+)\s*\|\s*([^\|]+)\s*\|\s*([A-Z]?)\s*\|\s*([A-Z]?)\s*\|\s*([^\|]+)',
|
| 239 |
-
re.MULTILINE
|
| 240 |
-
)
|
| 241 |
-
}
|
| 242 |
-
|
| 243 |
-
def _compile_homeschool_patterns(self):
|
| 244 |
-
return {
|
| 245 |
-
'student': re.compile(r'Student Name:\s*(.+)\s*SSN:'),
|
| 246 |
-
'course': re.compile(
|
| 247 |
-
r'^\|?\s*([^\|]+?)\s*\|\s*([A-Z][+*]?)\s*\|\s*([^\|]+)\s*\|\s*(\d+\.?\d*)\s*\|\s*(\d+)'
|
| 248 |
-
)
|
| 249 |
-
}
|
| 250 |
-
|
| 251 |
-
def _compile_doral_academy_patterns(self):
|
| 252 |
-
return {
|
| 253 |
-
'student': re.compile(r'LEGAL NAME:\s*([^\n]+)'),
|
| 254 |
-
'course': re.compile(
|
| 255 |
-
r'(\d)\s+(\d{7})\s+([^\n]+?)\s+([A-Z]{2})\s+([A-Z])\s+([A-Z])\s+([A-Z])\s+(\d\.\d{2})\s+(\d\.\d{2})',
|
| 256 |
-
re.MULTILINE
|
| 257 |
-
)
|
| 258 |
-
}
|
| 259 |
-
|
| 260 |
-
def extract_gpa(text, gpa_type):
|
| 261 |
-
pattern = rf'{gpa_type}\s*([\d\.]+)'
|
| 262 |
-
match = re.search(pattern, text)
|
| 263 |
-
return match.group(1) if match else "N/A"
|
| 264 |
-
|
| 265 |
-
def parse_transcript(file):
|
| 266 |
-
parser = UniversalTranscriptParser()
|
| 267 |
-
|
| 268 |
-
if file.name.endswith('.pdf'):
|
| 269 |
-
text = ''
|
| 270 |
-
with pdfplumber.open(file.name) as pdf:
|
| 271 |
-
for page in pdf.pages:
|
| 272 |
-
text += page.extract_text() + '\n'
|
| 273 |
-
|
| 274 |
-
parsed_data = parser.parse_transcript(text)
|
| 275 |
-
|
| 276 |
-
# Prepare detailed output
|
| 277 |
-
output_text = f"Student Transcript Summary\n{'='*40}\n"
|
| 278 |
-
|
| 279 |
-
if 'student_info' in parsed_data and 'name' in parsed_data['student_info']:
|
| 280 |
-
output_text += f"Student: {parsed_data['student_info']['name']}\n"
|
| 281 |
-
|
| 282 |
-
output_text += f"Current Grade Level: {parsed_data.get('grade_level', 'Unknown')}\n"
|
| 283 |
-
|
| 284 |
-
if 'gpa' in parsed_data:
|
| 285 |
-
gpa = parsed_data['gpa']
|
| 286 |
-
output_text += f"Weighted GPA: {gpa.get('weighted', 'N/A')}\n"
|
| 287 |
-
output_text += f"Unweighted GPA: {gpa.get('unweighted', 'N/A')}\n\n"
|
| 288 |
-
|
| 289 |
-
output_text += "Course History:\n{'='*40}\n"
|
| 290 |
-
|
| 291 |
-
if 'courses' in parsed_data:
|
| 292 |
-
courses_by_grade = parsed_data['courses']
|
| 293 |
-
|
| 294 |
-
# Improved grade sorting that handles both numeric and text grades
|
| 295 |
-
def grade_sort_key(grade):
|
| 296 |
-
try:
|
| 297 |
-
# Extract numeric part from strings like "9th Grade" or "Grade 9"
|
| 298 |
-
num = int(re.search(r'\d+', grade).group())
|
| 299 |
-
return num
|
| 300 |
-
except (AttributeError, ValueError):
|
| 301 |
-
# For non-numeric grades like "All", sort them last
|
| 302 |
-
return float('inf')
|
| 303 |
-
|
| 304 |
-
grades_sorted = sorted(courses_by_grade.keys(), key=grade_sort_key)
|
| 305 |
-
|
| 306 |
-
for grade in grades_sorted:
|
| 307 |
-
output_text += f"\nGrade {grade}:\n{'-'*30}\n"
|
| 308 |
-
for course in courses_by_grade[grade]:
|
| 309 |
-
output_text += f"- {course.get('name', 'Unnamed Course')}"
|
| 310 |
-
if 'grade' in course and course['grade']:
|
| 311 |
-
output_text += f" (Grade: {course['grade']})"
|
| 312 |
-
if 'credits' in course:
|
| 313 |
-
output_text += f" | Credits: {course['credits']}"
|
| 314 |
-
if 'school_year' in course:
|
| 315 |
-
output_text += f" | Year: {course['school_year']}"
|
| 316 |
-
output_text += "\n"
|
| 317 |
-
|
| 318 |
-
return output_text, parsed_data
|
| 319 |
-
else:
|
| 320 |
-
return "Unsupported file format (PDF only for transcript parsing)", None
|
| 321 |
-
|
| 322 |
-
def transcript_display(transcript_dict):
|
| 323 |
-
if not transcript_dict or "courses" not in transcript_dict:
|
| 324 |
-
return "No course information available"
|
| 325 |
-
|
| 326 |
-
display = "### Detailed Course History\n"
|
| 327 |
-
courses_by_grade = transcript_dict["courses"]
|
| 328 |
-
|
| 329 |
-
if isinstance(courses_by_grade, dict):
|
| 330 |
-
# Improved grade sorting that handles both numeric and text grades
|
| 331 |
-
def grade_sort_key(grade):
|
| 332 |
-
try:
|
| 333 |
-
# Extract numeric part from strings like "9th Grade" or "Grade 9"
|
| 334 |
-
num = int(re.search(r'\d+', grade).group())
|
| 335 |
-
return num
|
| 336 |
-
except (AttributeError, ValueError):
|
| 337 |
-
# For non-numeric grades like "All", sort them last
|
| 338 |
-
return float('inf')
|
| 339 |
-
|
| 340 |
-
grades_sorted = sorted(courses_by_grade.keys(), key=grade_sort_key)
|
| 341 |
-
|
| 342 |
-
for grade in grades_sorted:
|
| 343 |
-
display += f"\n**Grade {grade}**\n"
|
| 344 |
-
for course in courses_by_grade[grade]:
|
| 345 |
-
display += f"- {course.get('name', 'Unnamed Course')}"
|
| 346 |
-
if 'grade' in course and course['grade']:
|
| 347 |
-
display += f" (Grade: {course['grade']})"
|
| 348 |
-
if 'credits' in course:
|
| 349 |
-
display += f" | Credits: {course['credits']}"
|
| 350 |
-
if 'school_year' in course:
|
| 351 |
-
display += f" | Year: {course['school_year']}"
|
| 352 |
-
display += "\n"
|
| 353 |
-
|
| 354 |
-
if 'gpa' in transcript_dict:
|
| 355 |
-
gpa = transcript_dict['gpa']
|
| 356 |
-
display += "\n**GPA Information**\n"
|
| 357 |
-
display += f"- Unweighted: {gpa.get('unweighted', 'N/A')}\n"
|
| 358 |
-
display += f"- Weighted: {gpa.get('weighted', 'N/A')}\n"
|
| 359 |
-
|
| 360 |
-
return display
|
| 361 |
-
|
| 362 |
-
# ========== LEARNING STYLE QUIZ ==========
|
| 363 |
-
learning_style_questions = [
|
| 364 |
-
"When you study for a test, you prefer to:",
|
| 365 |
-
"When you need directions to a new place, you prefer:",
|
| 366 |
-
"When you learn a new skill, you prefer to:",
|
| 367 |
-
"When you're trying to concentrate, you:",
|
| 368 |
-
"When you meet new people, you remember them by:",
|
| 369 |
-
"When you're assembling furniture or a gadget, you:",
|
| 370 |
-
"When choosing a restaurant, you rely most on:",
|
| 371 |
-
"When you're in a waiting room, you typically:",
|
| 372 |
-
"When giving someone instructions, you tend to:",
|
| 373 |
-
"When you're trying to recall information, you:",
|
| 374 |
-
"When you're at a museum or exhibit, you:",
|
| 375 |
-
"When you're learning a new language, you prefer:",
|
| 376 |
-
"When you're taking notes in class, you:",
|
| 377 |
-
"When you're explaining something complex, you:",
|
| 378 |
-
"When you're at a party, you enjoy:",
|
| 379 |
-
"When you're trying to remember a phone number, you:",
|
| 380 |
-
"When you're relaxing, you prefer to:",
|
| 381 |
-
"When you're learning to use new software, you:",
|
| 382 |
-
"When you're giving a presentation, you rely on:",
|
| 383 |
-
"When you're solving a difficult problem, you:"
|
| 384 |
-
]
|
| 385 |
-
|
| 386 |
-
learning_style_options = [
|
| 387 |
-
["Read the textbook (Reading/Writing)", "Listen to lectures (Auditory)", "Use diagrams/charts (Visual)", "Practice problems (Kinesthetic)"],
|
| 388 |
-
["Look at a map (Visual)", "Have someone tell you (Auditory)", "Write down directions (Reading/Writing)", "Try walking/driving there (Kinesthetic)"],
|
| 389 |
-
["Read instructions (Reading/Writing)", "Have someone show you (Visual)", "Listen to explanations (Auditory)", "Try it yourself (Kinesthetic)"],
|
| 390 |
-
["Need quiet (Reading/Writing)", "Need background noise (Auditory)", "Need to move around (Kinesthetic)", "Need visual stimulation (Visual)"],
|
| 391 |
-
["Their face (Visual)", "Their name (Auditory)", "What you talked about (Reading/Writing)", "What you did together (Kinesthetic)"],
|
| 392 |
-
["Read the instructions carefully (Reading/Writing)", "Look at the diagrams (Visual)", "Ask someone to explain (Auditory)", "Start putting pieces together (Kinesthetic)"],
|
| 393 |
-
["Online photos of the food (Visual)", "Recommendations from friends (Auditory)", "Reading the menu online (Reading/Writing)", "Remembering how it felt to eat there (Kinesthetic)"],
|
| 394 |
-
["Read magazines (Reading/Writing)", "Listen to music (Auditory)", "Watch TV (Visual)", "Fidget or move around (Kinesthetic)"],
|
| 395 |
-
["Write them down (Reading/Writing)", "Explain verbally (Auditory)", "Demonstrate (Visual)", "Guide them physically (Kinesthetic)"],
|
| 396 |
-
["See written words in your mind (Visual)", "Hear the information in your head (Auditory)", "Write it down to remember (Reading/Writing)", "Associate it with physical actions (Kinesthetic)"],
|
| 397 |
-
["Read all the descriptions (Reading/Writing)", "Listen to audio guides (Auditory)", "Look at the displays (Visual)", "Touch interactive exhibits (Kinesthetic)"],
|
| 398 |
-
["Study grammar rules (Reading/Writing)", "Listen to native speakers (Auditory)", "Use flashcards with images (Visual)", "Practice conversations (Kinesthetic)"],
|
| 399 |
-
["Write detailed paragraphs (Reading/Writing)", "Record the lecture (Auditory)", "Draw diagrams and charts (Visual)", "Doodle while listening (Kinesthetic)"],
|
| 400 |
-
["Write detailed steps (Reading/Writing)", "Explain verbally with examples (Auditory)", "Draw diagrams (Visual)", "Use physical objects to demonstrate (Kinesthetic)"],
|
| 401 |
-
["Conversations with people (Auditory)", "Watching others or the environment (Visual)", "Writing notes or texting (Reading/Writing)", "Dancing or physical activities (Kinesthetic)"],
|
| 402 |
-
["See the numbers in your head (Visual)", "Say them aloud (Auditory)", "Write them down (Reading/Writing)", "Dial them on a keypad (Kinesthetic)"],
|
| 403 |
-
["Read a book (Reading/Writing)", "Listen to music (Auditory)", "Watch TV/movies (Visual)", "Do something physical (Kinesthetic)"],
|
| 404 |
-
["Read the manual (Reading/Writing)", "Ask someone to show you (Visual)", "Call tech support (Auditory)", "Experiment with the software (Kinesthetic)"],
|
| 405 |
-
["Detailed notes (Reading/Writing)", "Verbal explanations (Auditory)", "Visual slides (Visual)", "Physical demonstrations (Kinesthetic)"],
|
| 406 |
-
["Write out possible solutions (Reading/Writing)", "Talk through it with someone (Auditory)", "Draw diagrams (Visual)", "Build a model or prototype (Kinesthetic)"]
|
| 407 |
-
]
|
| 408 |
-
|
| 409 |
-
def learning_style_quiz(*answers):
|
| 410 |
-
scores = {
|
| 411 |
-
"Visual": 0,
|
| 412 |
-
"Auditory": 0,
|
| 413 |
-
"Reading/Writing": 0,
|
| 414 |
-
"Kinesthetic": 0
|
| 415 |
-
}
|
| 416 |
-
|
| 417 |
-
for i, answer in enumerate(answers):
|
| 418 |
-
if answer == learning_style_options[i][0]:
|
| 419 |
-
scores["Reading/Writing"] += 1
|
| 420 |
-
elif answer == learning_style_options[i][1]:
|
| 421 |
-
scores["Auditory"] += 1
|
| 422 |
-
elif answer == learning_style_options[i][2]:
|
| 423 |
-
scores["Visual"] += 1
|
| 424 |
-
elif answer == learning_style_options[i][3]:
|
| 425 |
-
scores["Kinesthetic"] += 1
|
| 426 |
-
|
| 427 |
-
max_score = max(scores.values())
|
| 428 |
-
total_questions = len(learning_style_questions)
|
| 429 |
-
|
| 430 |
-
# Calculate percentages
|
| 431 |
-
percentages = {style: (score/total_questions)*100 for style, score in scores.items()}
|
| 432 |
-
|
| 433 |
-
# Sort styles by score (descending)
|
| 434 |
-
sorted_styles = sorted(scores.items(), key=lambda x: x[1], reverse=True)
|
| 435 |
-
|
| 436 |
-
# Prepare detailed results
|
| 437 |
-
result = "Your Learning Style Results:\n\n"
|
| 438 |
-
for style, score in sorted_styles:
|
| 439 |
-
result += f"{style}: {score}/{total_questions} ({percentages[style]:.1f}%)\n"
|
| 440 |
-
|
| 441 |
-
result += "\n"
|
| 442 |
-
|
| 443 |
-
# Determine primary and secondary styles
|
| 444 |
-
primary_styles = [style for style, score in scores.items() if score == max_score]
|
| 445 |
-
|
| 446 |
-
if len(primary_styles) == 1:
|
| 447 |
-
result += f"Your primary learning style is: {primary_styles[0]}\n\n"
|
| 448 |
-
# Add personalized tips based on primary style
|
| 449 |
-
if primary_styles[0] == "Visual":
|
| 450 |
-
result += "Tips for Visual Learners:\n"
|
| 451 |
-
result += "- Use color coding in your notes\n"
|
| 452 |
-
result += "- Create mind maps and diagrams\n"
|
| 453 |
-
result += "- Watch educational videos\n"
|
| 454 |
-
result += "- Use flashcards with images\n"
|
| 455 |
-
elif primary_styles[0] == "Auditory":
|
| 456 |
-
result += "Tips for Auditory Learners:\n"
|
| 457 |
-
result += "- Record lectures and listen to them\n"
|
| 458 |
-
result += "- Participate in study groups\n"
|
| 459 |
-
result += "- Explain concepts out loud to yourself\n"
|
| 460 |
-
result += "- Use rhymes or songs to remember information\n"
|
| 461 |
-
elif primary_styles[0] == "Reading/Writing":
|
| 462 |
-
result += "Tips for Reading/Writing Learners:\n"
|
| 463 |
-
result += "- Write detailed notes\n"
|
| 464 |
-
result += "- Create summaries in your own words\n"
|
| 465 |
-
result += "- Read textbooks and articles\n"
|
| 466 |
-
result += "- Make lists to organize information\n"
|
| 467 |
-
else: # Kinesthetic
|
| 468 |
-
result += "Tips for Kinesthetic Learners:\n"
|
| 469 |
-
result += "- Use hands-on activities\n"
|
| 470 |
-
result += "- Take frequent movement breaks\n"
|
| 471 |
-
result += "- Create physical models\n"
|
| 472 |
-
result += "- Associate information with physical actions\n"
|
| 473 |
-
else:
|
| 474 |
-
result += f"You have multiple strong learning styles: {', '.join(primary_styles)}\n\n"
|
| 475 |
-
result += "You may benefit from combining different learning approaches.\n"
|
| 476 |
-
|
| 477 |
-
return result
|
| 478 |
-
|
| 479 |
-
# ========== SAVE STUDENT PROFILE ==========
|
| 480 |
-
def save_profile(name, age, interests, transcript, learning_style,
|
| 481 |
-
movie, movie_reason, show, show_reason,
|
| 482 |
-
book, book_reason, character, character_reason, blog):
|
| 483 |
-
# Convert age to int if it's a numpy number (from gradio Number input)
|
| 484 |
-
age = int(age) if age else 0
|
| 485 |
-
|
| 486 |
-
favorites = {
|
| 487 |
-
"movie": movie,
|
| 488 |
-
"movie_reason": movie_reason,
|
| 489 |
-
"show": show,
|
| 490 |
-
"show_reason": show_reason,
|
| 491 |
-
"book": book,
|
| 492 |
-
"book_reason": book_reason,
|
| 493 |
-
"character": character,
|
| 494 |
-
"character_reason": character_reason
|
| 495 |
-
}
|
| 496 |
-
|
| 497 |
-
data = {
|
| 498 |
-
"name": name,
|
| 499 |
-
"age": age,
|
| 500 |
-
"interests": interests,
|
| 501 |
-
"transcript": transcript,
|
| 502 |
-
"learning_style": learning_style,
|
| 503 |
-
"favorites": favorites,
|
| 504 |
-
"blog": blog
|
| 505 |
-
}
|
| 506 |
-
|
| 507 |
-
os.makedirs("student_profiles", exist_ok=True)
|
| 508 |
-
json_path = os.path.join("student_profiles", f"{name.replace(' ', '_')}_profile.json")
|
| 509 |
-
with open(json_path, "w") as f:
|
| 510 |
-
json.dump(data, f, indent=2)
|
| 511 |
-
|
| 512 |
-
markdown_summary = f"""### Student Profile: {name}
|
| 513 |
-
**Age:** {age}
|
| 514 |
-
**Interests:** {interests}
|
| 515 |
-
**Learning Style:** {learning_style}
|
| 516 |
-
#### Transcript:
|
| 517 |
-
{transcript_display(transcript)}
|
| 518 |
-
#### Favorites:
|
| 519 |
-
- Movie: {favorites['movie']} ({favorites['movie_reason']})
|
| 520 |
-
- Show: {favorites['show']} ({favorites['show_reason']})
|
| 521 |
-
- Book: {favorites['book']} ({favorites['book_reason']})
|
| 522 |
-
- Character: {favorites['character']} ({favorites['character_reason']})
|
| 523 |
-
#### Blog:
|
| 524 |
-
{blog if blog else "_No blog provided_"}
|
| 525 |
-
"""
|
| 526 |
-
return markdown_summary
|
| 527 |
-
|
| 528 |
-
# ========== AI TEACHING ASSISTANT ==========
|
| 529 |
-
def load_profile():
|
| 530 |
-
if not os.path.exists("student_profiles"):
|
| 531 |
-
return {}
|
| 532 |
-
files = [f for f in os.listdir("student_profiles") if f.endswith('.json')]
|
| 533 |
-
if files:
|
| 534 |
-
with open(os.path.join("student_profiles", files[0]), "r") as f:
|
| 535 |
-
return json.load(f)
|
| 536 |
-
return {}
|
| 537 |
-
|
| 538 |
-
def generate_response(message, history):
|
| 539 |
-
profile = load_profile()
|
| 540 |
-
if not profile:
|
| 541 |
-
return "Please complete and save your profile first using the previous tabs."
|
| 542 |
-
|
| 543 |
-
# Get profile data
|
| 544 |
-
learning_style = profile.get("learning_style", "")
|
| 545 |
-
grade_level = profile.get("transcript", {}).get("grade_level", "unknown")
|
| 546 |
-
gpa = profile.get("transcript", {}).get("gpa", {})
|
| 547 |
-
interests = profile.get("interests", "")
|
| 548 |
-
courses = profile.get("transcript", {}).get("courses", {})
|
| 549 |
-
|
| 550 |
-
# Common responses
|
| 551 |
-
greetings = ["hi", "hello", "hey"]
|
| 552 |
-
study_help = ["study", "learn", "prepare", "exam"]
|
| 553 |
-
grade_help = ["grade", "gpa", "score"]
|
| 554 |
-
interest_help = ["interest", "hobby", "passion"]
|
| 555 |
-
course_help = ["courses", "classes", "transcript", "schedule"]
|
| 556 |
-
|
| 557 |
-
if any(greet in message.lower() for greet in greetings):
|
| 558 |
-
return f"Hello {profile.get('name', 'there')}! How can I help you today?"
|
| 559 |
-
|
| 560 |
-
elif any(word in message.lower() for word in study_help):
|
| 561 |
-
if "Visual" in learning_style:
|
| 562 |
-
response = ("Based on your visual learning style, I recommend:\n"
|
| 563 |
-
"- Creating mind maps or diagrams\n"
|
| 564 |
-
"- Using color-coded notes\n"
|
| 565 |
-
"- Watching educational videos")
|
| 566 |
-
elif "Auditory" in learning_style:
|
| 567 |
-
response = ("Based on your auditory learning style, I recommend:\n"
|
| 568 |
-
"- Recording lectures and listening to them\n"
|
| 569 |
-
"- Participating in study groups\n"
|
| 570 |
-
"- Explaining concepts out loud")
|
| 571 |
-
elif "Reading/Writing" in learning_style:
|
| 572 |
-
response = ("Based on your reading/writing learning style, I recommend:\n"
|
| 573 |
-
"- Writing detailed notes\n"
|
| 574 |
-
"- Creating summaries in your own words\n"
|
| 575 |
-
"- Reading textbooks and articles")
|
| 576 |
-
elif "Kinesthetic" in learning_style:
|
| 577 |
-
response = ("Based on your kinesthetic learning style, I recommend:\n"
|
| 578 |
-
"- Hands-on practice\n"
|
| 579 |
-
"- Creating physical models\n"
|
| 580 |
-
"- Taking frequent movement breaks")
|
| 581 |
-
else:
|
| 582 |
-
response = ("Here are some general study tips:\n"
|
| 583 |
-
"- Break study sessions into 25-minute chunks\n"
|
| 584 |
-
"- Review material regularly\n"
|
| 585 |
-
"- Teach concepts to someone else")
|
| 586 |
-
|
| 587 |
-
return response
|
| 588 |
-
|
| 589 |
-
elif any(word in message.lower() for word in grade_help):
|
| 590 |
-
return (f"Your GPA information:\n"
|
| 591 |
-
f"- Unweighted: {gpa.get('unweighted', 'N/A')}\n"
|
| 592 |
-
f"- Weighted: {gpa.get('weighted', 'N/A')}\n\n"
|
| 593 |
-
"To improve your grades, try:\n"
|
| 594 |
-
"- Setting specific goals\n"
|
| 595 |
-
"- Meeting with teachers\n"
|
| 596 |
-
"- Developing a study schedule")
|
| 597 |
-
|
| 598 |
-
elif any(word in message.lower() for word in interest_help):
|
| 599 |
-
return (f"I see you're interested in: {interests}\n\n"
|
| 600 |
-
"You might want to:\n"
|
| 601 |
-
"- Find clubs or activities related to these interests\n"
|
| 602 |
-
"- Explore career paths that align with them")
|
| 603 |
-
|
| 604 |
-
elif any(word in message.lower() for word in course_help):
|
| 605 |
-
response = "Here's a summary of your courses:\n"
|
| 606 |
-
if isinstance(courses, dict):
|
| 607 |
-
# Use the same grade sorting logic as in transcript display
|
| 608 |
-
def grade_sort_key(grade):
|
| 609 |
-
try:
|
| 610 |
-
num = int(re.search(r'\d+', grade).group())
|
| 611 |
-
return num
|
| 612 |
-
except (AttributeError, ValueError):
|
| 613 |
-
return float('inf')
|
| 614 |
-
|
| 615 |
-
grades_sorted = sorted(courses.keys(), key=grade_sort_key)
|
| 616 |
-
|
| 617 |
-
for grade in grades_sorted:
|
| 618 |
-
response += f"\nGrade {grade}:\n"
|
| 619 |
-
for course in courses[grade]:
|
| 620 |
-
response += f"- {course.get('name', 'Unnamed Course')}"
|
| 621 |
-
if 'grade' in course:
|
| 622 |
-
response += f" (Grade: {course['grade']})"
|
| 623 |
-
response += "\n"
|
| 624 |
-
else:
|
| 625 |
-
response += "No detailed course information available."
|
| 626 |
-
return response
|
| 627 |
-
|
| 628 |
-
elif "help" in message.lower():
|
| 629 |
-
return ("I can help with:\n"
|
| 630 |
-
"- Study tips based on your learning style\n"
|
| 631 |
-
"- GPA and grade information\n"
|
| 632 |
-
"- Course history and schedules\n"
|
| 633 |
-
"- General academic advice\n\n"
|
| 634 |
-
"Try asking about study strategies or your grades!")
|
| 635 |
-
|
| 636 |
-
else:
|
| 637 |
-
return ("I'm your personalized teaching assistant. "
|
| 638 |
-
"I can help with study tips, grade information, and academic advice. "
|
| 639 |
-
"Try asking about how to study for your classes!")
|
| 640 |
-
|
| 641 |
-
# ========== GRADIO INTERFACE ==========
|
| 642 |
-
with gr.Blocks() as app:
|
| 643 |
-
with gr.Tab("Step 1: Upload Transcript"):
|
| 644 |
-
gr.Markdown("### Upload your transcript (PDF recommended for best results)")
|
| 645 |
-
transcript_file = gr.File(label="Transcript file", file_types=[".pdf"])
|
| 646 |
-
transcript_output = gr.Textbox(label="Transcript Results", lines=20)
|
| 647 |
-
transcript_data = gr.State()
|
| 648 |
-
transcript_file.change(
|
| 649 |
-
fn=parse_transcript,
|
| 650 |
-
inputs=transcript_file,
|
| 651 |
-
outputs=[transcript_output, transcript_data]
|
| 652 |
-
)
|
| 653 |
-
|
| 654 |
-
with gr.Tab("Step 2: Learning Style Quiz"):
|
| 655 |
-
gr.Markdown("### Learning Style Quiz (20 Questions)")
|
| 656 |
-
quiz_components = []
|
| 657 |
-
for i, (question, options) in enumerate(zip(learning_style_questions, learning_style_options)):
|
| 658 |
-
quiz_components.append(gr.Radio(options, label=f"{i+1}. {question}"))
|
| 659 |
-
|
| 660 |
-
learning_output = gr.Textbox(label="Your Learning Style", lines=15)
|
| 661 |
-
gr.Button("Submit Quiz").click(
|
| 662 |
-
fn=learning_style_quiz,
|
| 663 |
-
inputs=quiz_components,
|
| 664 |
-
outputs=learning_output
|
| 665 |
-
)
|
| 666 |
-
|
| 667 |
-
with gr.Tab("Step 3: Personal Questions"):
|
| 668 |
-
name = gr.Textbox(label="What's your name?")
|
| 669 |
-
age = gr.Number(label="How old are you?", precision=0)
|
| 670 |
-
interests = gr.Textbox(label="What are your interests?")
|
| 671 |
-
movie = gr.Textbox(label="Favorite movie?")
|
| 672 |
-
movie_reason = gr.Textbox(label="Why do you like that movie?")
|
| 673 |
-
show = gr.Textbox(label="Favorite TV show?")
|
| 674 |
-
show_reason = gr.Textbox(label="Why do you like that show?")
|
| 675 |
-
book = gr.Textbox(label="Favorite book?")
|
| 676 |
-
book_reason = gr.Textbox(label="Why do you like that book?")
|
| 677 |
-
character = gr.Textbox(label="Favorite character?")
|
| 678 |
-
character_reason = gr.Textbox(label="Why do you like that character?")
|
| 679 |
-
blog_checkbox = gr.Checkbox(label="Do you want to write a blog?", value=False)
|
| 680 |
-
blog_text = gr.Textbox(label="Write your blog here", visible=False, lines=5)
|
| 681 |
-
blog_checkbox.change(lambda x: gr.update(visible=x), inputs=blog_checkbox, outputs=blog_text)
|
| 682 |
-
|
| 683 |
-
with gr.Tab("Step 4: Save & Review"):
|
| 684 |
-
output_summary = gr.Markdown()
|
| 685 |
-
save_btn = gr.Button("Save Profile")
|
| 686 |
-
save_btn.click(
|
| 687 |
-
fn=save_profile,
|
| 688 |
-
inputs=[name, age, interests, transcript_data, learning_output,
|
| 689 |
-
movie, movie_reason, show, show_reason,
|
| 690 |
-
book, book_reason, character, character_reason, blog_text],
|
| 691 |
-
outputs=output_summary
|
| 692 |
-
)
|
| 693 |
-
|
| 694 |
-
with gr.Tab("🤖 AI Teaching Assistant"):
|
| 695 |
-
gr.Markdown("## Your Personalized Learning Assistant")
|
| 696 |
-
chatbot = gr.ChatInterface(
|
| 697 |
-
fn=generate_response,
|
| 698 |
-
examples=[
|
| 699 |
-
"How should I study for my next test?",
|
| 700 |
-
"What's my GPA information?",
|
| 701 |
-
"Show me my course history",
|
| 702 |
-
"How can I improve my grades?"
|
| 703 |
-
]
|
| 704 |
-
)
|
| 705 |
|
| 706 |
if __name__ == "__main__":
|
| 707 |
-
|
| 708 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# ========== STARTUP DEPENDENCY CHECK ==========
|
| 2 |
+
import sys
|
| 3 |
+
import subprocess
|
| 4 |
+
import importlib
|
| 5 |
+
|
| 6 |
+
# List of required packages with their import names and pip names
|
| 7 |
+
required_packages = {
|
| 8 |
+
'gradio': 'gradio',
|
| 9 |
+
'pandas': 'pandas',
|
| 10 |
+
'PyPDF2': 'PyPDF2',
|
| 11 |
+
'transformers': 'transformers',
|
| 12 |
+
'pdfplumber': 'pdfplumber',
|
| 13 |
+
'typing_extensions': 'typing_extensions' # Often needed for transformers
|
| 14 |
+
}
|
| 15 |
+
|
| 16 |
+
def check_and_install_packages():
|
| 17 |
+
missing_packages = []
|
| 18 |
+
for import_name, pkg_name in required_packages.items():
|
| 19 |
+
try:
|
| 20 |
+
importlib.import_module(import_name)
|
| 21 |
+
except ImportError:
|
| 22 |
+
missing_packages.append(pkg_name)
|
| 23 |
+
|
| 24 |
+
if missing_packages:
|
| 25 |
+
print(f"Missing packages: {', '.join(missing_packages)}")
|
| 26 |
+
print("Attempting to install...")
|
| 27 |
+
|
| 28 |
+
try:
|
| 29 |
+
subprocess.check_call([sys.executable, "-m", "pip", "install", *missing_packages])
|
| 30 |
+
print("Installation successful. Please restart the application.")
|
| 31 |
+
sys.exit(0)
|
| 32 |
+
except subprocess.CalledProcessError as e:
|
| 33 |
+
print(f"Failed to install packages. Error: {e}")
|
| 34 |
+
print("Please install them manually with:")
|
| 35 |
+
print(f"pip install {' '.join(missing_packages)}")
|
| 36 |
+
sys.exit(1)
|
| 37 |
+
|
| 38 |
+
check_and_install_packages()
|
| 39 |
+
|
| 40 |
+
# ========== MAIN IMPORTS (AFTER DEPENDENCY CHECK) ==========
|
| 41 |
import gradio as gr
|
| 42 |
import pandas as pd
|
| 43 |
import json
|
|
|
|
| 49 |
from typing import List, Dict, Union
|
| 50 |
import pdfplumber
|
| 51 |
|
| 52 |
+
[... REST OF YOUR ORIGINAL CODE REMAINS EXACTLY THE SAME ...]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 53 |
|
| 54 |
if __name__ == "__main__":
|
| 55 |
+
# Check if running in a notebook environment
|
| 56 |
+
try:
|
| 57 |
+
from IPython import get_ipython
|
| 58 |
+
if 'IPKernelApp' not in get_ipython().config:
|
| 59 |
+
app.launch()
|
| 60 |
+
except:
|
| 61 |
+
app.launch()
|
| 62 |
+
|