File size: 1,787 Bytes
7b0679a
 
 
 
 
 
3330ec7
7b0679a
f387c69
 
 
 
 
 
 
 
 
7b0679a
 
f387c69
 
 
 
 
 
 
 
 
7b0679a
 
f387c69
 
 
 
 
 
 
 
 
 
 
7b0679a
f387c69
3675014
7b0679a
f387c69
7b0679a
f387c69
 
7b0679a
3330ec7
7b0679a
3330ec7
 
 
 
 
 
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
58
59
import pandas as pd
import matplotlib.pyplot as plt
import numpy as np
import gradio as gr

def analyze(file):
    df = pd.read_csv(file)

    # Clean percentage column (remove % and convert to int)
    df["Percentage"] = df["Percentage"].str.replace("%", "").astype(float)

    subjects = df["Subjects"]
    percentages = df["Percentage"]

    best = subjects[percentages.idxmax()]
    weak = subjects[percentages.idxmin()]
    avg = np.mean(percentages)

    remarks = []
    for subj, perc in zip(subjects, percentages):
        if perc <= 33:
            remarks.append(f"❌ {subj}: {perc}% → Fail. Needs to reappear.")
        elif 34 <= perc <= 70:
            remarks.append(f"⚠️ {subj}: {perc}% → Average. Needs improvement.")
        elif 71 <= perc <= 89:
            remarks.append(f"✅ {subj}: {perc}% → Good. Did great!")
        else:  # 90-100
            remarks.append(f"🌟 {subj}: {perc}% → Amazing performance!")

    # Plot
    colors = []
    for subj, perc in zip(subjects, percentages):
        if perc <= 33:
            colors.append("red")
        elif perc <= 70:
            colors.append("orange")
        elif perc <= 89:
            colors.append("skyblue")
        else:
            colors.append("green")

    plt.figure(figsize=(6,4))
    plt.bar(subjects, percentages, color=colors, edgecolor="black")
    plt.axhline(avg, color="purple", linestyle="--", label=f"Numerical Average of Subjects: {avg:.2f}%")
    plt.legend()
    plt.title("Student Performance Analysis")
    plt.xlabel("Subjects")
    plt.ylabel("Percentage (%)")
    plt.ylim(0, 110)
    
    return "\n".join(remarks), plt.gcf()

app = gr.Interface(
    fn=analyze, 
    inputs=gr.File(label="Upload CSV", type="filepath"),
    outputs=["text", "plot"]
)
app.launch()