File size: 2,096 Bytes
6bf4de3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import gradio as gr
import pandas as pd
import joblib

# Load model & columns
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)