|
import gradio as gr |
|
import pandas as pd |
|
import matplotlib.pyplot as plt |
|
import os |
|
|
|
|
|
def visualize_progress(file): |
|
|
|
if file is None: |
|
return "No file uploaded!" |
|
|
|
try: |
|
|
|
df = pd.read_csv(file.name) |
|
|
|
|
|
required_columns = {'student_name', 'date', 'score'} |
|
if not required_columns.issubset(df.columns): |
|
return "CSV should contain 'student_name', 'date', and 'score' columns." |
|
|
|
|
|
plt.figure(figsize=(10, 6)) |
|
for student in df['student_name'].unique(): |
|
student_data = df[df['student_name'] == student] |
|
plt.plot(student_data['date'], student_data['score'], label=student) |
|
|
|
|
|
plt.xlabel('Date') |
|
plt.ylabel('Score') |
|
plt.title('Student Progress Over Time') |
|
plt.legend() |
|
plt.grid(True) |
|
|
|
|
|
plot_filename = "progress.png" |
|
plt.savefig(plot_filename) |
|
plt.close() |
|
|
|
return plot_filename |
|
|
|
except Exception as e: |
|
return f"Error: {e}" |
|
|
|
|
|
with gr.Blocks() as demo: |
|
gr.Markdown("# Student Progress Analysis Tool") |
|
|
|
|
|
file_input = gr.File(label="Upload Student Data (CSV)") |
|
output_image = gr.Image(label="Progress Chart") |
|
|
|
|
|
file_input.change(visualize_progress, inputs=file_input, outputs=output_image) |
|
|
|
|
|
demo.launch() |
|
|