Dannyar608 commited on
Commit
a8ea573
·
verified ·
1 Parent(s): 8b799c5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +60 -38
app.py CHANGED
@@ -28,7 +28,15 @@ import plotly.express as px
28
  import pdfplumber
29
  from io import BytesIO
30
  import base64
31
- import matplotlib.pyplot as plt
 
 
 
 
 
 
 
 
32
 
33
  # ========== CONFIGURATION ==========
34
  PROFILES_DIR = "student_profiles"
@@ -304,44 +312,58 @@ def analyze_college_readiness(student_info, requirements, courses):
304
 
305
  def create_requirements_visualization_matplotlib(requirements):
306
  """Create matplotlib visualization for requirements completion"""
307
- fig, ax = plt.subplots(figsize=(10, 6))
308
- req_names = [req['code'] for req in requirements]
309
- req_completion = [min(req['status'], 100) for req in requirements]
310
- colors = ['#4CAF50' if x >= 100 else '#FFC107' if x > 0 else '#F44336' for x in req_completion]
311
-
312
- bars = ax.barh(req_names, req_completion, color=colors)
313
- ax.set_xlabel('Completion (%)')
314
- ax.set_title('Requirement Completion Status')
315
- ax.set_xlim(0, 100)
316
-
317
- # Add value labels
318
- for bar in bars:
319
- width = bar.get_width()
320
- ax.text(width + 1, bar.get_y() + bar.get_height()/2,
321
- f'{width:.1f}%',
322
- ha='left', va='center')
323
 
324
- plt.tight_layout()
325
- return fig
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
326
 
327
  def create_credits_distribution_visualization(requirements):
328
  """Create pie chart for credits distribution"""
329
- fig, ax = plt.subplots(figsize=(8, 8))
330
-
331
- core_credits = sum(req['completed'] for req in requirements if req['code'] in ['A-English', 'B-Math', 'C-Science', 'D-Social'])
332
- elective_credits = sum(req['completed'] for req in requirements if req['code'] in ['G-Electives'])
333
- other_credits = sum(req['completed'] for req in requirements if req['code'] in ['E-Arts', 'F-PE'])
334
-
335
- credit_values = [core_credits, elective_credits, other_credits]
336
- credit_labels = ['Core Subjects', 'Electives', 'Arts/PE']
337
- colors = ['#3498db', '#2ecc71', '#9b59b6']
338
-
339
- ax.pie(credit_values, labels=credit_labels, autopct='%1.1f%%',
340
- colors=colors, startangle=90)
341
- ax.set_title('Credit Distribution')
342
 
343
- plt.tight_layout()
344
- return fig
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
345
 
346
  # ========== TEXT EXTRACTION FUNCTIONS ==========
347
  def preprocess_text(text: str) -> str:
@@ -498,7 +520,7 @@ class GraduationProgress(BaseModel):
498
  community_service_date: str
499
  total_credits_earned: float
500
  virtual_grade: str
501
- requirements: Dict[str, Dict[str, float]]
502
  courses: List[Course]
503
  assessments: Dict[str, str]
504
 
@@ -1629,9 +1651,9 @@ def create_interface():
1629
  outputs=output_summary
1630
  ).then(
1631
  fn=lambda td: (
1632
- gr.update(visible=True),
1633
- gr.update(visible=True)
1634
- ) if td and 'requirements' in td else (gr.update(visible=False), gr.update(visible=False)),
1635
  inputs=transcript_data,
1636
  outputs=[req_viz_matplotlib, credits_viz]
1637
  ).then(
 
28
  import pdfplumber
29
  from io import BytesIO
30
  import base64
31
+
32
+ # Handle matplotlib import with fallback
33
+ try:
34
+ import matplotlib.pyplot as plt
35
+ MATPLOTLIB_AVAILABLE = True
36
+ except ImportError:
37
+ MATPLOTLIB_AVAILABLE = False
38
+ plt = None
39
+ logging.warning("Matplotlib not available - some visualizations will be disabled")
40
 
41
  # ========== CONFIGURATION ==========
42
  PROFILES_DIR = "student_profiles"
 
312
 
313
  def create_requirements_visualization_matplotlib(requirements):
314
  """Create matplotlib visualization for requirements completion"""
315
+ if not MATPLOTLIB_AVAILABLE or not requirements:
316
+ return None
 
 
 
 
 
 
 
 
 
 
 
 
 
 
317
 
318
+ try:
319
+ fig, ax = plt.subplots(figsize=(10, 6))
320
+ req_names = [req['code'] for req in requirements]
321
+ req_completion = [min(req['status'], 100) for req in requirements]
322
+ colors = ['#4CAF50' if x >= 100 else '#FFC107' if x > 0 else '#F44336' for x in req_completion]
323
+
324
+ bars = ax.barh(req_names, req_completion, color=colors)
325
+ ax.set_xlabel('Completion (%)')
326
+ ax.set_title('Requirement Completion Status')
327
+ ax.set_xlim(0, 100)
328
+
329
+ # Add value labels
330
+ for bar in bars:
331
+ width = bar.get_width()
332
+ ax.text(width + 1, bar.get_y() + bar.get_height()/2,
333
+ f'{width:.1f}%',
334
+ ha='left', va='center')
335
+
336
+ plt.tight_layout()
337
+ return fig
338
+ except Exception as e:
339
+ logging.error(f"Error creating matplotlib visualization: {str(e)}")
340
+ return None
341
 
342
  def create_credits_distribution_visualization(requirements):
343
  """Create pie chart for credits distribution"""
344
+ if not MATPLOTLIB_AVAILABLE or not requirements:
345
+ return None
 
 
 
 
 
 
 
 
 
 
 
346
 
347
+ try:
348
+ fig, ax = plt.subplots(figsize=(8, 8))
349
+
350
+ core_credits = sum(req['completed'] for req in requirements if req['code'] in ['A-English', 'B-Math', 'C-Science', 'D-Social'])
351
+ elective_credits = sum(req['completed'] for req in requirements if req['code'] in ['G-Electives'])
352
+ other_credits = sum(req['completed'] for req in requirements if req['code'] in ['E-Arts', 'F-PE'])
353
+
354
+ credit_values = [core_credits, elective_credits, other_credits]
355
+ credit_labels = ['Core Subjects', 'Electives', 'Arts/PE']
356
+ colors = ['#3498db', '#2ecc71', '#9b59b6']
357
+
358
+ ax.pie(credit_values, labels=credit_labels, autopct='%1.1f%%',
359
+ colors=colors, startangle=90)
360
+ ax.set_title('Credit Distribution')
361
+
362
+ plt.tight_layout()
363
+ return fig
364
+ except Exception as e:
365
+ logging.error(f"Error creating credits visualization: {str(e)}")
366
+ return None
367
 
368
  # ========== TEXT EXTRACTION FUNCTIONS ==========
369
  def preprocess_text(text: str) -> str:
 
520
  community_service_date: str
521
  total_credits_earned: float
522
  virtual_grade: str
523
+ requirements: Dict[str, Dict[str, float]]]
524
  courses: List[Course]
525
  assessments: Dict[str, str]
526
 
 
1651
  outputs=output_summary
1652
  ).then(
1653
  fn=lambda td: (
1654
+ gr.update(visible=MATPLOTLIB_AVAILABLE and bool(td and 'requirements' in td)),
1655
+ gr.update(visible=MATPLOTLIB_AVAILABLE and bool(td and 'requirements' in td))
1656
+ ),
1657
  inputs=transcript_data,
1658
  outputs=[req_viz_matplotlib, credits_viz]
1659
  ).then(