Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,32 +1,32 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
|
| 3 |
-
# Map
|
| 4 |
def percentage_to_gpa(percent):
|
| 5 |
if percent >= 90:
|
| 6 |
-
return 4.00
|
| 7 |
elif percent >= 85:
|
| 8 |
-
return 4.00
|
| 9 |
elif percent >= 80:
|
| 10 |
-
return 3.66 + (percent - 80) * (3.99 - 3.66) / (84.99 - 80)
|
| 11 |
elif percent >= 75:
|
| 12 |
-
return 3.33 + (percent - 75) * (3.65 - 3.33) / (79.99 - 75)
|
| 13 |
elif percent >= 71:
|
| 14 |
-
return 3.00 + (percent - 71) * (3.32 - 3.00) / (74.99 - 71)
|
| 15 |
elif percent >= 68:
|
| 16 |
-
return 2.66 + (percent - 68) * (2.99 - 2.66) / (70.99 - 68)
|
| 17 |
elif percent >= 61:
|
| 18 |
-
return 2.00 + (percent - 61) * (2.65 - 2.00) / (67.99 - 61)
|
| 19 |
elif percent >= 50:
|
| 20 |
-
return 1.00 + (percent - 50) * (1.99 - 1.00) / (60.99 - 50)
|
| 21 |
else:
|
| 22 |
-
return 0.00
|
| 23 |
|
| 24 |
# GPA calculation
|
| 25 |
def calculate_gpa(w_assign, w_quiz, w_gdb, w_mid, w_final,
|
| 26 |
p_assign, p_quiz, p_gdb, p_mid, p_final):
|
| 27 |
weights_sum = w_assign + w_quiz + w_gdb + w_mid + w_final
|
| 28 |
if weights_sum != 100:
|
| 29 |
-
return "⚠️ Total weightage must be 100%"
|
| 30 |
|
| 31 |
total_score = (
|
| 32 |
w_assign * p_assign +
|
|
@@ -36,8 +36,8 @@ def calculate_gpa(w_assign, w_quiz, w_gdb, w_mid, w_final,
|
|
| 36 |
w_final * p_final
|
| 37 |
) / 100
|
| 38 |
|
| 39 |
-
gpa = percentage_to_gpa(total_score)
|
| 40 |
-
return f"{gpa:.2f}"
|
| 41 |
|
| 42 |
# Build Gradio interface
|
| 43 |
with gr.Blocks(title="GPA Calculator") as app:
|
|
@@ -45,40 +45,35 @@ with gr.Blocks(title="GPA Calculator") as app:
|
|
| 45 |
# Custom CSS for HUGE GPA display
|
| 46 |
app.css = """
|
| 47 |
#gpa_big textarea {
|
| 48 |
-
font-size:
|
| 49 |
font-weight: bold;
|
| 50 |
text-align: center;
|
| 51 |
-
color: #1a73e8;
|
| 52 |
}
|
| 53 |
"""
|
| 54 |
|
| 55 |
gr.Markdown("## 📊 GPA Calculator (Out of 4)")
|
| 56 |
-
gr.Markdown("Enter weightages and achieved percentages. Use the slider for Final Term
|
|
|
|
|
|
|
| 57 |
|
| 58 |
with gr.Row():
|
| 59 |
# Weightages column
|
| 60 |
with gr.Column():
|
| 61 |
gr.Markdown("### Weightage (%)")
|
| 62 |
w_assign = gr.Number(value=10, label="Assignment")
|
| 63 |
-
w_quiz = gr.Number(value=
|
| 64 |
-
w_gdb = gr.Number(value=
|
| 65 |
-
w_mid = gr.Number(value=
|
| 66 |
-
w_final = gr.Number(value=
|
| 67 |
|
| 68 |
# Achieved percentages column
|
| 69 |
with gr.Column():
|
| 70 |
gr.Markdown("### Achieved (%)")
|
| 71 |
-
p_assign = gr.
|
| 72 |
-
p_quiz = gr.
|
| 73 |
-
p_gdb = gr.
|
| 74 |
-
p_mid = gr.
|
| 75 |
-
p_final = gr.Slider(
|
| 76 |
-
minimum=0,
|
| 77 |
-
maximum=100,
|
| 78 |
-
value=50,
|
| 79 |
-
step=1,
|
| 80 |
-
label="Final Term Percentage"
|
| 81 |
-
)
|
| 82 |
|
| 83 |
# GPA column
|
| 84 |
with gr.Column():
|
|
@@ -88,7 +83,11 @@ with gr.Blocks(title="GPA Calculator") as app:
|
|
| 88 |
inputs = [w_assign, w_quiz, w_gdb, w_mid, w_final,
|
| 89 |
p_assign, p_quiz, p_gdb, p_mid, p_final]
|
| 90 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 91 |
for inp in inputs:
|
| 92 |
-
inp.change(
|
| 93 |
|
| 94 |
app.launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
|
| 3 |
+
# Map percentage to GPA and color
|
| 4 |
def percentage_to_gpa(percent):
|
| 5 |
if percent >= 90:
|
| 6 |
+
return 4.00, "#00c853" # A+ Green
|
| 7 |
elif percent >= 85:
|
| 8 |
+
return 4.00, "#00c853" # A Green
|
| 9 |
elif percent >= 80:
|
| 10 |
+
return 3.66 + (percent - 80) * (3.99 - 3.66) / (84.99 - 80), "#64dd17" # A- Light Green
|
| 11 |
elif percent >= 75:
|
| 12 |
+
return 3.33 + (percent - 75) * (3.65 - 3.33) / (79.99 - 75), "#c6ff00" # B+ Yellow-Green
|
| 13 |
elif percent >= 71:
|
| 14 |
+
return 3.00 + (percent - 71) * (3.32 - 3.00) / (74.99 - 71), "#ffeb3b" # B Yellow
|
| 15 |
elif percent >= 68:
|
| 16 |
+
return 2.66 + (percent - 68) * (2.99 - 2.66) / (70.99 - 68), "#ffc107" # B- Orange
|
| 17 |
elif percent >= 61:
|
| 18 |
+
return 2.00 + (percent - 61) * (2.65 - 2.00) / (67.99 - 61), "#ff9800" # C Orange
|
| 19 |
elif percent >= 50:
|
| 20 |
+
return 1.00 + (percent - 50) * (1.99 - 1.00) / (60.99 - 50), "#f44336" # D Red
|
| 21 |
else:
|
| 22 |
+
return 0.00, "#b71c1c" # F Dark Red
|
| 23 |
|
| 24 |
# GPA calculation
|
| 25 |
def calculate_gpa(w_assign, w_quiz, w_gdb, w_mid, w_final,
|
| 26 |
p_assign, p_quiz, p_gdb, p_mid, p_final):
|
| 27 |
weights_sum = w_assign + w_quiz + w_gdb + w_mid + w_final
|
| 28 |
if weights_sum != 100:
|
| 29 |
+
return "⚠️ Total weightage must be 100%", "#000000"
|
| 30 |
|
| 31 |
total_score = (
|
| 32 |
w_assign * p_assign +
|
|
|
|
| 36 |
w_final * p_final
|
| 37 |
) / 100
|
| 38 |
|
| 39 |
+
gpa, color = percentage_to_gpa(total_score)
|
| 40 |
+
return f"{gpa:.2f}", color
|
| 41 |
|
| 42 |
# Build Gradio interface
|
| 43 |
with gr.Blocks(title="GPA Calculator") as app:
|
|
|
|
| 45 |
# Custom CSS for HUGE GPA display
|
| 46 |
app.css = """
|
| 47 |
#gpa_big textarea {
|
| 48 |
+
font-size: 120px !important;
|
| 49 |
font-weight: bold;
|
| 50 |
text-align: center;
|
|
|
|
| 51 |
}
|
| 52 |
"""
|
| 53 |
|
| 54 |
gr.Markdown("## 📊 GPA Calculator (Out of 4)")
|
| 55 |
+
gr.Markdown("Enter weightages and achieved percentages. Use the slider for Final Term. GPA updates live!")
|
| 56 |
+
|
| 57 |
+
options = [5, 10, 15, 20, 30, 50, 60] # Drop-down options for achieved percentages
|
| 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():
|
|
|
|
| 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 |
for inp in inputs:
|
| 91 |
+
inp.change(update_gpa, inputs=inputs, outputs=gpa_display)
|
| 92 |
|
| 93 |
app.launch()
|