|
|
import gradio as gr |
|
|
import pandas as pd |
|
|
import joblib |
|
|
|
|
|
|
|
|
model = joblib.load("student_gpa_model.pkl") |
|
|
columns = joblib.load("columns.pkl") |
|
|
|
|
|
def predict_gpa( |
|
|
Age, |
|
|
Gender, |
|
|
Ethnicity, |
|
|
ParentalEducation, |
|
|
StudyTimeWeekly, |
|
|
Absences, |
|
|
Tutoring, |
|
|
ParentalSupport, |
|
|
Extracurricular, |
|
|
Sports, |
|
|
Music, |
|
|
Volunteering |
|
|
): |
|
|
data = { |
|
|
"Age": Age, |
|
|
"Gender": Gender, |
|
|
"Ethnicity": Ethnicity, |
|
|
"ParentalEducation": ParentalEducation, |
|
|
"StudyTimeWeekly": StudyTimeWeekly, |
|
|
"Absences": Absences, |
|
|
"Tutoring": Tutoring, |
|
|
"ParentalSupport": ParentalSupport, |
|
|
"Extracurricular": Extracurricular, |
|
|
"Sports": Sports, |
|
|
"Music": Music, |
|
|
"Volunteering": Volunteering, |
|
|
} |
|
|
|
|
|
df = pd.DataFrame([data]) |
|
|
df = pd.get_dummies(df) |
|
|
df = df.reindex(columns=columns, fill_value=0) |
|
|
|
|
|
prediction = model.predict(df)[0] |
|
|
return round(float(prediction), 2) |
|
|
|
|
|
app = gr.Interface( |
|
|
fn=predict_gpa, |
|
|
inputs=[ |
|
|
gr.Number(label="Age"), |
|
|
gr.Dropdown(["Male", "Female"], label="Gender"), |
|
|
gr.Dropdown( |
|
|
["Group A", "Group B", "Group C", "Group D", "Group E"], |
|
|
label="Ethnicity" |
|
|
), |
|
|
gr.Dropdown( |
|
|
["High School", "Associate", "Bachelor", "Master"], |
|
|
label="Parental Education" |
|
|
), |
|
|
gr.Number(label="Weekly Study Time (hours)"), |
|
|
gr.Number(label="Absences"), |
|
|
gr.Dropdown(["Yes", "No"], label="Tutoring"), |
|
|
gr.Dropdown(["Low", "Medium", "High"], label="Parental Support"), |
|
|
gr.Dropdown(["Yes", "No"], label="Extracurricular"), |
|
|
gr.Dropdown(["Yes", "No"], label="Sports"), |
|
|
gr.Dropdown(["Yes", "No"], label="Music"), |
|
|
gr.Dropdown(["Yes", "No"], label="Volunteering"), |
|
|
], |
|
|
outputs=gr.Number(label="Predicted GPA"), |
|
|
title="Student GPA Predictor", |
|
|
description="ML model to predict student GPA based on academic & lifestyle factors" |
|
|
) |
|
|
|
|
|
if __name__ == "__main__": |
|
|
app.launch(server_name="0.0.0.0", server_port=7860) |
|
|
|