| import gradio as gr |
| import pandas as pd |
|
|
| def process_marksheet(file): |
| df = pd.read_csv(file.name) |
|
|
| |
| subjects = ["Mathematics", "Science", "English", "Social_Studies", "Computer_Science"] |
| df["Total"] = df[subjects].sum(axis=1) |
|
|
| |
| df["Percentage"] = (df["Total"] / 500) * 100 |
|
|
| output_file = "updated_marksheet.csv" |
| df.to_csv(output_file, index=False) |
|
|
| return df, output_file |
|
|
| with gr.Blocks() as demo: |
| gr.Markdown("# 📊 Student Marksheet Processor") |
| gr.Markdown("Upload a CSV file to calculate Total and Percentage.") |
|
|
| file_input = gr.File(file_types=[".csv"]) |
| process_btn = gr.Button("Process Marksheet") |
|
|
| output_table = gr.Dataframe() |
| download_file = gr.File(label="Download Updated CSV") |
|
|
| process_btn.click( |
| process_marksheet, |
| inputs=file_input, |
| outputs=[output_table, download_file] |
| ) |
|
|
| demo.launch() |