|
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 |
|
|
|
|
|
|
|
|
|
REPO_ID = "Hemg/modelxxx" |
|
MoDEL_FILENAME = "studentpredict.joblib" |
|
SCALER_FILENAME ="studentscaler.joblib" |
|
|
|
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 |
|
|
|
|
|
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) |
|
|
|
|
|
print("\nDataFrame before encoding:") |
|
print(input_df) |
|
|
|
df = encode_categorical_columns(input_df) |
|
|
|
|
|
print("\nDataFrame after encoding:") |
|
print(df) |
|
|
|
|
|
df = df.reindex(columns=scaler.feature_names_in_, fill_value=0) |
|
|
|
scaled_input = scaler.transform(df) |
|
|
|
|
|
print("\nScaled input:") |
|
print(scaled_input) |
|
|
|
prediction = model.predict(scaled_input)[0] |
|
|
|
|
|
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") |
|
], |
|
outputs="text", |
|
title="chances of student admission", |
|
description="chances of student admission" |
|
) |
|
|
|
|
|
if __name__ == "__main__": |
|
iface.launch(share=True) |
|
|