-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
522 lines (469 loc) · 28.3 KB
/
app.py
File metadata and controls
522 lines (469 loc) · 28.3 KB
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
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
"""
GradeScope — CGPA Predictor · Flask Backend
============================================
Architecture:
- 5-page HTML frontend served from /
- Single POST endpoint /api/predict
Encoding reference (matches training data exactly):
Career alignment / Participation / Peer behaviour / Interest / Difficulty (student-perceived)
Very Poor/Very Low = 1 | Poor/Low = 2 | Good/High = 4 | Very Strong/Very High = 5
(scale jumps 2→4, skipping 3 — matches original survey encoding)
Seating: Front = 1 | Random = 3 | Back = 5
Teacher: Poor+Strict = 1 | Good+Strict = 3 | Poor+Friendly = 4 | Good+Friendly = 6
Attendance: Below 60% = 1 | 60-75% = 2 | 75-90% = 3 | 91-100% = 4
ec_difference = extracurricular_encoded (1/2/4/5) − absolute_difficulty_from_CSV (1-4)
diff_alignment = career_alignment_encoded − student_perceived_difficulty
relative_diff = predicted_sgpa − absolute_difficulty [computed inline]
"""
from flask import Flask, render_template, request, jsonify
import pickle, json, traceback
import numpy as np
import os
app = Flask(__name__)
BASE = os.path.dirname(__file__)
# ── Load trained models ───────────────────────────────────────────
def _load(name):
with open(os.path.join(BASE, 'models', name), 'rb') as f:
return pickle.load(f)
rf_model = _load('rf_model.pkl')
gb_model = _load('gb_model.pkl')
et_model = _load('et_model.pkl')
ridge_model = _load('ridge_model.pkl')
imputer = _load('imputer.pkl')
scaler = _load('scaler.pkl')
with open(os.path.join(BASE, 'models', 'model_stats.json')) as f:
STATS = json.load(f)
FEATURE_COLS = STATS['feature_cols']
W = STATS['ensemble_weights'] # {rf, gb, et, ridge}
W_TOTAL = sum(W.values())
# ── Subject metadata ──────────────────────────────────────────────
SUBJECTS_DATA = {
# Institute Core
"Engineering Drawing and Sketching": {"credits": 1, "abs_diff": 3},
"Basic Economics": {"credits": 2, "abs_diff": 1},
"English Communication Skills": {"credits": 2, "abs_diff": 1},
"Introduction to Mechanical Systems": {"credits": 2, "abs_diff": 2},
"Modern Physics": {"credits": 3, "abs_diff": 3},
"Mathematics II": {"credits": 4, "abs_diff": 4},
"Classical Physics": {"credits": 3, "abs_diff": 2},
"Environmental Science": {"credits": 2, "abs_diff": 1},
"Programming with Python": {"credits": 2, "abs_diff": 2},
"Engineering Chemistry": {"credits": 3, "abs_diff": 2},
"Basics of Electronics Engineering": {"credits": 2, "abs_diff": 2},
"Basics of Electrical Engineering": {"credits": 2, "abs_diff": 3},
"Mathematics I": {"credits": 4, "abs_diff": 3},
# MECH
"Applied Probability and Statistics": {"credits": 3, "abs_diff": 2},
"Casting Welding and Forming": {"credits": 3, "abs_diff": 2},
"Problem Solving using C": {"credits": 2, "abs_diff": 2},
"Discrete Mathematics": {"credits": 3, "abs_diff": 3},
"Engineering Mechanics": {"credits": 3, "abs_diff": 2},
"Engineering Thermodynamics": {"credits": 4, "abs_diff": 4},
"Kinematics of Machines": {"credits": 3, "abs_diff": 2},
"Basics of Management": {"credits": 3, "abs_diff": 1},
"Fluid Mechanics": {"credits": 4, "abs_diff": 3},
"Materials Science and Engineering": {"credits": 3, "abs_diff": 2},
"Mechanical Measurements and Metrology":{"credits": 3, "abs_diff": 2},
"Solid Mechanics": {"credits": 4, "abs_diff": 3},
"Operations Planning and Control": {"credits": 3, "abs_diff": 2},
"Applied machine learning": {"credits": 3, "abs_diff": 3},
"Mechatronics in Manufacturing": {"credits": 3, "abs_diff": 3},
"Dynamics of Machines": {"credits": 4, "abs_diff": 4},
"Heat Transfer": {"credits": 4, "abs_diff": 4},
"I C Engines": {"credits": 3, "abs_diff": 2},
"Science of Machining": {"credits": 4, "abs_diff": 3},
"Introduction to Standardization": {"credits": 1, "abs_diff": 1},
"Industrial Engineering": {"credits": 2, "abs_diff": 2},
"Operations Research": {"credits": 3, "abs_diff": 4},
"Control System Engineering": {"credits": 4, "abs_diff": 4},
"CAD & CAM": {"credits": 3, "abs_diff": 2},
"Design of Machine Elements": {"credits": 4, "abs_diff": 3},
"Fluid and Turbo Machines": {"credits": 4, "abs_diff": 3},
"Refrigeration and Air Conditioning": {"credits": 3, "abs_diff": 3},
"Product Design and Development": {"credits": 3, "abs_diff": 2},
"Supply Chain Management": {"credits": 3, "abs_diff": 2},
"Advanced Machining & Additive Manufacturing":{"credits": 3, "abs_diff": 3},
"Design of Mechanical Systems": {"credits": 4, "abs_diff": 4},
"Automobile Engineering": {"credits": 3, "abs_diff": 2},
"Industry 4.0": {"credits": 3, "abs_diff": 2},
"Mechanics of Composites": {"credits": 3, "abs_diff": 4},
"Metal Forming": {"credits": 3, "abs_diff": 3},
"Project Management": {"credits": 3, "abs_diff": 1},
"Air Conditioning System Design": {"credits": 3, "abs_diff": 3},
"Artificial Intelligence for Robotic systems":{"credits": 3, "abs_diff": 4},
"Lean Six Sigma": {"credits": 3, "abs_diff": 2},
"Tool Engineering": {"credits": 3, "abs_diff": 3},
"Welding Engineering & Technology": {"credits": 3, "abs_diff": 2},
# META
"Introduction to Engineering Materials":{"credits": 3, "abs_diff": 1},
"Fuels, Furnaces and Refractories": {"credits": 4, "abs_diff": 2},
"Introduction to Physical Metallurgy": {"credits": 4, "abs_diff": 3},
"Mineral Processing": {"credits": 3, "abs_diff": 2},
"Electrometallurgy & Corrosion": {"credits": 4, "abs_diff": 3},
"Foundry Technology": {"credits": 4, "abs_diff": 2},
"Introduction to Extractive Metallurgy":{"credits": 4, "abs_diff": 3},
"Mechanical Behaviour and Testing of Metals":{"credits": 4, "abs_diff": 3},
"Metallurgical Thermodynamics and Kinetics":{"credits": 4, "abs_diff": 4},
"Computer Aided Design and Computer Aided Manufacturing (Program Linked EAS)":{"credits": 2, "abs_diff": 2},
"Basics of Transport Phenomena": {"credits": 4, "abs_diff": 4},
"Iron Making": {"credits": 4, "abs_diff": 3},
"Mechanical Working of Metals": {"credits": 4, "abs_diff": 3},
"NDT and Evaluation": {"credits": 3, "abs_diff": 2},
"Phase Transformations": {"credits": 4, "abs_diff": 4},
"Introduction to Nanomaterials and Technology":{"credits": 3, "abs_diff": 3},
"Materials Characterization": {"credits": 3, "abs_diff": 3},
"Powder Metallurgy": {"credits": 3, "abs_diff": 2},
"Principles of Heat Treatment": {"credits": 4, "abs_diff": 3},
"Production of Sponge Iron and Ferroalloys":{"credits": 3, "abs_diff": 2},
"Design and selection of materials": {"credits": 3, "abs_diff": 3},
"High Temperature Corrosion": {"credits": 3, "abs_diff": 3},
"Composite Materials": {"credits": 4, "abs_diff": 3},
"Joining of Materials": {"credits": 4, "abs_diff": 2},
"Non-Ferrous Extractive Metallurgy": {"credits": 4, "abs_diff": 3},
"Steel Making": {"credits": 4, "abs_diff": 3},
"Light Metals and Alloys": {"credits": 3, "abs_diff": 2},
"Welding Metallurgy": {"credits": 3, "abs_diff": 3},
"Fracture & Failure": {"credits": 3, "abs_diff": 4},
"Physical Metallurgy of Alloy Steels": {"credits": 3, "abs_diff": 4},
"Surface Engineering": {"credits": 3, "abs_diff": 2},
"Automotive and Aerospace Material": {"credits": 3, "abs_diff": 2},
"Metallurgy of Additive Manufacturing": {"credits": 3, "abs_diff": 3},
"Secondary Steel Making": {"credits": 3, "abs_diff": 3},
"Electronic and Magnetic Materials": {"credits": 3, "abs_diff": 4},
# EE
"Power Generation Sources": {"credits": 4, "abs_diff": 1},
"Network Theory": {"credits": 4, "abs_diff": 3},
"Measurements and Actuators": {"credits": 4, "abs_diff": 2},
"Advanced Programming for Design": {"credits": 3, "abs_diff": 2},
"Analysis & Design of Digital Logic Circuits":{"credits": 4, "abs_diff": 2},
"Electrical Machines-I": {"credits": 4, "abs_diff": 3},
"Integrated Electronics": {"credits": 4, "abs_diff": 3},
"Network, Systems and Signals": {"credits": 4, "abs_diff": 4},
"Advanced Engineering Mathematics": {"credits": 4, "abs_diff": 4},
"Control Systems Engineering": {"credits": 3, "abs_diff": 3},
"Electrical Machines-II": {"credits": 4, "abs_diff": 4},
"Microprocessor and Microcontroller": {"credits": 4, "abs_diff": 3},
"Power Electronics-I": {"credits": 4, "abs_diff": 3},
"Transmission and Distribution Systems":{"credits": 4, "abs_diff": 2},
"Principles of Communication Engineering":{"credits": 4, "abs_diff": 3},
"Modern Control Engineering": {"credits": 4, "abs_diff": 4},
"Power Electronics-II": {"credits": 4, "abs_diff": 4},
"Power System Switchgear and Protection":{"credits": 4, "abs_diff": 3},
"Advanced Power Transmission": {"credits": 4, "abs_diff": 3},
"Digital Signal Processing and Applications":{"credits": 4, "abs_diff": 4},
"Electric Drives and Control": {"credits": 4, "abs_diff": 4},
"Industrial Machine Learning": {"credits": 4, "abs_diff": 3},
"Operation and Control of Power Systems":{"credits": 4, "abs_diff": 4},
"Computer Aided Power System Analysis": {"credits": 4, "abs_diff": 3},
"Computer Architecture and Organization":{"credits": 4, "abs_diff": 3},
"Optimal Control Systems": {"credits": 4, "abs_diff": 4},
"Power System Restructuring, Deregulation and Economics":{"credits": 4, "abs_diff": 2},
# ECE
"Electronic Measurement & Instrumentation":{"credits": 3, "abs_diff": 2},
"Electronics Devices and Circuits": {"credits": 3, "abs_diff": 3},
"Signals and Systems": {"credits": 3, "abs_diff": 4},
"Analog Communication (M1)": {"credits": 3, "abs_diff": 3},
"Data Structures and Algorithms": {"credits": 3, "abs_diff": 3},
"Digital Logic Design (M2)": {"credits": 3, "abs_diff": 2},
"Electro-Magnetic Field Theory": {"credits": 3, "abs_diff": 4},
"Linear Integrated Circuits": {"credits": 3, "abs_diff": 3},
"Operating System Concepts": {"credits": 3, "abs_diff": 2},
"Technical Documentation": {"credits": 1, "abs_diff": 1},
"Analog CMOS IC": {"credits": 3, "abs_diff": 4},
"Computer Architecture": {"credits": 3, "abs_diff": 3},
"Digital Communication Systems": {"credits": 3, "abs_diff": 3},
"Digital Signal Processing": {"credits": 3, "abs_diff": 4},
"Microwave Engineering": {"credits": 3, "abs_diff": 3},
"VLSI Testing & Testability": {"credits": 3, "abs_diff": 3},
"Antenna & Wave Propagation": {"credits": 3, "abs_diff": 3},
"Digital CMOS IC": {"credits": 3, "abs_diff": 3},
"Embedded Systems": {"credits": 3, "abs_diff": 3},
"Microprocessors": {"credits": 3, "abs_diff": 3},
"Management Principles for Engineers": {"credits": 3, "abs_diff": 1},
"Computer & Network Security": {"credits": 3, "abs_diff": 2},
"Optical Communication Systems": {"credits": 3, "abs_diff": 3},
"Satellite & Radar Engineering": {"credits": 3, "abs_diff": 3},
"Wireless and 5G Communication": {"credits": 3, "abs_diff": 3},
"Neural Networks & Fuzzy Logic": {"credits": 3, "abs_diff": 3},
"Advanced Digital Communication Systems":{"credits": 3, "abs_diff": 4},
"Advanced Semiconductor Devices": {"credits": 3, "abs_diff": 4},
"Advanced Optical Communication Systems":{"credits": 3, "abs_diff": 4},
"VLSI signal processing architectures": {"credits": 3, "abs_diff": 4},
"CAD Algorithms for Synthesis of VLSI System":{"credits": 3, "abs_diff": 4},
"Artificial Intelligence and Expert Systems":{"credits": 3, "abs_diff": 3},
# CIVIL
"Surveying": {"credits": 3, "abs_diff": 2},
"Engineering Geology": {"credits": 3, "abs_diff": 2},
"Mechanics of Solids": {"credits": 4, "abs_diff": 3},
"Advanced Surveying": {"credits": 2, "abs_diff": 3},
"Building Technology": {"credits": 2, "abs_diff": 2},
"Introduction to Satellite Based Positioning":{"credits": 2, "abs_diff": 2},
"Construction Materials": {"credits": 3, "abs_diff": 1},
"Structural Analysis": {"credits": 4, "abs_diff": 4},
"Numerical Methods & Optimization": {"credits": 3, "abs_diff": 3},
"Building Planning & Services": {"credits": 2, "abs_diff": 2},
"Design of RCC Structures": {"credits": 3, "abs_diff": 3},
"Environmental Engineering - I": {"credits": 3, "abs_diff": 2},
"Geotechnical Engineering - I": {"credits": 4, "abs_diff": 3},
"Hydraulic Engineering": {"credits": 4, "abs_diff": 3},
"Transportation Engineering - I": {"credits": 3, "abs_diff": 2},
"Design of RCC Systems": {"credits": 4, "abs_diff": 4},
"Design of Steel Structures": {"credits": 4, "abs_diff": 4},
"Environmental Engineering-II": {"credits": 3, "abs_diff": 3},
"Geotechnical Engineering-II": {"credits": 4, "abs_diff": 4},
"Hydrology": {"credits": 4, "abs_diff": 2},
"Transportation Engineering - II": {"credits": 3, "abs_diff": 3},
"Soft Skills and Personality Development":{"credits": 2, "abs_diff": 1},
"Construction Project Management": {"credits": 3, "abs_diff": 2},
"Estimation and Costing": {"credits": 4, "abs_diff": 2},
"Water Resources Engineering": {"credits": 3, "abs_diff": 3},
"Numerical Methods": {"credits": 3, "abs_diff": 3},
"Design of Hydraulic Structures": {"credits": 3, "abs_diff": 4},
"Dynamics of Structures": {"credits": 3, "abs_diff": 4},
"Earth Dams": {"credits": 3, "abs_diff": 3},
"Finite Element Method": {"credits": 3, "abs_diff": 4},
"Landfill Engineering": {"credits": 3, "abs_diff": 2},
"Prestressed Concrete": {"credits": 3, "abs_diff": 4},
"Soil Dynamics": {"credits": 3, "abs_diff": 4},
"Solid Waste Management": {"credits": 3, "abs_diff": 2},
# CSE
"Technical Writing": {"credits": 1, "abs_diff": 1},
"Data Communications": {"credits": 3, "abs_diff": 2},
"Design and Analysis of Algorithms": {"credits": 3, "abs_diff": 4},
"Digital Circuits and Microprocessors": {"credits": 3, "abs_diff": 3},
"MATHEMATICS FOR AI": {"credits": 3, "abs_diff": 4},
"Object Oriented Analysis and Design": {"credits": 3, "abs_diff": 2},
"SOCIAL SCIENCES AND PROFESIONAL ETHICS":{"credits": 4, "abs_diff": 1},
"BASICS OF MANAGEMENT": {"credits": 3, "abs_diff": 1},
"Computer Networks": {"credits": 3, "abs_diff": 3},
"Computer Organization and Architecture":{"credits": 4, "abs_diff": 3},
"Database Information Systems": {"credits": 3, "abs_diff": 2},
"Machine Learning": {"credits": 3, "abs_diff": 3},
"Theory of Computation": {"credits": 4, "abs_diff": 4},
"Compiler Design": {"credits": 3, "abs_diff": 4},
"Cryptography": {"credits": 3, "abs_diff": 4},
"Emerging Technologies for CS": {"credits": 3, "abs_diff": 2},
"Operating System": {"credits": 3, "abs_diff": 3},
"Software Engineering (Minor)": {"credits": 3, "abs_diff": 2},
"Blockchain Technologies": {"credits": 3, "abs_diff": 3},
"Deep Learning": {"credits": 3, "abs_diff": 4},
"Operating System (Minor)": {"credits": 3, "abs_diff": 3},
"Data Structures (Minor)": {"credits": 3, "abs_diff": 3},
"Artificial Intelligence (AI)": {"credits": 3, "abs_diff": 3},
"Computer and Network Security (CNS)": {"credits": 3, "abs_diff": 3},
"Digital Image Processing (DIP)": {"credits": 3, "abs_diff": 3},
"Parallel and Distributed Computing (PDC)":{"credits": 3, "abs_diff": 4},
"Malware Analysis": {"credits": 3, "abs_diff": 4},
"Wireless Networks (WN)": {"credits": 3, "abs_diff": 2},
"Data Structures": {"credits": 4, "abs_diff": 3},
"Computer Vision": {"credits": 3, "abs_diff": 4},
"Decentralized Learning": {"credits": 3, "abs_diff": 4},
"Full Stack Development": {"credits": 3, "abs_diff": 2},
"Information Retrieval": {"credits": 3, "abs_diff": 3},
"Natural Language Processing": {"credits": 3, "abs_diff": 4},
"Topics in Operating System": {"credits": 3, "abs_diff": 4},
# CHEM
"Introduction to Chemical Engineering": {"credits": 3, "abs_diff": 1},
"Chemical Engineering Thermodynamics-I":{"credits": 4, "abs_diff": 3},
"Chemical Process Calculations": {"credits": 4, "abs_diff": 3},
"Process Instrumentation": {"credits": 3, "abs_diff": 2},
"Computer Aided Numerical Methods": {"credits": 4, "abs_diff": 2},
"Chemical Engineering Thermodynamics-II":{"credits": 4, "abs_diff": 4},
"Conventional & Alternate Energy Resources":{"credits": 3, "abs_diff": 2},
"Mechanical Operations": {"credits": 4, "abs_diff": 2},
"Fundamentals of Materials Science and Engineering":{"credits": 3, "abs_diff": 2},
"Heat Transfer Operations": {"credits": 4, "abs_diff": 3},
"Industrial Pollution Abatement": {"credits": 4, "abs_diff": 2},
"Mass Transfer-I": {"credits": 4, "abs_diff": 3},
"AI and ML in Chemical Engineering": {"credits": 4, "abs_diff": 3},
"Chemical Reaction Engineering-II": {"credits": 4, "abs_diff": 4},
"Mass Transfer-II": {"credits": 4, "abs_diff": 4},
"Process Dynamics and Control": {"credits": 4, "abs_diff": 4},
"Process Safety and Hazards": {"credits": 4, "abs_diff": 2},
"DL": {"credits": 3, "abs_diff": 4},
"Big Data": {"credits": 3, "abs_diff": 3},
"IoT": {"credits": 3, "abs_diff": 2},
"Advanced Process Control": {"credits": 4, "abs_diff": 4},
"CFD in Chemical Engineering": {"credits": 4, "abs_diff": 4},
"Mechanical Design of Process Equipment":{"credits": 4, "abs_diff": 3},
"Nano-materials & Characterization": {"credits": 3, "abs_diff": 3},
"Optimization of Chemical Processes": {"credits": 3, "abs_diff": 4},
"Polymer Science and Technology": {"credits": 3, "abs_diff": 2},
"Process Integration": {"credits": 3, "abs_diff": 3},
"Solid & Hazard Waste Management": {"credits": 3, "abs_diff": 2},
"Petroleum, Petrochemicals & Natural Gas Engineering":{"credits": 3, "abs_diff": 2},
"Non-Conventional Energy Sources": {"credits": 3, "abs_diff": 2},
# AIDE
"PROBLEM SOLVING WITH C": {"credits": 2, "abs_diff": 2},
"Discrete Structure": {"credits": 3, "abs_diff": 3},
"Social Sciences and Professional Ethics":{"credits": 4, "abs_diff": 1},
"Algorithm Design": {"credits": 3, "abs_diff": 4},
"Automata Theory": {"credits": 4, "abs_diff": 4},
"Digital Systems and Computer Architecture":{"credits": 4, "abs_diff": 3},
"Foundations of Data Science": {"credits": 3, "abs_diff": 2},
"Artificial Neural Network": {"credits": 3, "abs_diff": 3},
"Data Communication and Networks": {"credits": 3, "abs_diff": 2},
"Database Management System": {"credits": 3, "abs_diff": 2},
"Introduction to Artificial Intelligence":{"credits": 3, "abs_diff": 2},
"Introduction to Compiler Design": {"credits": 3, "abs_diff": 4},
"Big Data Analytics": {"credits": 3, "abs_diff": 3},
"Data Mining and Warehousing": {"credits": 3, "abs_diff": 2},
"Image Processing": {"credits": 3, "abs_diff": 3},
"Principles of Machine Learning": {"credits": 3, "abs_diff": 3},
"High Performance Computing": {"credits": 3, "abs_diff": 4},
"Information Security": {"credits": 3, "abs_diff": 3},
# Sem 8
"Internship": {"credits": 20, "abs_diff": 2},
"Project": {"credits": 6, "abs_diff": 2},
"Elective": {"credits": 3, "abs_diff": 2},
}
GRADE_TO_MARK = {"AA": 10, "AB": 9, "BB": 8, "BC": 7, "CC": 6, "CD": 5, "DD": 4, "FP": 0}
SEM8_NAMES = {"Internship", "Project", "Elective"}
DEFAULT_INFO = {"credits": 3, "abs_diff": 2}
def get_info(name):
return SUBJECTS_DATA.get(name, DEFAULT_INFO)
def grade_mark_to_letter(gm):
"""Convert continuous grade mark (6-10) to letter grade."""
gm = float(gm)
if gm == 10 : return "AA"
if gm >= 9 : return "AB"
if gm >= 8 : return "BB"
if gm >= 7 : return "BC"
if gm >= 6 : return "CC"
if gm >= 5 : return "CD"
if gm >= 4 : return "DD"
return "FP"
def sgpa(subjects):
tw = sum(s["grade_mark"] * s["credits"] for s in subjects)
tc = sum(s["credits"] for s in subjects)
return round(tw / tc, 4) if tc else 0.0
def cgpa(all_sgpas):
return round(sum(all_sgpas) / len(all_sgpas), 4) if all_sgpas else 0.0
def trend_slope(sgpas):
n = len(sgpas)
if n < 2: return 0.0
x = list(range(1, n + 1))
xm = sum(x) / n
ym = sum(sgpas) / n
num = sum((xi - xm) * (yi - ym) for xi, yi in zip(x, sgpas))
den = sum((xi - xm) ** 2 for xi in x)
return round(num / den, 4) if den else 0.0
def ml_predict(fv):
"""
4-model ensemble (RF + GB + ET + Ridge).
Returns grade_encoded (float 6-10), then caller rounds to letter.
"""
arr = np.array(fv, dtype=float).reshape(1, -1)
arr_imp = imputer.transform(arr)
arr_sc = scaler.transform(arr_imp)
rf_pred = rf_model.predict(arr_imp)[0]
gb_pred = gb_model.predict(arr_imp)[0]
et_pred = et_model.predict(arr_imp)[0]
ridge_pred = ridge_model.predict(arr_sc)[0]
pred = (W['rf'] * rf_pred + W['gb'] * gb_pred +
W['et'] * et_pred + W['ridge'] * ridge_pred) / W_TOTAL
intr_enc = fv[8]
alignment = fv[11]
if intr_enc <= 2:
pred -= 0.5
if alignment < 0:
pred -= 0.4
if intr_enc <= 2 and alignment < 0:
pred -= 0.3
return float(np.clip(pred, 6.0, 10.0))
@app.route('/')
def index():
return render_template('index.html')
@app.route('/api/predict', methods=['POST'])
def predict():
try:
d = request.get_json(force=True)
previous_sgpas = [float(s) for s in d['previous_sgpas']]
beh = d['behavioral']
subjects_in = d['subjects']
# ── Global behavioural features ───────────────────────────
jee = float(beh.get('jee_percentile', 50.0))
scr = float(beh.get('screen_time', 4.0))
std = float(beh.get('study_hours', 2.0))
exam = float(beh.get('exam_study_hours', 3.0))
seat = int(beh.get('seating', 3)) # 1/3/5
parti = int(beh.get('participation', 2)) # 1/2/4/5
peer = int(beh.get('peer_behaviour', 2)) # 1/2/4/5
ca = int(beh.get('career_alignment', 4)) # 1/2/4/5
ec = int(beh.get('extracurriculars', 2)) # 1/2/4/5
# ── Trend + projected SGPA ────────────────────────────────
hist = previous_sgpas[:-1] if len(previous_sgpas) > 1 else previous_sgpas
slope = trend_slope(hist)
p_sgpa = float(np.clip(previous_sgpas[-1] + slope, 0, 10)) \
if previous_sgpas else STATS['predicted_sgpa_mean']
results = []
for s in subjects_in:
name = s['name']
is_sem8 = bool(s.get('is_sem8', name in SEM8_NAMES))
info = get_info(name)
cred = info['credits']
abs_d = info['abs_diff']
# ── Sem 8: manual grade entry ─────────────────────────
if is_sem8:
mg = s.get('grade_manual', 'BB')
results.append({
"name": name,
"grade": mg,
"grade_mark": float(GRADE_TO_MARK.get(mg, 8)),
"credits": cred,
"source": "manual"
})
continue
# ── Regular subject ───────────────────────────────────
filled = bool(s.get('filled', False))
att = int(s.get('attendance', 3)) if filled else 3 # 1-4
intr = int(s.get('interest', 4)) if filled else 4 # 1/2/4/5
tch = int(s.get('teacher', 3)) if filled else 3 # 1/3/4/6
diff = int(s.get('difficulty', 2)) if filled else 2 # 1/2/4/5
# ── Derived features (match training data columns) ────
# relative diff = predicted_sgpa − abs_diff (approximated)
rel_diff = p_sgpa - abs_d
# relative allignment = career_alignment − difficulty (approx)
rel_align = ca - diff
# relative ec = ec_encoded − abs_diff
rel_ec = ec - abs_d
# interest and alignment w career encoded
interest_x_alignment = intr * rel_align
# Feature vector — ORDER must match FEATURE_COLS exactly:
# JEE, screen_time, study_hrs, exam_hrs,
# seat, parti, peer, att, intr, tch,
# rel_diff, rel_align, rel_ec, predicted_sgpa
fv = [jee, scr, std, exam,
seat, parti, peer,
att, intr, tch,
rel_diff, rel_align, rel_ec,
p_sgpa, interest_x_alignment]
gm = ml_predict(fv)
results.append({
"name": name,
"grade": grade_mark_to_letter(gm),
"grade_mark": round(gm, 2),
"credits": cred,
"source": "model" if filled else "default"
})
cur_sgpa = sgpa([{"grade_mark": r["grade_mark"], "credits": r["credits"]}
for r in results])
all_sgpas = previous_sgpas + [cur_sgpa]
cur_cgpa = cgpa(all_sgpas)
return jsonify({
"success": True,
"subjects": results,
"current_sgpa": round(cur_sgpa, 4),
"cgpa": round(cur_cgpa, 4)
})
except Exception as e:
return jsonify({
"success": False,
"error": str(e),
"trace": traceback.format_exc()
}), 500
if __name__ == '__main__':
import os
if __name__ == "__main__":
port = int(os.environ.get("PORT", 5000))
app.run(host="0.0.0.0", port=port)