File size: 5,205 Bytes
02aeee5
 
 
 
 
 
 
 
 
 
0ad62b5
02aeee5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0ad62b5
02aeee5
 
 
 
 
 
 
 
 
0ad62b5
4d080d2
02aeee5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import pandas as pd
import joblib
import gradio as gr

# Load the trained model pipeline
model = joblib.load('best_model_pipeline_5_24.pkl')

columns = [
    'gender', 'it_program', 'current_res', 'fam_size', 'guardian', 'health_stat', 'travel_time',
    'study_time', 'mot_edu', 'fat_edu', 'fam_rel_qual', 'parents_cohab_stat', 'add_type', 'current_stat',
    'extra_curricular', 'hang_out_friends', 'current_cgpa', 'prev_edu', 'current_sem', 'calc',
    'pf', 'oop', 'dsa', 'matric_or_o', 'fsc_or_a', 'sem_1_sgpa', 'sem_2_sgpa', 'sem_3_sgpa', 'sem_4_sgpa'
]


def preprocess_input(input_data):
    # Perform the same preprocessing steps as in the training phase
    grade_mapping = {
        'A+': 4.0, 'A': 3.85, 'A-': 3.7, 'B+': 3.3, 'B': 3.0, 'B-': 2.7,
        'C+': 2.3, 'C': 2.0, 'C-': 1.7, 'D+': 1.3, 'D': 1.0, 'D-': 0.7, 'F': 0.0
    }
    grade_columns = ['calc', 'pf', 'oop', 'dsa']

    for col in grade_columns:
        input_data[col] = grade_mapping[input_data[col]]

    # Replace "3+" with 3 in the Failures column
    #input_data['fail'] = 3 if input_data['fail'] == '3+' else int(input_data['fail'])

    # Convert input data to DataFrame and ensure the correct order of columns
    input_df = pd.DataFrame([input_data], columns=columns)

    return input_df

def predict(
    gender, it_program, current_res, fam_size, guardian, health_stat, travel_time,
    study_time, mot_edu, fat_edu, fam_rel_qual, parents_cohab_stat, add_type, current_stat,
    extra_curricular, hang_out_friends, current_cgpa, prev_edu, current_sem, calc,
    pf, oop, dsa, matric_or_o, fsc_or_a, sem_1_sgpa, sem_2_sgpa, sem_3_sgpa, sem_4_sgpa
):
    input_data = {
        'gender': gender,
        'it_program': it_program,
        'current_res': current_res,
        'fam_size': fam_size,
        'guardian': guardian,
        'health_stat': health_stat,
        'travel_time': travel_time,
        'study_time': study_time,
        'mot_edu': mot_edu,
        'fat_edu': fat_edu,
        'fam_rel_qual': fam_rel_qual,
        'parents_cohab_stat': parents_cohab_stat,
        'add_type': add_type,
        'current_stat': current_stat,
        'extra_curricular': extra_curricular,
        'hang_out_friends': hang_out_friends,
        'current_cgpa': current_cgpa,
        'prev_edu': prev_edu,
        'current_sem': current_sem,
        'calc': calc,
        'pf': pf,
        'oop': oop,
        'dsa': dsa,
        'matric_or_o': matric_or_o,
        'fsc_or_a': fsc_or_a,
        'sem_1_sgpa': sem_1_sgpa,
        'sem_2_sgpa': sem_2_sgpa,
        'sem_3_sgpa': sem_3_sgpa,
        'sem_4_sgpa': sem_4_sgpa
    }

    # Preprocess the input data
    input_df = preprocess_input(input_data)

    # Make prediction
    prediction = model.predict(input_df)

    return prediction[0]

# Create a Gradio interface with multiple inputs
iface = gr.Interface(
    fn=predict,
    inputs=[
        gr.Dropdown(choices=["Male", "Female"], label="Gender"),
        gr.Dropdown(choices=["CS", "DS", "SE"], label="IT Program"),
        gr.Dropdown(choices=["Hostel", "Home"], label="Current residence"),
        gr.Dropdown(choices=["LT3", "GT3"], label="Family size"),
        gr.Dropdown(choices=["Father", "Mother", "Grandparents"], label="Guardian"),
        gr.Slider(1, 5, step=1, label="Health Status"),
        gr.Slider(1, 4, step=1, label="Travel time to university"),
        gr.Slider(1, 4, step=1, label="Study time"),
        gr.Slider(0, 4, step=1, label="Mothers education"),
        gr.Slider(0, 4, step=1, label="Fathers education"),
        gr.Slider(1, 5, step=1, label="Family relations quality"),
        gr.Dropdown(choices=["Together", "Abroad"], label="Parents cohabitation status"),
        gr.Dropdown(choices=["Urban", "Rural"], label="Home address Type"),
        gr.Dropdown(choices=["Internship", "Full time student", "Job"], label="Status"),
        gr.Dropdown(choices=["Yes", "No"], label="Participation in extra-curricular activities"),
        gr.Slider(1, 5, step=1, label="Going out with friends"),
        gr.Number(label="Current CGPA"),
        gr.Dropdown(choices=["Matriculation and FSc/ICS", "O and A levels"], label="Previous education"),
        gr.Dropdown(choices=[1, 2, 3, 4, 5],label="Current Semester"),
        gr.Dropdown(choices=["A+", "A", "A-", "B+", "B", "B-", "C+", "C", "C-", "D", "F"], label="Grade in Calculus"),
        gr.Dropdown(choices=["A+", "A", "A-", "B+", "B", "B-", "C+", "C", "C-", "D", "F"], label="Grade in Programming Fundamentals (PF)"),
        gr.Dropdown(choices=["A+", "A", "A-", "B+", "B", "B-", "C+", "C", "C-", "D", "F"], label="Grade in Object Oriented Programming (OOP)"),
        gr.Dropdown(choices=["A+", "A", "A-", "B+", "B", "B-", "C+", "C", "C-", "D", "F"], label="Grade in Data structures and algorithms (DSA)"),
        gr.Number(label="Percentage in Matric or O levels"),
        gr.Number(label="Percentage in FSc or A levels"),
        gr.Number(label="Semester 1 GPA (SGPA)"),
        gr.Number(label="Semester 2 GPA (SGPA)"),
        gr.Number(label="Semester 3 GPA (SGPA)"),
        gr.Number(label="Semester 4 GPA (SGPA)")
    ],
    outputs="text",
    live=False
)

# Launch the Gradio interface
iface.launch()