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()