|
|
import joblib
|
|
|
import pandas as pd
|
|
|
import numpy as np
|
|
|
import gradio as gr
|
|
|
|
|
|
|
|
|
model = joblib.load('trained_model.joblib')
|
|
|
|
|
|
|
|
|
def grade_to_numeric(grade):
|
|
|
if pd.isna(grade) or grade == "":
|
|
|
return np.nan
|
|
|
grade_map = {
|
|
|
"A1": 1, "B2": 2, "B3": 3, "C4": 4, "C5": 5, "C6": 6,
|
|
|
"D7": 7, "E8": 8, "F9": 9
|
|
|
}
|
|
|
return grade_map.get(grade, np.nan)
|
|
|
|
|
|
|
|
|
def preprocess_input(desired_career, aggregate, english, core_maths, science,
|
|
|
social_studies, electives, elective_maths=None,
|
|
|
business_management=None, government=None, chemistry=None,
|
|
|
physics=None, economics=None, visual_arts=None, geography=None,
|
|
|
e_ict=None, literature=None, biology=None):
|
|
|
|
|
|
|
|
|
input_data = {
|
|
|
"Desired_Career": desired_career,
|
|
|
"Aggregate": aggregate,
|
|
|
"English": english,
|
|
|
"Core Maths": core_maths,
|
|
|
"Science": science,
|
|
|
"Social Studies": social_studies,
|
|
|
"Electives": electives,
|
|
|
"Elective Maths": elective_maths,
|
|
|
"Business Management": business_management,
|
|
|
"Government": government,
|
|
|
"Chemistry": chemistry,
|
|
|
"Physics": physics,
|
|
|
"Economics": economics,
|
|
|
"Visual Arts": visual_arts,
|
|
|
"Geography": geography,
|
|
|
"E-ICT": e_ict,
|
|
|
"Literature": literature,
|
|
|
"Biology": biology
|
|
|
}
|
|
|
|
|
|
|
|
|
student_df = pd.DataFrame([input_data])
|
|
|
|
|
|
|
|
|
grade_cols = ['English', 'Core Maths', 'Science', 'Social Studies',
|
|
|
'Elective Maths', 'Business Management', 'Government',
|
|
|
'Chemistry', 'Physics', 'Economics', 'Visual Arts',
|
|
|
'Geography', 'E-ICT', 'Literature', 'Biology']
|
|
|
|
|
|
for col in grade_cols:
|
|
|
if col in student_df.columns:
|
|
|
student_df[col] = student_df[col].apply(grade_to_numeric)
|
|
|
|
|
|
return student_df
|
|
|
|
|
|
def predict_career(desired_career, aggregate, english, core_maths, science,
|
|
|
social_studies, electives, elective_maths=None,
|
|
|
business_management=None, government=None, chemistry=None,
|
|
|
physics=None, economics=None, visual_arts=None, geography=None,
|
|
|
e_ict=None, literature=None, biology=None):
|
|
|
|
|
|
|
|
|
processed_input = preprocess_input(
|
|
|
desired_career, aggregate, english, core_maths, science,
|
|
|
social_studies, electives, elective_maths, business_management,
|
|
|
government, chemistry, physics, economics, visual_arts, geography,
|
|
|
e_ict, literature, biology
|
|
|
)
|
|
|
|
|
|
|
|
|
prediction = model.predict(processed_input)
|
|
|
probabilities = model.predict_proba(processed_input)[0]
|
|
|
|
|
|
|
|
|
class_indices = np.argsort(probabilities)[::-1][:3]
|
|
|
classes = model.classes_
|
|
|
recommendations = [
|
|
|
(classes[idx], float(probabilities[idx]))
|
|
|
for idx in class_indices
|
|
|
]
|
|
|
|
|
|
|
|
|
output = "\n".join(
|
|
|
[f"{course}: {prob*100:.1f}%" for course, prob in recommendations]
|
|
|
)
|
|
|
|
|
|
return output
|
|
|
|
|
|
|
|
|
inputs = [
|
|
|
gr.Dropdown(["Medicine", "Pharmacy", "Law", "Computer Science", "Engineering",
|
|
|
"Business", "Nursing", "Agriculture", "Journalism", "Education"],
|
|
|
label="Desired Career"),
|
|
|
gr.Number(label="Aggregate Score"),
|
|
|
gr.Dropdown(["A1", "B2", "B3", "C4", "C5", "C6", "D7", "E8", "F9"], label="English"),
|
|
|
gr.Dropdown(["A1", "B2", "B3", "C4", "C5", "C6", "D7", "E8", "F9"], label="Core Maths"),
|
|
|
gr.Dropdown(["A1", "B2", "B3", "C4", "C5", "C6", "D7", "E8", "F9"], label="Science"),
|
|
|
gr.Dropdown(["A1", "B2", "B3", "C4", "C5", "C6", "D7", "E8", "F9"], label="Social Studies"),
|
|
|
gr.Textbox(label="Electives (comma separated)"),
|
|
|
gr.Dropdown(["A1", "B2", "B3", "C4", "C5", "C6", "D7", "E8", "F9", None], label="Elective Maths (optional)"),
|
|
|
|
|
|
]
|
|
|
|
|
|
outputs = gr.Textbox(label="Recommended Courses")
|
|
|
|
|
|
interface = gr.Interface(
|
|
|
fn=predict_career,
|
|
|
inputs=inputs,
|
|
|
outputs=outputs,
|
|
|
title="Career Path Recommender",
|
|
|
description="Enter your academic information to get career recommendations"
|
|
|
)
|
|
|
|
|
|
interface.launch() |