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