Spaces:
Sleeping
Sleeping
File size: 1,926 Bytes
576c11b |
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 |
import gradio as gr
import pandas as pd
# Global list to store student data
student_data = []
# Function to calculate and store the grade
def calculate_grade(name, id, pass_criteria, merit_criteria, distinct_criteria):
total_criteria = pass_criteria + merit_criteria + distinct_criteria
grade = "Not Achieved"
if pass_criteria == 11 or (pass_criteria >= 8 and total_criteria >= 12):
grade = "P"
if pass_criteria >= 8 and merit_criteria >= 6 and total_criteria >= 17:
grade = "M"
if pass_criteria >= 8 and merit_criteria >= 6 and distinct_criteria >= 3 and total_criteria >= 20:
grade = "D"
student_data.append([name, id, grade])
return f"Added: {name}, {id}, {grade}"
# Function to export data to Excel
def export_to_excel():
if not student_data:
return "No data to export."
df = pd.DataFrame(student_data, columns=["Name", "ID", "Grade"])
df.to_excel("grades.xlsx", index=False)
return "Data exported to grades.xlsx"
# Gradio interface
with gr.Blocks() as app:
gr.Markdown("Student Grading App")
with gr.Row():
name = gr.Textbox(label="Student Name")
id = gr.Number(label="Student ID", precision=0)
with gr.Row():
pass_criteria = gr.Slider(minimum=0, maximum=11, label="Pass Criteria Met")
merit_criteria = gr.Slider(minimum=0, maximum=8, label="Merit Criteria Met")
distinct_criteria = gr.Slider(minimum=0, maximum=4, label="Distinct Criteria Met")
with gr.Row():
grade_button = gr.Button("Add Student")
export_button = gr.Button("Export to Excel")
output = gr.Textbox(label="Output", lines=2)
export_status = gr.Text(label="Export Status")
grade_button.click(calculate_grade, inputs=[name, id, pass_criteria, merit_criteria, distinct_criteria], outputs=output)
export_button.click(export_to_excel, inputs=[], outputs=export_status)
app.launch()
|