File size: 1,714 Bytes
597120e
 
 
5fefb8a
597120e
 
 
5fefb8a
 
 
597120e
5fefb8a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
597120e
 
 
 
 
5fefb8a
597120e
 
 
5fefb8a
597120e
 
5fefb8a
 
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
53
54
55
56
57
import gradio as gr
import pandas as pd
import matplotlib.pyplot as plt
import os

# Function to visualize student progress
def visualize_progress(file):
    # Check if the file is a valid CSV file
    if file is None:
        return "No file uploaded!"
    
    try:
        # Read the CSV file using pandas
        df = pd.read_csv(file.name)

        # Check if required columns exist in the CSV
        required_columns = {'student_name', 'date', 'score'}
        if not required_columns.issubset(df.columns):
            return "CSV should contain 'student_name', 'date', and 'score' columns."

        # Create a progress plot for each student
        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)

        # Customize the chart
        plt.xlabel('Date')
        plt.ylabel('Score')
        plt.title('Student Progress Over Time')
        plt.legend()
        plt.grid(True)

        # Save the plot to a file
        plot_filename = "progress.png"
        plt.savefig(plot_filename)
        plt.close()

        return plot_filename
    
    except Exception as e:
        return f"Error: {e}"

# Gradio UI
with gr.Blocks() as demo:
    gr.Markdown("# Student Progress Analysis Tool")

    # File input for CSV and display output
    file_input = gr.File(label="Upload Student Data (CSV)")
    output_image = gr.Image(label="Progress Chart")

    # Call the visualize_progress function when the file changes
    file_input.change(visualize_progress, inputs=file_input, outputs=output_image)

# Launch the Gradio app
demo.launch()