Spaces:
Sleeping
Sleeping
File size: 4,655 Bytes
d664445 21e349b 6c3a9de 21e349b 815574c 21e349b 5b8842a 21e349b 5b8842a 21e349b 7da9eae 815574c 092001b 7da9eae 815574c 7da9eae 092001b 815574c 7da9eae 815574c 7da9eae 815574c 6c3a9de 5b8842a 815574c 7da9eae 815574c 21e349b 815574c 21e349b 815574c 21e349b 7da9eae 815574c 21e349b 815574c 6ed3494 7da9eae 6ed3494 7da9eae 6ed3494 7da9eae 6ed3494 7da9eae 815574c 6c3a9de 815574c 7da9eae 21e349b 815574c fa04a9f 4cc8ead 815574c 21e349b e9df9b2 4cc8ead 5b8842a 21e349b 5b8842a 7da9eae 21e349b 5b8842a 21e349b 27e44c8 21e349b 5b8842a 21e349b 4873d31 |
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 |
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 LabelEncoder
# Load the trained model and scaler objects from file
REPO_ID = "Hemg/modelxxx"
MODEL_FILENAME = "predjob.joblib"
SCALER_FILENAME = "scalejob.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):
# Create a copy of the DataFrame
df_encoded = df.copy()
# Convert Yes/No to 1/0 for binary columns
binary_columns = ['Visited Parent', 'Visited College for Inquiry', 'Attended Any Event', 'College']
for col in binary_columns:
df_encoded[col] = df_encoded[col].map({'Yes': 1, 'No': 0}).astype(float)
# Encode other categorical columns
categorical_columns = ['Location', 'Course', 'Faculty', 'Source', 'Event', 'Presenter']
label_encoder = LabelEncoder()
for col in categorical_columns:
df_encoded[col] = label_encoder.fit_transform(df_encoded[col]).astype(float)
# Ensure numerical columns are float
numerical_columns = ['College Fee', 'GPA', 'Year']
for col in numerical_columns:
df_encoded[col] = df_encoded[col].astype(float)
return df_encoded
def predict_performance(Location, Course, College, Faculty, Source, Event, Presenter, Visited_Parent, Visited_College_for_Inquiry, Attended_Any_Event, College_Fee, GPA, Year):
# Create initial DataFrame
input_data = {
'Location': [Location],
'Course': [Course],
'College': [College],
'Faculty': [Faculty],
'Source': [Source],
'Event': [Event],
'Presenter': [Presenter],
'Visited Parent': [Visited_Parent],
'Visited College for Inquiry': [Visited_College_for_Inquiry],
'Attended Any Event': [Attended_Any_Event],
'College Fee': [float(College_Fee)],
'GPA': [float(GPA)],
'Year': [float(Year)]
}
input_df = pd.DataFrame(input_data)
print("\nInput DataFrame:")
print(input_df)
# Encode all categorical variables
encoded_df = encode_categorical_columns(input_df)
print("\nEncoded DataFrame:")
print(encoded_df)
# Normalize numerical features
# College Fee normalization
encoded_df['College Fee'] = (encoded_df['College Fee'] - 1000000) / (1700000 - 1000000)
# Year normalization
encoded_df['Year'] = (encoded_df['Year'] - 2019) / (2025 - 2019)
# GPA normalization
encoded_df['GPA'] = (encoded_df['GPA'] - 2.0) / (3.0 - 2.0)
print("\nNormalized DataFrame:")
print(encoded_df)
# Make prediction
prediction = model.predict(encoded_df.astype(float))[0]
# Clip prediction between 0 and 1
prediction = np.clip(prediction, 0, 1)
print("\nPrediction:", prediction)
return f"Chance of Admission: {prediction:.1f}"
# Create Gradio interface
iface = gr.Interface(
fn=predict_performance,
inputs=[
gr.Radio(["Kathmandu", "Bhaktapur", "Lalitpur", "Kritipur"], label="Location"),
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"),
gr.Radio(["Yes", "No"], label="College"),
gr.Radio(["Science", "Management", "Humanities"], label="Faculty"),
gr.Radio(["Event", "Facebook", "Instagram", "Offline", "Recommendation"], label="Source"),
gr.Radio(["New Year", "Dashain", "Orientation", "Fresher's Party", "Holi Festival", "Welcome Ceremony"],
label="Event"),
gr.Radio(["Ram", "Gita", "Manish", "Shyam", "Raj", "Hari", "Rina", "Shree"], label="Presenter"),
gr.Radio(["Yes", "No"], label="Visited Parent"),
gr.Radio(["Yes", "No"], label="Visited College for Inquiry"),
gr.Radio(["Yes", "No"], label="Attended Any Event"),
gr.Slider(minimum=1000000, maximum=1700000, step=1000, label="College Fee"),
gr.Slider(minimum=2.0, maximum=3.0, step=0.1, label="GPA"),
gr.Slider(minimum=2019, maximum=2025, step=1, label="Year")
],
outputs="text",
title="Chance of Student Admission",
description="Predict the chances of a student's admission based on various inputs."
)
# Run the app
if __name__ == "__main__":
iface.launch(share=True) |