File size: 4,531 Bytes
090afd0
 
 
 
 
 
 
 
 
 
c35148b
090afd0
 
 
 
 
 
 
 
 
 
1b015aa
090afd0
 
 
 
 
c35148b
090afd0
 
 
 
 
 
 
 
 
f5b7d8a
090afd0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import pandas as pd
import joblib
import gradio as gr

# Load the trained model pipeline
model = joblib.load('best_model_pipeline_3_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', 'matric_or_o', 'fsc_or_a', 'sem_1_sgpa', 'sem_2_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']

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

    # Replace "3+" with 3 in the Failures column
    

    # 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, matric_or_o, fsc_or_a, sem_1_sgpa, sem_2_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,
        'matric_or_o': matric_or_o,
        'fsc_or_a': fsc_or_a,
        'sem_1_sgpa': sem_1_sgpa,
        'sem_2_sgpa': sem_2_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],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.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)")
    ],
    outputs="text",
    live=False
)

# Launch the Gradio interface
iface.launch()