ingtech
commited on
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,123 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import joblib
|
3 |
+
import numpy as np
|
4 |
+
import pandas as pd
|
5 |
+
from huggingface_hub import hf_hub_download
|
6 |
+
from sklearn.preprocessing import StandardScaler, LabelEncoder
|
7 |
+
|
8 |
+
REPO_ID = "Hemg/modelxxx"
|
9 |
+
MoDEL_FILENAME = "studentpredict.joblib"
|
10 |
+
SCALER_FILENAME = "studentscaler.joblib"
|
11 |
+
|
12 |
+
model = joblib.load(hf_hub_download(repo_id=REPO_ID, filename=MoDEL_FILENAME))
|
13 |
+
scaler = joblib.load(hf_hub_download(repo_id=REPO_ID, filename=SCALER_FILENAME))
|
14 |
+
|
15 |
+
def encode_categorical_columns(df):
|
16 |
+
label_encoder = LabelEncoder()
|
17 |
+
ordinal_columns = df.select_dtypes(include=['object']).columns
|
18 |
+
|
19 |
+
for col in ordinal_columns:
|
20 |
+
df[col] = label_encoder.fit_transform(df[col])
|
21 |
+
|
22 |
+
nominal_columns = df.select_dtypes(include=['object']).columns.difference(ordinal_columns)
|
23 |
+
df = pd.get_dummies(df, columns=nominal_columns, drop_first=True)
|
24 |
+
|
25 |
+
return df
|
26 |
+
|
27 |
+
def predict_performance(Location, College_Fee, College, GPA, Year, Course_Interested, Faculty, Source,
|
28 |
+
Visited_College_for_Inquiry_Only, Event, Attended_Any_Events,
|
29 |
+
Presenter, Visited_Parents):
|
30 |
+
try:
|
31 |
+
input_data = [[Location, College_Fee, College, GPA, Year, Course_Interested, Faculty, Source,
|
32 |
+
Visited_College_for_Inquiry_Only, Event, Attended_Any_Events,
|
33 |
+
Presenter, Visited_Parents]]
|
34 |
+
|
35 |
+
feature_names = ["Location", "College Fee", "College", "GPA", "Year", "Course Interested",
|
36 |
+
"Faculty", "Source", "Visited College for Inquiry Only", "Event",
|
37 |
+
"Attended Any Events", "Presenter", "Visited Parents"]
|
38 |
+
|
39 |
+
input_df = pd.DataFrame(input_data, columns=feature_names)
|
40 |
+
df = encode_categorical_columns(input_df)
|
41 |
+
df = df.reindex(columns=scaler.feature_names_in_, fill_value=0)
|
42 |
+
scaled_input = scaler.transform(df)
|
43 |
+
|
44 |
+
# Get probability prediction
|
45 |
+
probabilities = model.predict_proba(scaled_input)[0]
|
46 |
+
# Take the probability of positive class (usually index 1)
|
47 |
+
admission_probability = probabilities[1]
|
48 |
+
|
49 |
+
# Ensure the probability is between 0 and 1
|
50 |
+
admission_probability = np.clip(admission_probability, 0, 1)
|
51 |
+
|
52 |
+
# Convert to percentage
|
53 |
+
prediction_percentage = admission_probability * 100
|
54 |
+
|
55 |
+
# Create styled HTML output
|
56 |
+
# html_template = """
|
57 |
+
# <div style='text-align: center; padding: 20px;'>
|
58 |
+
# <div style='font-family: Arial, sans-serif; font-size: 24px; margin-bottom: 15px;'>
|
59 |
+
# Admission Probability: <span style='font-weight: bold;'>{:.1f}%</span>
|
60 |
+
# </div>
|
61 |
+
# <div style='{style}'>
|
62 |
+
# {message}
|
63 |
+
# </div>
|
64 |
+
# </div>
|
65 |
+
# """
|
66 |
+
# Create styled HTML output
|
67 |
+
html_template = """
|
68 |
+
<div style='text-align: center; padding: 20px;'>
|
69 |
+
<div style='{style}'>
|
70 |
+
{message}
|
71 |
+
</div>
|
72 |
+
</div>
|
73 |
+
"""
|
74 |
+
|
75 |
+
|
76 |
+
if prediction_percentage > 50:
|
77 |
+
style = "font-family: Arial, sans-serif; font-size: 32px; color: #28a745; font-weight: bold;"
|
78 |
+
message = "High chance of admission"
|
79 |
+
elif prediction_percentage < 50:
|
80 |
+
style = "font-family: Arial, sans-serif; font-size: 32px; color: #dc3545; font-weight: bold; text-transform: uppercase;"
|
81 |
+
message = "Lower chance of admission"
|
82 |
+
else: # exactly 50
|
83 |
+
style = "font-family: Arial, sans-serif; font-size: 32px; color: #ffc107; font-weight: bold;"
|
84 |
+
message = "Moderate chance of admission"
|
85 |
+
|
86 |
+
return html_template.format(prediction_percentage, style=style, message=message)
|
87 |
+
|
88 |
+
except Exception as e:
|
89 |
+
return f"<div style='color: red; font-family: Arial, sans-serif;'>Error in prediction: {str(e)}</div>"
|
90 |
+
|
91 |
+
# Update the Gradio interface
|
92 |
+
iface = gr.Interface(
|
93 |
+
fn=predict_performance,
|
94 |
+
inputs=[
|
95 |
+
gr.Radio(["Kathmandu", "Bhaktapur", "Lalitpur", "Kritipur"], label="Location",info="What is your current location?"),
|
96 |
+
gr.Slider(minimum=1000000, maximum=1700000,step=100000,label="College Fee", info="What 's the the total bachelor fee for the course you want to enroll?"),
|
97 |
+
gr.Radio(["Trinity", "CCRC", "KMC", "SOS", "ISMT", "St. Xavier's", "Everest", "Prime"], label="College", info="What is the name of the last college you attended?"),
|
98 |
+
gr.Slider(minimum=2, maximum=3, label="GPA", info="What is your GPA (Grade Point Average) of +2 ?"),
|
99 |
+
gr.Slider(minimum=2024, maximum=2026, step=1, label="Year", info="What is your intended year of admission?"),
|
100 |
+
#gr.Radio([2024, 2025, 2026], label="Year", info="What is your intended year of admission?")
|
101 |
+
gr.Radio(["MSc IT & Applied Security", "BSc (Hons) Computing", "BSc (Hons) Computing with Artificial Intelligence",
|
102 |
+
"BSc (Hons) Computer Networking & IT Security", "BSc (Hons) Multimedia Technologies", "MBA",
|
103 |
+
"BA (Hons) Accounting & Finance", "BA (Hons) Business Administration"], label="Course_Interested", info="Which course are you most interested in?"),
|
104 |
+
gr.Radio(["Science", "Management", "Humanities"], label="Faculty", info="what is your last stream ?"),
|
105 |
+
gr.Radio(["Event", "Facebook", "Instagram", "Offline", "Recommendation"], label="Source",info="How did you first hear about this college?"),
|
106 |
+
gr.Radio(["Yes", "No"], label="visited_college_for_inquery_only", info="Have you visited the college you're interested in for an inquiry or consultation?"),
|
107 |
+
gr.Radio(["Yes", "No"], label="attended_any_event", info="Have you attended any events organized by the college you're interested in?"),
|
108 |
+
gr.Radio(["New Year", "Dashain", "Orientation", "Fresher's Party", "Holi Festival", "Welcome Ceremony"],
|
109 |
+
label="attended_event_name", info="If yes, which events did you attend?" ),
|
110 |
+
gr.Radio(["Ram", "Gita", "Manish", "Shyam", "Raj", "Hari", "Rina", "Shree"], label="Presenter", info="who is the counser that help you while in counseling?"),
|
111 |
+
gr.Radio(["Yes", "No"], label="visited_with_parents", info="Did you visit the college with your parents?")
|
112 |
+
],
|
113 |
+
|
114 |
+
|
115 |
+
|
116 |
+
outputs=gr.HTML(), # Changed to HTML output
|
117 |
+
title="Student Admission Prediction",
|
118 |
+
description="Predict the probability of student admission",
|
119 |
+
css="body { font-family: Arial, sans-serif; }"
|
120 |
+
)
|
121 |
+
|
122 |
+
if __name__ == "__main__":
|
123 |
+
iface.launch(share=True)
|