File size: 6,012 Bytes
f218349
 
 
 
 
 
f61583d
f218349
 
8125c72
f218349
f61583d
8a38616
8125c72
f61583d
8125c72
f218349
 
8125c72
f218349
 
 
 
 
 
 
 
 
 
 
 
 
 
8a38616
f218349
 
 
00d210a
f218349
 
 
 
f61583d
f218349
 
 
 
 
 
f61583d
f218349
 
f61583d
f218349
543332b
f218349
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8a38616
f218349
 
 
 
 
 
 
 
f61583d
 
 
 
 
 
 
f218349
 
 
8125c72
f218349
 
 
 
 
f61583d
f218349
 
 
 
 
 
 
 
 
 
 
 
 
 
 
f61583d
 
8125c72
 
f218349
 
8125c72
f218349
 
 
8125c72
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
f218349
 
8a38616
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
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(
        """
        <div style='text-align:center'>
        <h2>Srinivasa Ramanujan Centre,<br>
        SASTRA Deemed to be University, Kumbakonam</h2>
        <h3>Student Performance Analysis</h3>
        </div>
        """
    )

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