import gradio as gr import numpy as np import matplotlib.pyplot as plt import pandas as pd import os from sklearn.ensemble import RandomForestRegressor from PIL import Image # -------------------------------------------------- # LOGO PATH # -------------------------------------------------- LOGO_PATH = r"C:\Users\SASTRA\Desktop\sastra_logo.jpg" logo_img = Image.open(LOGO_PATH) if os.path.exists(LOGO_PATH) else None CSV_FILE = "student_analysis_database.csv" # -------------------------------------------------- # MODEL TRAINING # -------------------------------------------------- np.random.seed(42) X_train = np.random.uniform(1,10,(400,15)) y_train = ( 0.15*X_train[:,1] + 0.15*X_train[:,2] + 0.18*X_train[:,3] + 0.14*X_train[:,4] + 0.10*X_train[:,5] + 0.10*X_train[:,6] + 0.18*X_train[:,7] ) * 8 model = RandomForestRegressor(n_estimators=150, random_state=42) model.fit(X_train,y_train) # -------------------------------------------------- # IQ CALCULATION # -------------------------------------------------- def calculate_iq(reasoning, aptitude, problem_solving, verbal, communication, understanding): return round(( 0.25*reasoning + 0.20*aptitude + 0.20*problem_solving + 0.15*verbal + 0.10*communication + 0.10*understanding ) * 10, 2) # -------------------------------------------------- # MAIN FUNCTION # -------------------------------------------------- def institutional_ai( name, regno, vision, mission, arrears, sg1, sg2, sg3, sg4, sg5, sg6, cgpa, understanding, coding, problem_solving, presentation, aptitude, reasoning, verbal, communication, team_building, group_discussion, study_time): iq = calculate_iq(reasoning, aptitude, problem_solving, verbal, communication, understanding) features = np.array([[ arrears, sg1, sg2, sg3, sg4, sg5, sg6, cgpa, coding, problem_solving, aptitude, communication, iq, study_time, presentation ]]) performance = float(model.predict(features)[0]) weak=[] if coding<5: weak.append("Coding") if aptitude<5: weak.append("Aptitude") if communication<5: weak.append("Communication") concentration=", ".join(weak) if weak else "Balanced Skill Profile" placement = ( "High Probability → Product Companies" if performance>=80 and cgpa>=8 else "Moderate Probability → Service Companies" if performance>=65 else "Needs Skill Improvement" ) advice="Improve weak areas and maintain academic consistency." # ---------- Graphs ---------- fig1=plt.figure() plt.bar(["Performance"],[performance]) plt.ylim(0,100) fig2=plt.figure() plt.plot(range(1,7),[sg1,sg2,sg3,sg4,sg5,sg6],marker='o') labels=['Understanding','Coding','ProblemSolving', 'Aptitude','Communication','Presentation'] skills=[understanding,coding,problem_solving, aptitude,communication,presentation] angles=np.linspace(0,2*np.pi,len(labels),endpoint=False) skills=np.concatenate((skills,[skills[0]])) angles=np.concatenate((angles,[angles[0]])) fig3=plt.figure() ax=fig3.add_subplot(111,polar=True) ax.plot(angles,skills) ax.fill(angles,skills,alpha=0.2) report=f"Student: {name}\nPerformance: {round(performance,2)}\nIQ: {iq}" return performance, iq, concentration, placement, advice, report, fig1, fig2, fig3 # -------------------------------------------------- # UI USING BLOCKS ONLY (KEY FIX) # -------------------------------------------------- with gr.Blocks() as demo: # LOGO CENTERED if logo_img is not None: gr.Image(value=logo_img, show_label=False, height=160) gr.Markdown( """

Srinivasa Ramanujan Centre,
SASTRA Deemed to be University, Kumbakonam

Student Performance Analysis

""" ) # INPUTS name = gr.Textbox(label="Student Name") regno = gr.Textbox(label="Register Number") vision = gr.Textbox(label="Vision") mission = gr.Textbox(label="Mission") arrears = gr.Slider(0,10,label="Arrears") sg1 = gr.Slider(0,10,label="SGPA 1") sg2 = gr.Slider(0,10,label="SGPA 2") sg3 = gr.Slider(0,10,label="SGPA 3") sg4 = gr.Slider(0,10,label="SGPA 4") sg5 = gr.Slider(0,10,label="SGPA 5") sg6 = gr.Slider(0,10,label="SGPA 6") cgpa = gr.Slider(0,10,label="CGPA") understanding = gr.Slider(1,10,label="Understanding") coding = gr.Slider(1,10,label="Coding") problem_solving = gr.Slider(1,10,label="Problem Solving") presentation = gr.Slider(1,10,label="Presentation") aptitude = gr.Slider(1,10,label="Aptitude") reasoning = gr.Slider(1,10,label="Reasoning") verbal = gr.Slider(1,10,label="Verbal") communication = gr.Slider(1,10,label="Communication") team_building = gr.Slider(1,10,label="Team Building") group_discussion = gr.Slider(1,10,label="Group Discussion") study_time = gr.Slider(1,10,label="Daily Study Time") submit = gr.Button("Analyze Student") # OUTPUTS out1 = gr.Number(label="Predicted Performance") out2 = gr.Number(label="Estimated IQ") out3 = gr.Textbox(label="Concentration Areas") out4 = gr.Textbox(label="Placement") out5 = gr.Textbox(label="Advice") out6 = gr.Textbox(label="Report") plot1 = gr.Plot() plot2 = gr.Plot() plot3 = gr.Plot() submit.click( institutional_ai, inputs=[name,regno,vision,mission,arrears, sg1,sg2,sg3,sg4,sg5,sg6,cgpa, understanding,coding,problem_solving, presentation,aptitude,reasoning, verbal,communication,team_building, group_discussion,study_time], outputs=[out1,out2,out3,out4,out5,out6,plot1,plot2,plot3] ) demo.launch(inbrowser=True)