Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -3,11 +3,12 @@ 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 |
-
|
9 |
-
|
10 |
-
|
|
|
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))
|
@@ -24,100 +25,43 @@ def encode_categorical_columns(df):
|
|
24 |
|
25 |
return df
|
26 |
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
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 |
-
|
36 |
-
|
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 |
-
|
45 |
-
|
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 |
-
|
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 |
-
|
77 |
-
|
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 |
-
|
|
|
87 |
|
88 |
-
|
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 |
-
|
95 |
-
gr.
|
96 |
-
gr.Slider(minimum=
|
97 |
-
gr.
|
98 |
-
gr.Slider(minimum=
|
99 |
-
gr.Slider(minimum=
|
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)
|
|
|
3 |
import numpy as np
|
4 |
import pandas as pd
|
5 |
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 |
+
REPO_ID = "Hemg/marketpredict" # Hugging Face repo ID
|
10 |
+
MoDEL_FILENAME = "stx.joblib" # Model file name
|
11 |
+
SCALER_FILENAME = "scaler.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))
|
|
|
25 |
|
26 |
return df
|
27 |
|
28 |
+
# Define the prediction function
|
29 |
+
def predict_performance(Year, Instagram_Advertising, Facebook_Advertising, Event_Expenses, Internet_Expenses):
|
30 |
+
# Prepare input data (represents independent variables for house prediction)
|
31 |
+
input_data = [[Year, Instagram_Advertising, Facebook_Advertising, Event_Expenses, Internet_Expenses]]
|
|
|
|
|
|
|
32 |
|
33 |
+
# Get the feature names from the Gradio interface inputs
|
34 |
+
feature_names = ["Year", "Instagram_Advertising", "Facebook_Advertising", "Event_Expenses", "Internet_Expenses"]
|
|
|
|
|
|
|
|
|
|
|
|
|
35 |
|
36 |
+
# Create a Pandas DataFrame with the input data and feature names
|
37 |
+
input_df = pd.DataFrame(input_data, columns=feature_names)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
38 |
|
39 |
+
input_df = encode_categorical_columns(input_df)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
40 |
|
41 |
+
# Scale the input data using the loaded scaler
|
42 |
+
scaled_input = scaler.transform(input_df)
|
43 |
|
44 |
+
# Make predictions using the loaded model
|
45 |
+
prediction = model.predict(scaled_input)[0]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
46 |
|
47 |
+
# Return the result as HTML with custom styling (green color and larger font)
|
48 |
+
return f'<p style="font-size: 24px; color: green;">Forecast no of. Students admission: {prediction:,.0f}</p>'
|
49 |
|
50 |
+
# Create the Gradio app
|
|
|
|
|
|
|
51 |
iface = gr.Interface(
|
52 |
fn=predict_performance,
|
53 |
+
inputs=[
|
54 |
+
gr.Slider(minimum=2024, maximum=2025, step=1, label="Year",info="The forecasted Year"),
|
55 |
+
gr.Slider(minimum=10000, maximum=45000, step=500, label="Instagram_Advertising", info="How much do you spend on Instagram ads Yearly($)?"),
|
56 |
+
gr.Slider(minimum=10000, maximum=75000, step=500, label="Facebook_Advertising", info="How much do you spend on Facebook ads Yearly($)?"),
|
57 |
+
gr.Slider(minimum=20000, maximum=100000, step=500, label="Event_Expenses", info="What’s your typical budget for events($)?"),
|
58 |
+
gr.Slider(minimum=5000, maximum=45000, step=500, label="Internet_Expenses", info="How much do you spend on internet Yearly($)?")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
59 |
],
|
60 |
+
outputs=gr.HTML(), # Specify the output as HTML
|
61 |
+
title="Student Admission Forecast",
|
62 |
+
description="Forecast of chances of student admission based on marketing expenditures"
|
|
|
|
|
|
|
|
|
63 |
)
|
64 |
|
65 |
+
# Run the app
|
66 |
if __name__ == "__main__":
|
67 |
iface.launch(share=True)
|