Update app.py
Browse files
app.py
CHANGED
@@ -6,16 +6,13 @@ from huggingface_hub import hf_hub_download
|
|
6 |
from sklearn.preprocessing import StandardScaler, OneHotEncoder, LabelEncoder
|
7 |
|
8 |
# Load the trained model and scaler objects from file
|
|
|
|
|
|
|
9 |
|
10 |
-
|
11 |
-
REPO_ID = "Hemg/modelxxx" # hugging face repo ID
|
12 |
-
MoDEL_FILENAME = "predjob.joblib" # modlinearel file name
|
13 |
-
SCALER_FILENAME ="scalejob.joblib" # scaler file name
|
14 |
-
|
15 |
-
model = joblib.load(hf_hub_download(repo_id=REPO_ID, filename=MoDEL_FILENAME))
|
16 |
-
|
17 |
scaler = joblib.load(hf_hub_download(repo_id=REPO_ID, filename=SCALER_FILENAME))
|
18 |
-
|
19 |
def encode_categorical_columns(df):
|
20 |
label_encoder = LabelEncoder()
|
21 |
ordinal_columns = df.select_dtypes(include=['object']).columns
|
@@ -29,28 +26,27 @@ def encode_categorical_columns(df):
|
|
29 |
return df
|
30 |
|
31 |
# Define the prediction function
|
32 |
-
def predict_performance(Location,Course,College,Faculty,Source,Event,Presenter,
|
33 |
-
|
34 |
# Debug print 1: Print all input values
|
35 |
print("\nInput Values:")
|
36 |
print(f"Location: {Location}")
|
37 |
print(f"College Fee: {College_Fee}")
|
38 |
print(f"GPA: {GPA}")
|
39 |
print(f"Year: {Year}")
|
40 |
-
print(f"Course: {
|
41 |
print(f"Faculty: {Faculty}")
|
42 |
print(f"Source: {Source}")
|
43 |
-
print(f"Visited College for Inquiry: {
|
44 |
-
print(f"Event
|
45 |
-
print(f"Attended Any
|
46 |
print(f"Presenter: {Presenter}")
|
47 |
-
print(f"Visited with
|
48 |
|
49 |
-
input_data = [Location,Course,College,Faculty,Source,Event,Presenter,
|
50 |
|
51 |
-
feature_names = ["Location", "Course", "College", "Faculty", "Source", "Event", "Presenter", "
|
52 |
|
53 |
-
input_df = pd.DataFrame(input_data, columns=feature_names)
|
54 |
|
55 |
# Debug print 2: Show DataFrame before encoding
|
56 |
print("\nDataFrame before encoding:")
|
@@ -64,23 +60,21 @@ def predict_performance(Location,Course,College,Faculty,Source,Event,Presenter,V
|
|
64 |
|
65 |
scaled_input = scaler.transform(df)
|
66 |
|
67 |
-
#
|
68 |
-
|
69 |
-
# print(scaled_input)
|
70 |
|
71 |
-
# prediction
|
|
|
|
|
|
|
|
|
72 |
|
73 |
-
# # Debug print 5: Show prediction details
|
74 |
-
# print("\nPrediction details:")
|
75 |
-
# print(f"Raw prediction: {prediction}")
|
76 |
-
# prediction_probability = 1 / (1 + np.exp(-prediction))
|
77 |
-
# print(f"Probability: {prediction_probability}")
|
78 |
prediction_percentage = prediction_probability * 100
|
79 |
print(f"Percentage: {prediction_percentage}")
|
80 |
|
81 |
return f"Chance of Admission: {prediction_percentage:.1f}%"
|
82 |
|
83 |
-
|
84 |
iface = gr.Interface(
|
85 |
fn=predict_performance,
|
86 |
inputs=[
|
@@ -90,19 +84,19 @@ iface = gr.Interface(
|
|
90 |
gr.Slider(minimum=2019, maximum=2025, step=1, label="Year"),
|
91 |
gr.Radio(["MSc IT & Applied Security", "BSc (Hons) Computing", "BSc (Hons) Computing with Artificial Intelligence",
|
92 |
"BSc (Hons) Computer Networking & IT Security", "BSc (Hons) Multimedia Technologies", "MBA",
|
93 |
-
"BA (Hons) Accounting &
|
94 |
gr.Radio(["Science", "Management", "Humanities"], label="Faculty"),
|
95 |
gr.Radio(["Event", "Facebook", "Instagram", "Offline", "Recommendation"], label="Source"),
|
96 |
-
gr.Radio(["Yes", "No"], label="
|
97 |
gr.Radio(["New Year", "Dashain", "Orientation", "Fresher's Party", "Holi Festival", "Welcome Ceremony"],
|
98 |
-
|
99 |
-
gr.Radio(["Yes", "No"], label="
|
100 |
gr.Radio(["Ram", "Gita", "Manish", "Shyam", "Raj", "Hari", "Rina", "Shree"], label="Presenter"),
|
101 |
-
gr.Radio(["Yes", "No"], label="
|
102 |
],
|
103 |
outputs="text",
|
104 |
-
title="
|
105 |
-
description="chances of student admission"
|
106 |
)
|
107 |
|
108 |
# Run the app
|
|
|
6 |
from sklearn.preprocessing import StandardScaler, OneHotEncoder, LabelEncoder
|
7 |
|
8 |
# Load the trained model and scaler objects from file
|
9 |
+
REPO_ID = "Hemg/modelxxx" # hugging face repo ID
|
10 |
+
MODEL_FILENAME = "predjob.joblib" # model file name
|
11 |
+
SCALER_FILENAME = "scalejob.joblib" # scaler file name
|
12 |
|
13 |
+
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 |
label_encoder = LabelEncoder()
|
18 |
ordinal_columns = df.select_dtypes(include=['object']).columns
|
|
|
26 |
return df
|
27 |
|
28 |
# Define the prediction function
|
29 |
+
def predict_performance(Location, Course, College, Faculty, Source, Event, Presenter, Visited_Parent, Visited_College_for_Inquiry, Attended_Any_Event, College_Fee, GPA, Year):
|
|
|
30 |
# Debug print 1: Print all input values
|
31 |
print("\nInput Values:")
|
32 |
print(f"Location: {Location}")
|
33 |
print(f"College Fee: {College_Fee}")
|
34 |
print(f"GPA: {GPA}")
|
35 |
print(f"Year: {Year}")
|
36 |
+
print(f"Course: {Course}")
|
37 |
print(f"Faculty: {Faculty}")
|
38 |
print(f"Source: {Source}")
|
39 |
+
print(f"Visited College for Inquiry: {Visited_College_for_Inquiry}")
|
40 |
+
print(f"Event: {Event}")
|
41 |
+
print(f"Attended Any Event: {Attended_Any_Event}")
|
42 |
print(f"Presenter: {Presenter}")
|
43 |
+
print(f"Visited with Parents: {Visited_Parent}")
|
44 |
|
45 |
+
input_data = [Location, Course, College, Faculty, Source, Event, Presenter, Visited_Parent, Visited_College_for_Inquiry, Attended_Any_Event, College_Fee, GPA, Year]
|
46 |
|
47 |
+
feature_names = ["Location", "Course", "College", "Faculty", "Source", "Event", "Presenter", "Visited_Parent", "Visited_College_for_Inquiry", "Attended_Any_Event", "College_Fee", "GPA", "Year"]
|
48 |
|
49 |
+
input_df = pd.DataFrame([input_data], columns=feature_names)
|
50 |
|
51 |
# Debug print 2: Show DataFrame before encoding
|
52 |
print("\nDataFrame before encoding:")
|
|
|
60 |
|
61 |
scaled_input = scaler.transform(df)
|
62 |
|
63 |
+
# Make the prediction
|
64 |
+
prediction = model.predict(scaled_input)[0]
|
|
|
65 |
|
66 |
+
# Debug print 4: Show prediction details
|
67 |
+
print("\nPrediction details:")
|
68 |
+
print(f"Raw prediction: {prediction}")
|
69 |
+
prediction_probability = 1 / (1 + np.exp(-prediction))
|
70 |
+
print(f"Probability: {prediction_probability}")
|
71 |
|
|
|
|
|
|
|
|
|
|
|
72 |
prediction_percentage = prediction_probability * 100
|
73 |
print(f"Percentage: {prediction_percentage}")
|
74 |
|
75 |
return f"Chance of Admission: {prediction_percentage:.1f}%"
|
76 |
|
77 |
+
# Create Gradio interface
|
78 |
iface = gr.Interface(
|
79 |
fn=predict_performance,
|
80 |
inputs=[
|
|
|
84 |
gr.Slider(minimum=2019, maximum=2025, step=1, label="Year"),
|
85 |
gr.Radio(["MSc IT & Applied Security", "BSc (Hons) Computing", "BSc (Hons) Computing with Artificial Intelligence",
|
86 |
"BSc (Hons) Computer Networking & IT Security", "BSc (Hons) Multimedia Technologies", "MBA",
|
87 |
+
"BA (Hons) Accounting & Finance", "BA (Hons) Business Administration"], label="Course"),
|
88 |
gr.Radio(["Science", "Management", "Humanities"], label="Faculty"),
|
89 |
gr.Radio(["Event", "Facebook", "Instagram", "Offline", "Recommendation"], label="Source"),
|
90 |
+
gr.Radio(["Yes", "No"], label="Visited College for Inquiry"),
|
91 |
gr.Radio(["New Year", "Dashain", "Orientation", "Fresher's Party", "Holi Festival", "Welcome Ceremony"],
|
92 |
+
label="Event"),
|
93 |
+
gr.Radio(["Yes", "No"], label="Attended Any Event"),
|
94 |
gr.Radio(["Ram", "Gita", "Manish", "Shyam", "Raj", "Hari", "Rina", "Shree"], label="Presenter"),
|
95 |
+
gr.Radio(["Yes", "No"], label="Visited with Parents")
|
96 |
],
|
97 |
outputs="text",
|
98 |
+
title="Chance of Student Admission",
|
99 |
+
description="Predict the chances of a student's admission based on various inputs."
|
100 |
)
|
101 |
|
102 |
# Run the app
|