Spaces:
Sleeping
Sleeping
Create app1.py
Browse files
app1.py
ADDED
@@ -0,0 +1,96 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
+
# Format the output
|
56 |
+
confidence_level = ""
|
57 |
+
if prediction_percentage >= 75:
|
58 |
+
confidence_level = "High chance of admission"
|
59 |
+
elif prediction_percentage >= 50:
|
60 |
+
confidence_level = "Moderate chance of admission"
|
61 |
+
else:
|
62 |
+
confidence_level = "Lower chance of admission"
|
63 |
+
|
64 |
+
return f"Chance of Admission: {prediction_percentage:.1f}%\n{confidence_level}"
|
65 |
+
|
66 |
+
except Exception as e:
|
67 |
+
return f"Error in prediction: {str(e)}"
|
68 |
+
|
69 |
+
# Create Gradio interface
|
70 |
+
iface = gr.Interface(
|
71 |
+
fn=predict_performance,
|
72 |
+
inputs=[
|
73 |
+
gr.Radio(["Kathmandu", "Bhaktapur", "Lalitpur", "Kritipur"], label="Location"),
|
74 |
+
gr.Slider(minimum=1000000, maximum=1700000, label="College Fee"),
|
75 |
+
gr.Radio(["Trinity", "CCRC", "KMC", "SOS", "ISMT", "St. Xavier's", "Everest", "Prime"], label="College"),
|
76 |
+
gr.Slider(minimum=2, maximum=3, label="GPA"),
|
77 |
+
gr.Slider(minimum=2020, maximum=2024, step=1, label="Year"),
|
78 |
+
gr.Radio(["MSc IT & Applied Security", "BSc (Hons) Computing", "BSc (Hons) Computing with Artificial Intelligence",
|
79 |
+
"BSc (Hons) Computer Networking & IT Security", "BSc (Hons) Multimedia Technologies", "MBA",
|
80 |
+
"BA (Hons) Accounting & Finance", "BA (Hons) Business Administration"], label="Course_Interested"),
|
81 |
+
gr.Radio(["Science", "Management", "Humanities"], label="Faculty"),
|
82 |
+
gr.Radio(["Event", "Facebook", "Instagram", "Offline", "Recommendation"], label="Source"),
|
83 |
+
gr.Radio(["Yes", "No"], label="visited_college_for_inquery_only"),
|
84 |
+
gr.Radio(["New Year", "Dashain", "Orientation", "Fresher's Party", "Holi Festival", "Welcome Ceremony"],
|
85 |
+
label="attended_event_name"),
|
86 |
+
gr.Radio(["Yes", "No"], label="attended_any_event"),
|
87 |
+
gr.Radio(["Ram", "Gita", "Manish", "Shyam", "Raj", "Hari", "Rina", "Shree"], label="Presenter"),
|
88 |
+
gr.Radio(["Yes", "No"], label="visited_with_parents")
|
89 |
+
],
|
90 |
+
outputs="text",
|
91 |
+
title="Student Admission Prediction",
|
92 |
+
description="Predict the probability of student admission"
|
93 |
+
)
|
94 |
+
|
95 |
+
if __name__ == "__main__":
|
96 |
+
iface.launch(share=True)
|