app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,141 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import pandas as pd
|
| 3 |
+
import numpy as np
|
| 4 |
+
|
| 5 |
+
from sklearn.model_selection import train_test_split
|
| 6 |
+
from sklearn.preprocessing import StandardScaler, OneHotEncoder
|
| 7 |
+
from sklearn.compose import ColumnTransformer
|
| 8 |
+
from sklearn.pipeline import Pipeline
|
| 9 |
+
from sklearn.multioutput import MultiOutputClassifier
|
| 10 |
+
from sklearn.metrics import accuracy_score
|
| 11 |
+
from sklearn.tree import DecisionTreeClassifier
|
| 12 |
+
from sklearn.ensemble import RandomForestClassifier
|
| 13 |
+
from sklearn.neighbors import KNeighborsClassifier
|
| 14 |
+
from sklearn.linear_model import LogisticRegression
|
| 15 |
+
from sklearn.svm import SVC
|
| 16 |
+
|
| 17 |
+
# ------------------- Load Data -------------------
|
| 18 |
+
df = pd.read_csv("Balanced_Placement_Data.csv")
|
| 19 |
+
|
| 20 |
+
features = [
|
| 21 |
+
'ssc_percentage', 'hsc_percentage', 'undergrad_degree', 'Graduate_degree_percentage',
|
| 22 |
+
'emp_test_percentage', 'Internship_Experience_Months', 'Certifications_Count',
|
| 23 |
+
'Technical_Skills_Score', 'Soft_Skills_Score', 'Hackathons_Participated',
|
| 24 |
+
'Resume_Score', 'Online_Course_Count', 'Social_Media_Presence'
|
| 25 |
+
]
|
| 26 |
+
target_columns = ['Placement_Status', 'Domain_of_Interest']
|
| 27 |
+
|
| 28 |
+
X = df[features]
|
| 29 |
+
y = df[target_columns]
|
| 30 |
+
|
| 31 |
+
categorical_features = ['undergrad_degree']
|
| 32 |
+
numerical_features = list(set(features) - set(categorical_features))
|
| 33 |
+
|
| 34 |
+
preprocessor = ColumnTransformer([
|
| 35 |
+
("num", StandardScaler(), numerical_features),
|
| 36 |
+
("cat", OneHotEncoder(drop="first"), categorical_features)
|
| 37 |
+
])
|
| 38 |
+
|
| 39 |
+
models = {
|
| 40 |
+
"Random Forest": RandomForestClassifier(random_state=42),
|
| 41 |
+
"Decision Tree": DecisionTreeClassifier(random_state=42),
|
| 42 |
+
"KNN": KNeighborsClassifier(),
|
| 43 |
+
"Logistic Regression": LogisticRegression(max_iter=1000),
|
| 44 |
+
"SVM": SVC(probability=True)
|
| 45 |
+
}
|
| 46 |
+
|
| 47 |
+
# ------------------- Train Models -------------------
|
| 48 |
+
def train_models():
|
| 49 |
+
X_train, X_test, y_train, y_test = train_test_split(
|
| 50 |
+
X, y, test_size=0.2, random_state=42
|
| 51 |
+
)
|
| 52 |
+
results = {}
|
| 53 |
+
for name, clf in models.items():
|
| 54 |
+
pipe = Pipeline([
|
| 55 |
+
("preprocessor", preprocessor),
|
| 56 |
+
("classifier", MultiOutputClassifier(clf))
|
| 57 |
+
])
|
| 58 |
+
pipe.fit(X_train, y_train)
|
| 59 |
+
y_pred = pipe.predict(X_test)
|
| 60 |
+
|
| 61 |
+
placement_acc = accuracy_score(y_test["Placement_Status"], y_pred[:,0])
|
| 62 |
+
domain_acc = accuracy_score(y_test["Domain_of_Interest"], y_pred[:,1])
|
| 63 |
+
|
| 64 |
+
results[name] = {
|
| 65 |
+
"Placement Accuracy": placement_acc,
|
| 66 |
+
"Domain Accuracy": domain_acc,
|
| 67 |
+
"Model": pipe
|
| 68 |
+
}
|
| 69 |
+
return results
|
| 70 |
+
|
| 71 |
+
results = train_models()
|
| 72 |
+
best_model_name = max(results, key=lambda m: results[m]["Placement Accuracy"] + results[m]["Domain Accuracy"])
|
| 73 |
+
best_model = results[best_model_name]["Model"]
|
| 74 |
+
|
| 75 |
+
# ------------------- Prediction Function -------------------
|
| 76 |
+
def predict_placement_and_domain(
|
| 77 |
+
ssc_percentage, hsc_percentage, undergrad_degree, Graduate_degree_percentage,
|
| 78 |
+
emp_test_percentage, Internship_Experience_Months, Certifications_Count,
|
| 79 |
+
Technical_Skills_Score, Soft_Skills_Score, Hackathons_Participated,
|
| 80 |
+
Resume_Score, Online_Course_Count, Social_Media_Presence
|
| 81 |
+
):
|
| 82 |
+
user_input = {
|
| 83 |
+
"ssc_percentage": ssc_percentage,
|
| 84 |
+
"hsc_percentage": hsc_percentage,
|
| 85 |
+
"undergrad_degree": undergrad_degree,
|
| 86 |
+
"Graduate_degree_percentage": Graduate_degree_percentage,
|
| 87 |
+
"emp_test_percentage": emp_test_percentage,
|
| 88 |
+
"Internship_Experience_Months": Internship_Experience_Months,
|
| 89 |
+
"Certifications_Count": Certifications_Count,
|
| 90 |
+
"Technical_Skills_Score": Technical_Skills_Score,
|
| 91 |
+
"Soft_Skills_Score": Soft_Skills_Score,
|
| 92 |
+
"Hackathons_Participated": Hackathons_Participated,
|
| 93 |
+
"Resume_Score": Resume_Score,
|
| 94 |
+
"Online_Course_Count": Online_Course_Count,
|
| 95 |
+
"Social_Media_Presence": Social_Media_Presence
|
| 96 |
+
}
|
| 97 |
+
|
| 98 |
+
input_df = pd.DataFrame([user_input])
|
| 99 |
+
prediction = best_model.predict(input_df)
|
| 100 |
+
|
| 101 |
+
return {
|
| 102 |
+
"Placement Status": prediction[0][0],
|
| 103 |
+
"Domain of Interest": prediction[0][1],
|
| 104 |
+
"Best Model": best_model_name
|
| 105 |
+
}
|
| 106 |
+
|
| 107 |
+
# ------------------- Gradio UI -------------------
|
| 108 |
+
with gr.Blocks() as demo:
|
| 109 |
+
gr.Markdown("# 🎯 Placement & Domain Predictor")
|
| 110 |
+
|
| 111 |
+
with gr.Row():
|
| 112 |
+
with gr.Column():
|
| 113 |
+
ssc_percentage = gr.Number(label="SSC Percentage", value=70)
|
| 114 |
+
hsc_percentage = gr.Number(label="HSC Percentage", value=65)
|
| 115 |
+
undergrad_degree = gr.Dropdown(choices=list(df['undergrad_degree'].unique()), label="Undergrad Degree")
|
| 116 |
+
Graduate_degree_percentage = gr.Number(label="Graduate Degree %", value=60)
|
| 117 |
+
emp_test_percentage = gr.Number(label="Employment Test %", value=50)
|
| 118 |
+
Internship_Experience_Months = gr.Number(label="Internship Months", value=0)
|
| 119 |
+
Certifications_Count = gr.Number(label="Certifications Count", value=1)
|
| 120 |
+
Technical_Skills_Score = gr.Number(label="Technical Skills Score", value=60)
|
| 121 |
+
Soft_Skills_Score = gr.Number(label="Soft Skills Score", value=60)
|
| 122 |
+
Hackathons_Participated = gr.Number(label="Hackathons Participated", value=1)
|
| 123 |
+
Resume_Score = gr.Number(label="Resume Score", value=50)
|
| 124 |
+
Online_Course_Count = gr.Number(label="Online Course Count", value=2)
|
| 125 |
+
Social_Media_Presence = gr.Number(label="Social Media Presence (0/1)", value=1)
|
| 126 |
+
|
| 127 |
+
btn = gr.Button("Predict")
|
| 128 |
+
|
| 129 |
+
with gr.Column():
|
| 130 |
+
output = gr.JSON(label="Prediction Result")
|
| 131 |
+
|
| 132 |
+
btn.click(
|
| 133 |
+
predict_placement_and_domain,
|
| 134 |
+
inputs=[ssc_percentage, hsc_percentage, undergrad_degree, Graduate_degree_percentage,
|
| 135 |
+
emp_test_percentage, Internship_Experience_Months, Certifications_Count,
|
| 136 |
+
Technical_Skills_Score, Soft_Skills_Score, Hackathons_Participated,
|
| 137 |
+
Resume_Score, Online_Course_Count, Social_Media_Presence],
|
| 138 |
+
outputs=output
|
| 139 |
+
)
|
| 140 |
+
|
| 141 |
+
demo.launch()
|