Upload Pearson_Grader.py
Browse files- Pearson_Grader.py +51 -0
Pearson_Grader.py
ADDED
@@ -0,0 +1,51 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import pandas as pd
|
3 |
+
|
4 |
+
# Global list to store student data
|
5 |
+
student_data = []
|
6 |
+
|
7 |
+
# Function to calculate and store the grade
|
8 |
+
def calculate_grade(name, id, pass_criteria, merit_criteria, distinct_criteria):
|
9 |
+
total_criteria = pass_criteria + merit_criteria + distinct_criteria
|
10 |
+
grade = "Not Achieved"
|
11 |
+
|
12 |
+
if pass_criteria == 11 or (pass_criteria >= 8 and total_criteria >= 12):
|
13 |
+
grade = "P"
|
14 |
+
if pass_criteria >= 8 and merit_criteria >= 6 and total_criteria >= 17:
|
15 |
+
grade = "M"
|
16 |
+
if pass_criteria >= 8 and merit_criteria >= 6 and distinct_criteria >= 3 and total_criteria >= 20:
|
17 |
+
grade = "D"
|
18 |
+
|
19 |
+
student_data.append([name, id, grade])
|
20 |
+
return f"Added: {name}, {id}, {grade}"
|
21 |
+
|
22 |
+
# Function to export data to Excel
|
23 |
+
def export_to_excel():
|
24 |
+
if not student_data:
|
25 |
+
return "No data to export."
|
26 |
+
|
27 |
+
df = pd.DataFrame(student_data, columns=["Name", "ID", "Grade"])
|
28 |
+
df.to_excel("grades.xlsx", index=False)
|
29 |
+
return "Data exported to grades.xlsx"
|
30 |
+
|
31 |
+
# Gradio interface
|
32 |
+
with gr.Blocks() as app:
|
33 |
+
gr.Markdown("Student Grading App")
|
34 |
+
with gr.Row():
|
35 |
+
name = gr.Textbox(label="Student Name")
|
36 |
+
id = gr.Number(label="Student ID", precision=0)
|
37 |
+
with gr.Row():
|
38 |
+
pass_criteria = gr.Slider(minimum=0, maximum=11, label="Pass Criteria Met")
|
39 |
+
merit_criteria = gr.Slider(minimum=0, maximum=8, label="Merit Criteria Met")
|
40 |
+
distinct_criteria = gr.Slider(minimum=0, maximum=4, label="Distinct Criteria Met")
|
41 |
+
with gr.Row():
|
42 |
+
grade_button = gr.Button("Add Student")
|
43 |
+
export_button = gr.Button("Export to Excel")
|
44 |
+
output = gr.Textbox(label="Output", lines=2)
|
45 |
+
export_status = gr.Text(label="Export Status")
|
46 |
+
grade_button.click(calculate_grade, inputs=[name, id, pass_criteria, merit_criteria, distinct_criteria], outputs=output)
|
47 |
+
export_button.click(export_to_excel, inputs=[], outputs=export_status)
|
48 |
+
|
49 |
+
app.launch(share=True)
|
50 |
+
|
51 |
+
|