Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,93 +1,97 @@
|
|
| 1 |
import gradio as gr
|
|
|
|
| 2 |
|
| 3 |
-
#
|
| 4 |
-
def
|
| 5 |
if percent >= 90:
|
| 6 |
-
return 4.
|
| 7 |
elif percent >= 85:
|
| 8 |
-
return 4.
|
| 9 |
elif percent >= 80:
|
| 10 |
-
return 3.66
|
| 11 |
elif percent >= 75:
|
| 12 |
-
return 3.33
|
| 13 |
elif percent >= 71:
|
| 14 |
-
return 3.
|
| 15 |
elif percent >= 68:
|
| 16 |
-
return 2.66
|
| 17 |
elif percent >= 61:
|
| 18 |
-
return 2.
|
| 19 |
elif percent >= 50:
|
| 20 |
-
return 1.
|
| 21 |
else:
|
| 22 |
-
return 0.
|
| 23 |
|
| 24 |
-
# GPA
|
| 25 |
-
def
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 30 |
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 38 |
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
with gr.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 44 |
|
| 45 |
-
#
|
| 46 |
app.css = """
|
| 47 |
#gpa_big textarea {
|
| 48 |
font-size: 120px !important;
|
| 49 |
font-weight: bold;
|
| 50 |
text-align: center;
|
|
|
|
| 51 |
}
|
| 52 |
"""
|
| 53 |
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
with gr.Row():
|
| 60 |
-
# Weightages column
|
| 61 |
-
with gr.Column():
|
| 62 |
-
gr.Markdown("### Weightage (%)")
|
| 63 |
-
w_assign = gr.Number(value=10, label="Assignment")
|
| 64 |
-
w_quiz = gr.Number(value=10, label="Quiz")
|
| 65 |
-
w_gdb = gr.Number(value=10, label="GDB")
|
| 66 |
-
w_mid = gr.Number(value=30, label="Mid Term")
|
| 67 |
-
w_final = gr.Number(value=40, label="Final Term")
|
| 68 |
-
|
| 69 |
-
# Achieved percentages column
|
| 70 |
-
with gr.Column():
|
| 71 |
-
gr.Markdown("### Achieved (%)")
|
| 72 |
-
p_assign = gr.Dropdown(label="Assignment", choices=options, value=50)
|
| 73 |
-
p_quiz = gr.Dropdown(label="Quiz", choices=options, value=50)
|
| 74 |
-
p_gdb = gr.Dropdown(label="GDB", choices=options, value=50)
|
| 75 |
-
p_mid = gr.Dropdown(label="Mid Term", choices=options, value=50)
|
| 76 |
-
p_final = gr.Slider(minimum=0, maximum=100, value=50, step=1, label="Final Term %")
|
| 77 |
-
|
| 78 |
-
# GPA column
|
| 79 |
-
with gr.Column():
|
| 80 |
-
gr.Markdown("### 🎓 GPA")
|
| 81 |
-
gpa_display = gr.Textbox(label="", interactive=False, value="0.00", elem_id="gpa_big", placeholder="GPA", lines=1)
|
| 82 |
-
|
| 83 |
-
inputs = [w_assign, w_quiz, w_gdb, w_mid, w_final,
|
| 84 |
-
p_assign, p_quiz, p_gdb, p_mid, p_final]
|
| 85 |
-
|
| 86 |
-
def update_gpa(*args):
|
| 87 |
-
result, color = calculate_gpa(*args)
|
| 88 |
-
return gr.update(value=result, style={"color": color})
|
| 89 |
|
| 90 |
-
|
| 91 |
-
inp.change(update_gpa, inputs=inputs, outputs=gpa_display)
|
| 92 |
|
| 93 |
app.launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
import pandas as pd
|
| 3 |
|
| 4 |
+
# Grading scheme mapping function
|
| 5 |
+
def percentage_to_gpa_letter(percent):
|
| 6 |
if percent >= 90:
|
| 7 |
+
return 4.0, "A+"
|
| 8 |
elif percent >= 85:
|
| 9 |
+
return 4.0, "A"
|
| 10 |
elif percent >= 80:
|
| 11 |
+
return 3.66, "A-"
|
| 12 |
elif percent >= 75:
|
| 13 |
+
return 3.33, "B+"
|
| 14 |
elif percent >= 71:
|
| 15 |
+
return 3.0, "B"
|
| 16 |
elif percent >= 68:
|
| 17 |
+
return 2.66, "B-"
|
| 18 |
elif percent >= 61:
|
| 19 |
+
return 2.0, "C"
|
| 20 |
elif percent >= 50:
|
| 21 |
+
return 1.0, "D"
|
| 22 |
else:
|
| 23 |
+
return 0.0, "F"
|
| 24 |
|
| 25 |
+
# Calculate projected GPA based on weightage and achieved percentages
|
| 26 |
+
def calculate_projected_gpa(df):
|
| 27 |
+
total_score = 0
|
| 28 |
+
total_weight = 0
|
| 29 |
+
for _, row in df.iterrows():
|
| 30 |
+
# Calculate total score based on weightage and achieved %
|
| 31 |
+
total_weight_row = row['Assignment Weight'] + row['Quiz Weight'] + row['GDB Weight'] + row['Midterm Weight'] + row['Final Weight']
|
| 32 |
+
achieved = (row['Assignment Weight']*row['Assignment Achieved'] +
|
| 33 |
+
row['Quiz Weight']*row['Quiz Achieved'] +
|
| 34 |
+
row['GDB Weight']*row['GDB Achieved'] +
|
| 35 |
+
row['Midterm Weight']*row['Midterm Achieved'] +
|
| 36 |
+
row['Final Weight']*row['Final Achieved']) / total_weight_row
|
| 37 |
+
gpa, grade = percentage_to_gpa_letter(achieved)
|
| 38 |
+
df.at[_, 'GPA'] = gpa
|
| 39 |
+
df.at[_, 'Grade'] = grade
|
| 40 |
+
total_score += gpa
|
| 41 |
+
total_weight += 1
|
| 42 |
+
projected_gpa = total_score / total_weight if total_weight != 0 else 0
|
| 43 |
+
return df, f"{projected_gpa:.2f}"
|
| 44 |
|
| 45 |
+
# Default course table
|
| 46 |
+
data = {
|
| 47 |
+
"Include": [True]*5,
|
| 48 |
+
"Course Code": ["CS401","CS403","CS502","CS604","MTH501"],
|
| 49 |
+
"Assignment Weight": [10,10,10,10,10],
|
| 50 |
+
"Quiz Weight": [10,10,10,10,10],
|
| 51 |
+
"GDB Weight": [10,10,10,10,10],
|
| 52 |
+
"Midterm Weight": [30,30,30,30,30],
|
| 53 |
+
"Final Weight": [40,40,40,40,40],
|
| 54 |
+
"Assignment Achieved": [80,70,90,85,75],
|
| 55 |
+
"Quiz Achieved": [85,75,95,80,70],
|
| 56 |
+
"GDB Achieved": [90,80,85,90,75],
|
| 57 |
+
"Midterm Achieved": [75,70,80,85,70],
|
| 58 |
+
"Final Achieved": [50,50,50,50,50], # Default slider value
|
| 59 |
+
"GPA": [0]*5,
|
| 60 |
+
"Grade": [""]*5
|
| 61 |
+
}
|
| 62 |
+
df = pd.DataFrame(data)
|
| 63 |
|
| 64 |
+
# Gradio app
|
| 65 |
+
with gr.Blocks() as app:
|
| 66 |
+
gr.Markdown("## 📊 Projected CGPA Calculator (Weighted Scores)")
|
| 67 |
+
with gr.Row():
|
| 68 |
+
with gr.Column(scale=3):
|
| 69 |
+
table = gr.Dataframe(
|
| 70 |
+
value=df,
|
| 71 |
+
headers=list(df.columns),
|
| 72 |
+
datatype=["bool","str"] + ["number"]*10 + ["number","str"],
|
| 73 |
+
row_count=(5,"dynamic"),
|
| 74 |
+
interactive=True
|
| 75 |
+
)
|
| 76 |
+
with gr.Column(scale=1):
|
| 77 |
+
gr.Markdown("### 🎓 Projected CGPA")
|
| 78 |
+
cgpa_display = gr.Textbox(value="0.00", interactive=False, elem_id="gpa_big", lines=1)
|
| 79 |
|
| 80 |
+
# Slider style for Final Achieved
|
| 81 |
app.css = """
|
| 82 |
#gpa_big textarea {
|
| 83 |
font-size: 120px !important;
|
| 84 |
font-weight: bold;
|
| 85 |
text-align: center;
|
| 86 |
+
color: #1a73e8;
|
| 87 |
}
|
| 88 |
"""
|
| 89 |
|
| 90 |
+
# Update GPA function
|
| 91 |
+
def update_table(df):
|
| 92 |
+
df, projected_gpa = calculate_projected_gpa(df)
|
| 93 |
+
return df, projected_gpa
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 94 |
|
| 95 |
+
table.change(update_table, inputs=table, outputs=[table,cgpa_display])
|
|
|
|
| 96 |
|
| 97 |
app.launch()
|