Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -14,20 +14,24 @@ model = joblib.load(hf_hub_download(repo_id=REPO_ID, filename=MODEL_FILENAME))
|
|
14 |
scaler = joblib.load(hf_hub_download(repo_id=REPO_ID, filename=SCALER_FILENAME))
|
15 |
|
16 |
def encode_categorical_columns(df):
|
17 |
-
|
18 |
-
|
19 |
-
# Create a copy of the DataFrame to avoid modifying the original
|
20 |
df_encoded = df.copy()
|
21 |
|
22 |
-
# Convert
|
23 |
-
binary_columns = ['Visited Parent', 'Visited College for Inquiry', 'Attended Any Event']
|
24 |
for col in binary_columns:
|
25 |
-
df_encoded[col] = df_encoded[col].map({'Yes': 1, 'No': 0})
|
26 |
|
27 |
# Encode other categorical columns
|
28 |
categorical_columns = ['Location', 'Course', 'Faculty', 'Source', 'Event', 'Presenter']
|
|
|
29 |
for col in categorical_columns:
|
30 |
-
df_encoded[col] = label_encoder.fit_transform(df_encoded[col])
|
|
|
|
|
|
|
|
|
|
|
31 |
|
32 |
return df_encoded
|
33 |
|
@@ -44,9 +48,9 @@ def predict_performance(Location, Course, College, Faculty, Source, Event, Prese
|
|
44 |
'Visited Parent': [Visited_Parent],
|
45 |
'Visited College for Inquiry': [Visited_College_for_Inquiry],
|
46 |
'Attended Any Event': [Attended_Any_Event],
|
47 |
-
'College Fee': [float(College_Fee)],
|
48 |
-
'GPA': [float(GPA)],
|
49 |
-
'Year': [float(Year)]
|
50 |
}
|
51 |
|
52 |
input_df = pd.DataFrame(input_data)
|
@@ -54,29 +58,27 @@ def predict_performance(Location, Course, College, Faculty, Source, Event, Prese
|
|
54 |
print("\nInput DataFrame:")
|
55 |
print(input_df)
|
56 |
|
57 |
-
# Encode categorical variables
|
58 |
encoded_df = encode_categorical_columns(input_df)
|
59 |
|
60 |
print("\nEncoded DataFrame:")
|
61 |
print(encoded_df)
|
62 |
|
63 |
-
# Normalize numerical features
|
64 |
-
|
65 |
-
encoded_df[
|
66 |
|
67 |
-
#
|
68 |
-
|
69 |
-
encoded_df['College Fee'] = (encoded_df['College Fee'] - college_fee_min) / (college_fee_max - college_fee_min)
|
70 |
|
71 |
-
#
|
72 |
-
|
73 |
-
encoded_df['Year'] = (encoded_df['Year'] - year_min) / (year_max - year_min)
|
74 |
|
75 |
-
print("\
|
76 |
print(encoded_df)
|
77 |
|
78 |
# Make prediction
|
79 |
-
prediction = model.predict(encoded_df)[0]
|
80 |
|
81 |
# Clip prediction between 0 and 1
|
82 |
prediction = np.clip(prediction, 0, 1)
|
@@ -85,7 +87,6 @@ def predict_performance(Location, Course, College, Faculty, Source, Event, Prese
|
|
85 |
|
86 |
return f"Chance of Admission: {prediction:.1f}"
|
87 |
|
88 |
-
# Create Gradio interface
|
89 |
# Create Gradio interface
|
90 |
iface = gr.Interface(
|
91 |
fn=predict_performance,
|
@@ -94,7 +95,7 @@ iface = gr.Interface(
|
|
94 |
gr.Radio(["MSc IT & Applied Security", "BSc (Hons) Computing", "BSc (Hons) Computing with Artificial Intelligence",
|
95 |
"BSc (Hons) Computer Networking & IT Security", "BSc (Hons) Multimedia Technologies", "MBA",
|
96 |
"BA (Hons) Accounting & Finance", "BA (Hons) Business Administration"], label="Course"),
|
97 |
-
gr.Radio(["Yes", "No"], label="College"),
|
98 |
gr.Radio(["Science", "Management", "Humanities"], label="Faculty"),
|
99 |
gr.Radio(["Event", "Facebook", "Instagram", "Offline", "Recommendation"], label="Source"),
|
100 |
gr.Radio(["New Year", "Dashain", "Orientation", "Fresher's Party", "Holi Festival", "Welcome Ceremony"],
|
@@ -112,8 +113,6 @@ iface = gr.Interface(
|
|
112 |
description="Predict the chances of a student's admission based on various inputs."
|
113 |
)
|
114 |
|
115 |
-
|
116 |
-
|
117 |
# Run the app
|
118 |
if __name__ == "__main__":
|
119 |
iface.launch(share=True)
|
|
|
14 |
scaler = joblib.load(hf_hub_download(repo_id=REPO_ID, filename=SCALER_FILENAME))
|
15 |
|
16 |
def encode_categorical_columns(df):
|
17 |
+
# Create a copy of the DataFrame
|
|
|
|
|
18 |
df_encoded = df.copy()
|
19 |
|
20 |
+
# Convert Yes/No to 1/0 for binary columns
|
21 |
+
binary_columns = ['Visited Parent', 'Visited College for Inquiry', 'Attended Any Event', 'College']
|
22 |
for col in binary_columns:
|
23 |
+
df_encoded[col] = df_encoded[col].map({'Yes': 1, 'No': 0}).astype(float)
|
24 |
|
25 |
# Encode other categorical columns
|
26 |
categorical_columns = ['Location', 'Course', 'Faculty', 'Source', 'Event', 'Presenter']
|
27 |
+
label_encoder = LabelEncoder()
|
28 |
for col in categorical_columns:
|
29 |
+
df_encoded[col] = label_encoder.fit_transform(df_encoded[col]).astype(float)
|
30 |
+
|
31 |
+
# Ensure numerical columns are float
|
32 |
+
numerical_columns = ['College Fee', 'GPA', 'Year']
|
33 |
+
for col in numerical_columns:
|
34 |
+
df_encoded[col] = df_encoded[col].astype(float)
|
35 |
|
36 |
return df_encoded
|
37 |
|
|
|
48 |
'Visited Parent': [Visited_Parent],
|
49 |
'Visited College for Inquiry': [Visited_College_for_Inquiry],
|
50 |
'Attended Any Event': [Attended_Any_Event],
|
51 |
+
'College Fee': [float(College_Fee)],
|
52 |
+
'GPA': [float(GPA)],
|
53 |
+
'Year': [float(Year)]
|
54 |
}
|
55 |
|
56 |
input_df = pd.DataFrame(input_data)
|
|
|
58 |
print("\nInput DataFrame:")
|
59 |
print(input_df)
|
60 |
|
61 |
+
# Encode all categorical variables
|
62 |
encoded_df = encode_categorical_columns(input_df)
|
63 |
|
64 |
print("\nEncoded DataFrame:")
|
65 |
print(encoded_df)
|
66 |
|
67 |
+
# Normalize numerical features
|
68 |
+
# College Fee normalization
|
69 |
+
encoded_df['College Fee'] = (encoded_df['College Fee'] - 1000000) / (1700000 - 1000000)
|
70 |
|
71 |
+
# Year normalization
|
72 |
+
encoded_df['Year'] = (encoded_df['Year'] - 2019) / (2025 - 2019)
|
|
|
73 |
|
74 |
+
# GPA normalization
|
75 |
+
encoded_df['GPA'] = (encoded_df['GPA'] - 2.0) / (3.0 - 2.0)
|
|
|
76 |
|
77 |
+
print("\nNormalized DataFrame:")
|
78 |
print(encoded_df)
|
79 |
|
80 |
# Make prediction
|
81 |
+
prediction = model.predict(encoded_df.astype(float))[0]
|
82 |
|
83 |
# Clip prediction between 0 and 1
|
84 |
prediction = np.clip(prediction, 0, 1)
|
|
|
87 |
|
88 |
return f"Chance of Admission: {prediction:.1f}"
|
89 |
|
|
|
90 |
# Create Gradio interface
|
91 |
iface = gr.Interface(
|
92 |
fn=predict_performance,
|
|
|
95 |
gr.Radio(["MSc IT & Applied Security", "BSc (Hons) Computing", "BSc (Hons) Computing with Artificial Intelligence",
|
96 |
"BSc (Hons) Computer Networking & IT Security", "BSc (Hons) Multimedia Technologies", "MBA",
|
97 |
"BA (Hons) Accounting & Finance", "BA (Hons) Business Administration"], label="Course"),
|
98 |
+
gr.Radio(["Yes", "No"], label="College"),
|
99 |
gr.Radio(["Science", "Management", "Humanities"], label="Faculty"),
|
100 |
gr.Radio(["Event", "Facebook", "Instagram", "Offline", "Recommendation"], label="Source"),
|
101 |
gr.Radio(["New Year", "Dashain", "Orientation", "Fresher's Party", "Holi Festival", "Welcome Ceremony"],
|
|
|
113 |
description="Predict the chances of a student's admission based on various inputs."
|
114 |
)
|
115 |
|
|
|
|
|
116 |
# Run the app
|
117 |
if __name__ == "__main__":
|
118 |
iface.launch(share=True)
|