File size: 4,525 Bytes
045de33
21e349b
 
 
 
e19a98b
21e349b
 
 
5b8842a
eda78df
7a7e551
 
451e4ba
 
 
 
 
21e349b
451e4ba
 
 
 
 
 
 
 
 
e19a98b
81fa7c6
451e4ba
 
 
 
 
 
 
 
 
55dff91
 
 
e19a98b
451e4ba
21e349b
e19a98b
 
815574c
21e349b
e19a98b
21e349b
e19a98b
 
 
6ed3494
55dff91
 
 
e19a98b
6ed3494
451e4ba
 
 
6ed3494
451e4ba
4cc8ead
451e4ba
e19a98b
 
451e4ba
 
 
 
21e349b
451e4ba
 
21e349b
 
 
 
451e4ba
3f85a10
732f7aa
451e4ba
 
 
21e349b
 
451e4ba
 
3f85a10
 
451e4ba
 
3f85a10
21e349b
 
451e4ba
 
21e349b
 
 
 
451e4ba
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
import gradio as gr
import joblib
import numpy as np
import pandas as pd
from huggingface_hub import hf_hub_download
from sklearn.preprocessing import StandardScaler, OneHotEncoder, LabelEncoder

# Load the trained model and scaler objects from file


REPO_ID = "Hemg/modelxxx" # hugging face  repo ID
MoDEL_FILENAME = "studentpredict.joblib" # model file name
SCALER_FILENAME ="studentscaler.joblib" # scaler file name

model = joblib.load(hf_hub_download(repo_id=REPO_ID, filename=MoDEL_FILENAME))

scaler = joblib.load(hf_hub_download(repo_id=REPO_ID, filename=SCALER_FILENAME))
 
def encode_categorical_columns(df):
    label_encoder = LabelEncoder()
    ordinal_columns = df.select_dtypes(include=['object']).columns

    for col in ordinal_columns:
        df[col] = label_encoder.fit_transform(df[col])

    nominal_columns = df.select_dtypes(include=['object']).columns.difference(ordinal_columns)
    df = pd.get_dummies(df, columns=nominal_columns, drop_first=True)

    return df

# Define the prediction function
def predict_performance(Location, College_Fee,College, GPA, Year, Course_Interested, Faculty, Source, 
                       Visited_College_for_Inquiry_Only, Event, Attended_Any_Events, 
                       Presenter, Visited_Parents):
    
    input_data = [[Location, College_Fee,College, GPA, Year, Course_Interested, Faculty, Source,
                 Visited_College_for_Inquiry_Only, Event, Attended_Any_Events,
                 Presenter, Visited_Parents]]

    feature_names = ["Location", "College Fee", "GPA", "Year", "Course Interested",
                 "Faculty", "Source", "Visited College for Inquiry Only", "Event",
                 "Attended Any Events", "College", "Presenter", "Visited Parents"]
    
    input_df = pd.DataFrame(input_data, columns=feature_names)
    
    # Debug print 2: Show DataFrame before encoding
    print("\nDataFrame before encoding:")
    print(input_df)
    
    df = encode_categorical_columns(input_df)
    
    # Debug print 3: Show DataFrame after encoding
    print("\nDataFrame after encoding:")
    print(df)
    
    # Ensure the DataFrame columns match the scaler's expected input
    df = df.reindex(columns=scaler.feature_names_in_, fill_value=0)
    
    scaled_input = scaler.transform(df)
    
    # Debug print 4: Show scaled input
    print("\nScaled input:")
    print(scaled_input)
    
    prediction = model.predict(scaled_input)[0]
    
    # Debug print 5: Show prediction details
    print("\nPrediction details:")
    print(f"Raw prediction: {prediction}")
    prediction_probability = 1 / (1 + np.exp(-prediction))
    print(f"Probability: {prediction_probability}")
    prediction_percentage = prediction_probability * 100
    print(f"Percentage: {prediction_percentage}")
    
    return f"Chance of Admission: {prediction_percentage:.1f}%"
 
iface = gr.Interface(
    fn=predict_performance,
    inputs=[
        gr.Radio(["Kathmandu", "Bhaktapur", "Lalitpur", "Kritipur"], label="Location"),
        gr.Slider(minimum=1000000, maximum=1700000, label="College Fee"),
        gr.Slider(minimum=2, maximum=3, label="GPA"),
        gr.Slider(minimum=2024, maximum=2024, step=1, label="Year"),
        gr.Radio(["MSc IT & Applied Security", "BSc (Hons) Computing", "BSc (Hons) Computing with Artificial Intelligence", 
                 "BSc (Hons) Computer Networking & IT Security", "BSc (Hons) Multimedia Technologies", "MBA", 
                 "BA (Hons) Accounting &  Finance", "BA (Hons) Business Administration"], label="Course_Interested"),
        gr.Radio(["Science", "Management", "Humanities"], label="Faculty"),
        gr.Radio(["Event", "Facebook", "Instagram", "Offline", "Recommendation"], label="Source"),
        gr.Radio(["Yes", "No"], label="visited_college_for_inquery_only"),
        gr.Radio(["New Year", "Dashain", "Orientation", "Fresher's Party", "Holi Festival", "Welcome Ceremony"], 
                label="attended_event_name"),
        gr.Radio(["Yes", "No"], label="attended_any_event"),
        gr.Radio(["Trinity", "CCRC", "KMC", "SOS", "ISMT", "St. Xavier's", "Everest", "Prime"], label="College"),
        gr.Radio(["Ram", "Gita", "Manish", "Shyam", "Raj", "Hari", "Rina", "Shree"], label="Presenter"),
        gr.Radio(["Yes", "No"], label="visited_with_parents")  # Removed the incorrect list here
    ],
    outputs="text",
    title="chances of student admission",
    description="chances of student admission"
)

# Run the app
if __name__ == "__main__":
    iface.launch(share=True)