Spaces:
Runtime error
Runtime error
File size: 1,707 Bytes
5441d7b 85696d3 5441d7b b956574 ff57dba beeb296 42b9cbd d14ca54 42b9cbd c1769c8 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
import gradio as gr
def calculate_cgpa(grades, credit_hours):
total_points = 0
total_credits = 0
for grade, credits in zip(grades, credit_hours):
# Convert grade to grade point based on the provided scale
if grade == 'O':
grade_point = 10
elif grade == 'A+':
grade_point = 9
elif grade == 'A':
grade_point = 8
elif grade == 'B+':
grade_point = 7
elif grade == 'B':
grade_point = 6
elif grade == 'C':
grade_point = 5
elif grade in ['F', 'W', 'I', 'Ab']:
grade_point = 0
else:
print(f"Unknown grade '{grade}' encountered. Skipping...")
continue
# Accumulate total points and total credits
total_points += grade_point * credits
total_credits += credits
# Calculate CGPA
if total_credits == 0:
return 0.0
cgpa = total_points / total_credits
return round(cgpa, 2)
def cgpa_calculator_interface(course_data):
try:
grades = []
credit_hours = []
for course in course_data:
grade = course['grade']
credits = int(course['credits'])
grades.append(grade)
credit_hours.append(credits)
cgpa = calculate_cgpa(grades, credit_hours)
return f"Your CGPA is: {cgpa}"
except ValueError:
return "Invalid input. Please ensure all credit hours are integers."
iface = gr.Interface(
cgpa_calculator_interface,
inputs = ["textbox", "textbox"],
gr.Label(label="Add Course"),
#debug=True,
#title="CGPA Calculator"
outputs = "textbox"
)
iface.launch()
|