Nickhilearla135095 commited on
Commit
43535e5
·
verified ·
1 Parent(s): f855daf

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -15
app.py CHANGED
@@ -25,15 +25,19 @@ class GPACalculator:
25
  }
26
 
27
  def calculate_gpa(self, grades, previous_gpa):
28
- total_points = previous_gpa * sum(len(grade_list) for grade_list in grades.values())
29
- total_courses = sum(len(grade_list) for grade_list in grades.values())
30
- for tier, tier_grades in grades.items():
 
 
31
  for grade in tier_grades:
32
  total_points += self.grade_tables[tier].get(grade, 0)
33
  total_courses += 1
34
- if total_courses == 0:
35
- return 0 # Avoid division by zero
36
- return total_points / total_courses
 
 
37
 
38
  calculator = GPACalculator()
39
 
@@ -55,15 +59,17 @@ def calculate_gpa_interface(grades_tier_1, grades_tier_2, grades_tier_3, previou
55
  return str(gpa)
56
 
57
 
58
- with gr.Blocks() as demo:
59
-
60
- grades_tier_1 = gr.Textbox(label="on levels", lines=2)
61
- grades_tier_2 = gr.Textbox(label="advanced")
62
- grades_tier_3 = gr.Textbox(label="AP")
63
- previous_gpa = gr.Textbox(label="Old GPA")
64
- txt_output = gr.Textbox(value="", label="Output")
65
- btn = gr.Button(value="Submit")
66
- btn.click(calculate_gpa_interface, inputs=[grades_tier_1, grades_tier_2, grades_tier_3, previous_gpa], outputs=[txt_output])
 
 
67
 
68
 
69
 
 
25
  }
26
 
27
  def calculate_gpa(self, grades, previous_gpa):
28
+ total_points = previous_gpa * sum(len(grade_list) for grade_list in grades.values())
29
+ total_courses = sum(len(grade_list) for grade_list in grades.values())
30
+
31
+ for tier, tier_grades in grades.items():
32
+ if tier_grades: # Check if there are grades in the tier
33
  for grade in tier_grades:
34
  total_points += self.grade_tables[tier].get(grade, 0)
35
  total_courses += 1
36
+
37
+ if total_courses == 0:
38
+ return 0 # Avoid division by zero
39
+ return total_points / total_courses
40
+
41
 
42
  calculator = GPACalculator()
43
 
 
59
  return str(gpa)
60
 
61
 
62
+ # Create Gradio interface
63
+ title = "GPA Calculator for FISD"
64
+ instructions = "Enter your grades for on-level, advanced, and AP courses, along with your previous GPA."
65
+ demo = gr.Interface(fn=calculate_gpa_interface,
66
+ inputs=[gr.Textbox(label="On-level Grades", lines=2),
67
+ gr.Textbox(label="Advanced Grades"),
68
+ gr.Textbox(label="AP Grades"),
69
+ gr.Textbox(label="Previous GPA")],
70
+ outputs=[gr.Textbox(label="Calculated GPA")],
71
+ title=title,
72
+ description=instructions)
73
 
74
 
75