Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -4,14 +4,20 @@ import matplotlib.pyplot as plt
|
|
| 4 |
import pandas as pd
|
| 5 |
import os
|
| 6 |
from sklearn.ensemble import RandomForestRegressor
|
|
|
|
| 7 |
|
| 8 |
# --------------------------------------------------
|
| 9 |
-
#
|
| 10 |
# --------------------------------------------------
|
| 11 |
-
|
| 12 |
|
| 13 |
CSV_FILE = "student_analysis_database.csv"
|
| 14 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
INSTITUTION_HTML = """
|
| 16 |
<div style="text-align:center">
|
| 17 |
<h2>Srinivasa Ramanujan Centre,<br>
|
|
@@ -21,12 +27,11 @@ SASTRA Deemed to be University, Kumbakonam</h2>
|
|
| 21 |
"""
|
| 22 |
|
| 23 |
# --------------------------------------------------
|
| 24 |
-
# TRAIN
|
| 25 |
# --------------------------------------------------
|
| 26 |
np.random.seed(42)
|
| 27 |
|
| 28 |
X_train = np.random.uniform(1,10,(400,15))
|
| 29 |
-
|
| 30 |
y_train = (
|
| 31 |
0.15*X_train[:,1] +
|
| 32 |
0.15*X_train[:,2] +
|
|
@@ -46,19 +51,17 @@ model.fit(X_train,y_train)
|
|
| 46 |
def calculate_iq(reasoning, aptitude, problem_solving,
|
| 47 |
verbal, communication, understanding):
|
| 48 |
|
| 49 |
-
|
| 50 |
0.25*reasoning +
|
| 51 |
0.20*aptitude +
|
| 52 |
0.20*problem_solving +
|
| 53 |
0.15*verbal +
|
| 54 |
0.10*communication +
|
| 55 |
0.10*understanding
|
| 56 |
-
) * 10
|
| 57 |
-
|
| 58 |
-
return round(iq,2)
|
| 59 |
|
| 60 |
# --------------------------------------------------
|
| 61 |
-
# MAIN
|
| 62 |
# --------------------------------------------------
|
| 63 |
def institutional_ai(
|
| 64 |
name, regno, vision, mission, arrears,
|
|
@@ -82,39 +85,32 @@ def institutional_ai(
|
|
| 82 |
|
| 83 |
performance = float(model.predict(features)[0])
|
| 84 |
|
| 85 |
-
# Weak areas
|
| 86 |
weak=[]
|
| 87 |
if coding<5: weak.append("Coding")
|
| 88 |
if aptitude<5: weak.append("Aptitude")
|
| 89 |
if communication<5: weak.append("Communication")
|
| 90 |
-
if sg6<sg4: weak.append("Academic Consistency")
|
| 91 |
|
| 92 |
concentration=", ".join(weak) if weak else "Balanced Skill Profile"
|
| 93 |
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
|
| 102 |
advice="Improve weak areas and maintain academic consistency."
|
| 103 |
|
| 104 |
-
# ----------------
|
| 105 |
-
# GRAPHS
|
| 106 |
-
# --------------------------------------------------
|
| 107 |
fig1=plt.figure()
|
| 108 |
plt.bar(["Performance"],[performance])
|
| 109 |
plt.ylim(0,100)
|
| 110 |
-
plt.title(f"{name}
|
| 111 |
|
| 112 |
-
sgpas=[sg1,sg2,sg3,sg4,sg5,sg6]
|
| 113 |
fig2=plt.figure()
|
| 114 |
-
plt.plot(range(1,7),
|
| 115 |
-
plt.title("
|
| 116 |
-
plt.xlabel("Semester")
|
| 117 |
-
plt.ylabel("SGPA")
|
| 118 |
|
| 119 |
labels=['Understanding','Coding','ProblemSolving',
|
| 120 |
'Aptitude','Communication','Presentation']
|
|
@@ -130,23 +126,6 @@ def institutional_ai(
|
|
| 130 |
ax.plot(angles,skills)
|
| 131 |
ax.fill(angles,skills,alpha=0.2)
|
| 132 |
ax.set_thetagrids(angles[:-1]*180/np.pi,labels)
|
| 133 |
-
ax.set_title("Skill Analysis")
|
| 134 |
-
|
| 135 |
-
# --------------------------------------------------
|
| 136 |
-
# REPORT
|
| 137 |
-
# --------------------------------------------------
|
| 138 |
-
report=f"""
|
| 139 |
-
Student: {name} ({regno})
|
| 140 |
-
|
| 141 |
-
Predicted Performance : {round(performance,2)}
|
| 142 |
-
Estimated IQ : {iq}
|
| 143 |
-
|
| 144 |
-
Focus Areas:
|
| 145 |
-
{concentration}
|
| 146 |
-
|
| 147 |
-
Placement Outlook:
|
| 148 |
-
{placement}
|
| 149 |
-
"""
|
| 150 |
|
| 151 |
# Save CSV
|
| 152 |
df=pd.DataFrame([{
|
|
@@ -154,8 +133,7 @@ Placement Outlook:
|
|
| 154 |
"RegisterNo":regno,
|
| 155 |
"CGPA":cgpa,
|
| 156 |
"IQ":iq,
|
| 157 |
-
"Performance":round(performance,2)
|
| 158 |
-
"Placement":placement
|
| 159 |
}])
|
| 160 |
|
| 161 |
if os.path.exists(CSV_FILE):
|
|
@@ -163,6 +141,8 @@ Placement Outlook:
|
|
| 163 |
else:
|
| 164 |
df.to_csv(CSV_FILE,index=False)
|
| 165 |
|
|
|
|
|
|
|
| 166 |
return (round(performance,2),iq,concentration,
|
| 167 |
placement,advice,report,fig1,fig2,fig3)
|
| 168 |
|
|
@@ -171,10 +151,12 @@ Placement Outlook:
|
|
| 171 |
# --------------------------------------------------
|
| 172 |
with gr.Blocks() as demo:
|
| 173 |
|
| 174 |
-
# Logo
|
| 175 |
-
if
|
| 176 |
-
gr.Image(
|
| 177 |
-
|
|
|
|
|
|
|
| 178 |
|
| 179 |
gr.HTML(INSTITUTION_HTML)
|
| 180 |
|
|
@@ -186,16 +168,13 @@ with gr.Blocks() as demo:
|
|
| 186 |
gr.Textbox(label="Vision"),
|
| 187 |
gr.Textbox(label="Mission"),
|
| 188 |
gr.Slider(0,10,label="Arrears"),
|
| 189 |
-
|
| 190 |
-
gr.Slider(0,10,label="SGPA
|
| 191 |
-
gr.Slider(0,10,label="SGPA
|
| 192 |
-
gr.Slider(0,10,label="SGPA
|
| 193 |
-
gr.Slider(0,10,label="SGPA
|
| 194 |
-
gr.Slider(0,10,label="SGPA
|
| 195 |
-
gr.Slider(0,10,label="SGPA Semester 6"),
|
| 196 |
-
|
| 197 |
gr.Slider(0,10,label="CGPA"),
|
| 198 |
-
|
| 199 |
gr.Slider(1,10,label="Understanding"),
|
| 200 |
gr.Slider(1,10,label="Coding"),
|
| 201 |
gr.Slider(1,10,label="Problem Solving"),
|
|
@@ -208,17 +187,16 @@ with gr.Blocks() as demo:
|
|
| 208 |
gr.Slider(1,10,label="Group Discussion"),
|
| 209 |
gr.Slider(1,10,label="Daily Study Time")
|
| 210 |
],
|
| 211 |
-
|
| 212 |
outputs=[
|
| 213 |
gr.Number(label="Predicted Performance"),
|
| 214 |
gr.Number(label="Estimated IQ"),
|
| 215 |
gr.Textbox(label="Concentration Areas"),
|
| 216 |
-
gr.Textbox(label="Placement
|
| 217 |
gr.Textbox(label="Advice"),
|
| 218 |
-
gr.Textbox(label="
|
| 219 |
-
gr.Plot(
|
| 220 |
-
gr.Plot(
|
| 221 |
-
gr.Plot(
|
| 222 |
]
|
| 223 |
)
|
| 224 |
|
|
|
|
| 4 |
import pandas as pd
|
| 5 |
import os
|
| 6 |
from sklearn.ensemble import RandomForestRegressor
|
| 7 |
+
from PIL import Image
|
| 8 |
|
| 9 |
# --------------------------------------------------
|
| 10 |
+
# LOGO PATH (DESKTOP)
|
| 11 |
# --------------------------------------------------
|
| 12 |
+
LOGO_PATH = r"C:\Users\SASTRA\Desktop\sastra_logo.jpg"
|
| 13 |
|
| 14 |
CSV_FILE = "student_analysis_database.csv"
|
| 15 |
|
| 16 |
+
# Load logo safely into memory
|
| 17 |
+
logo_image = None
|
| 18 |
+
if os.path.exists(LOGO_PATH):
|
| 19 |
+
logo_image = Image.open(LOGO_PATH)
|
| 20 |
+
|
| 21 |
INSTITUTION_HTML = """
|
| 22 |
<div style="text-align:center">
|
| 23 |
<h2>Srinivasa Ramanujan Centre,<br>
|
|
|
|
| 27 |
"""
|
| 28 |
|
| 29 |
# --------------------------------------------------
|
| 30 |
+
# TRAIN MODEL
|
| 31 |
# --------------------------------------------------
|
| 32 |
np.random.seed(42)
|
| 33 |
|
| 34 |
X_train = np.random.uniform(1,10,(400,15))
|
|
|
|
| 35 |
y_train = (
|
| 36 |
0.15*X_train[:,1] +
|
| 37 |
0.15*X_train[:,2] +
|
|
|
|
| 51 |
def calculate_iq(reasoning, aptitude, problem_solving,
|
| 52 |
verbal, communication, understanding):
|
| 53 |
|
| 54 |
+
return round((
|
| 55 |
0.25*reasoning +
|
| 56 |
0.20*aptitude +
|
| 57 |
0.20*problem_solving +
|
| 58 |
0.15*verbal +
|
| 59 |
0.10*communication +
|
| 60 |
0.10*understanding
|
| 61 |
+
) * 10, 2)
|
|
|
|
|
|
|
| 62 |
|
| 63 |
# --------------------------------------------------
|
| 64 |
+
# MAIN FUNCTION
|
| 65 |
# --------------------------------------------------
|
| 66 |
def institutional_ai(
|
| 67 |
name, regno, vision, mission, arrears,
|
|
|
|
| 85 |
|
| 86 |
performance = float(model.predict(features)[0])
|
| 87 |
|
|
|
|
| 88 |
weak=[]
|
| 89 |
if coding<5: weak.append("Coding")
|
| 90 |
if aptitude<5: weak.append("Aptitude")
|
| 91 |
if communication<5: weak.append("Communication")
|
|
|
|
| 92 |
|
| 93 |
concentration=", ".join(weak) if weak else "Balanced Skill Profile"
|
| 94 |
|
| 95 |
+
placement = (
|
| 96 |
+
"High Probability → Product Companies"
|
| 97 |
+
if performance>=80 and cgpa>=8
|
| 98 |
+
else "Moderate Probability → Service Companies"
|
| 99 |
+
if performance>=65
|
| 100 |
+
else "Needs Skill Improvement"
|
| 101 |
+
)
|
| 102 |
|
| 103 |
advice="Improve weak areas and maintain academic consistency."
|
| 104 |
|
| 105 |
+
# -------- Graphs --------
|
|
|
|
|
|
|
| 106 |
fig1=plt.figure()
|
| 107 |
plt.bar(["Performance"],[performance])
|
| 108 |
plt.ylim(0,100)
|
| 109 |
+
plt.title(f"{name} Performance")
|
| 110 |
|
|
|
|
| 111 |
fig2=plt.figure()
|
| 112 |
+
plt.plot(range(1,7),[sg1,sg2,sg3,sg4,sg5,sg6],marker='o')
|
| 113 |
+
plt.title("SGPA Trend")
|
|
|
|
|
|
|
| 114 |
|
| 115 |
labels=['Understanding','Coding','ProblemSolving',
|
| 116 |
'Aptitude','Communication','Presentation']
|
|
|
|
| 126 |
ax.plot(angles,skills)
|
| 127 |
ax.fill(angles,skills,alpha=0.2)
|
| 128 |
ax.set_thetagrids(angles[:-1]*180/np.pi,labels)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 129 |
|
| 130 |
# Save CSV
|
| 131 |
df=pd.DataFrame([{
|
|
|
|
| 133 |
"RegisterNo":regno,
|
| 134 |
"CGPA":cgpa,
|
| 135 |
"IQ":iq,
|
| 136 |
+
"Performance":round(performance,2)
|
|
|
|
| 137 |
}])
|
| 138 |
|
| 139 |
if os.path.exists(CSV_FILE):
|
|
|
|
| 141 |
else:
|
| 142 |
df.to_csv(CSV_FILE,index=False)
|
| 143 |
|
| 144 |
+
report=f"Student: {name}\nPerformance: {round(performance,2)}\nIQ: {iq}"
|
| 145 |
+
|
| 146 |
return (round(performance,2),iq,concentration,
|
| 147 |
placement,advice,report,fig1,fig2,fig3)
|
| 148 |
|
|
|
|
| 151 |
# --------------------------------------------------
|
| 152 |
with gr.Blocks() as demo:
|
| 153 |
|
| 154 |
+
# Logo centered (NOW ALWAYS WORKS)
|
| 155 |
+
if logo_image is not None:
|
| 156 |
+
gr.Image(value=logo_image,
|
| 157 |
+
show_label=False,
|
| 158 |
+
container=False,
|
| 159 |
+
height=160)
|
| 160 |
|
| 161 |
gr.HTML(INSTITUTION_HTML)
|
| 162 |
|
|
|
|
| 168 |
gr.Textbox(label="Vision"),
|
| 169 |
gr.Textbox(label="Mission"),
|
| 170 |
gr.Slider(0,10,label="Arrears"),
|
| 171 |
+
gr.Slider(0,10,label="SGPA 1"),
|
| 172 |
+
gr.Slider(0,10,label="SGPA 2"),
|
| 173 |
+
gr.Slider(0,10,label="SGPA 3"),
|
| 174 |
+
gr.Slider(0,10,label="SGPA 4"),
|
| 175 |
+
gr.Slider(0,10,label="SGPA 5"),
|
| 176 |
+
gr.Slider(0,10,label="SGPA 6"),
|
|
|
|
|
|
|
| 177 |
gr.Slider(0,10,label="CGPA"),
|
|
|
|
| 178 |
gr.Slider(1,10,label="Understanding"),
|
| 179 |
gr.Slider(1,10,label="Coding"),
|
| 180 |
gr.Slider(1,10,label="Problem Solving"),
|
|
|
|
| 187 |
gr.Slider(1,10,label="Group Discussion"),
|
| 188 |
gr.Slider(1,10,label="Daily Study Time")
|
| 189 |
],
|
|
|
|
| 190 |
outputs=[
|
| 191 |
gr.Number(label="Predicted Performance"),
|
| 192 |
gr.Number(label="Estimated IQ"),
|
| 193 |
gr.Textbox(label="Concentration Areas"),
|
| 194 |
+
gr.Textbox(label="Placement"),
|
| 195 |
gr.Textbox(label="Advice"),
|
| 196 |
+
gr.Textbox(label="Report"),
|
| 197 |
+
gr.Plot(),
|
| 198 |
+
gr.Plot(),
|
| 199 |
+
gr.Plot()
|
| 200 |
]
|
| 201 |
)
|
| 202 |
|