Spaces:
Running
Running
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,62 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import warnings
|
2 |
+
warnings.filterwarnings('ignore')
|
3 |
+
import pandas as pd
|
4 |
+
import numpy as np
|
5 |
+
from sklearn import preprocessing
|
6 |
+
from sklearn.ensemble import GradientBoostingClassifier
|
7 |
+
import pickle
|
8 |
+
import gradio as gr
|
9 |
+
|
10 |
+
# Load the model and encoder
|
11 |
+
with open("model.pkl", "rb") as model_file:
|
12 |
+
gbc = pickle.load(model_file)
|
13 |
+
|
14 |
+
with open("encoder.pkl", "rb") as encoder_file:
|
15 |
+
encoder_dict = pickle.load(encoder_file)
|
16 |
+
|
17 |
+
def predict_employability(Age, Accessibility, EdLevel, Employment, Gender, MentalHealth, MainBranch, YearsCode, PreviousSalary, ComputerSkills, Continent):
|
18 |
+
data = {
|
19 |
+
'Age': Age, 'Accessibility': Accessibility, 'EdLevel': EdLevel, 'Employment': Employment,
|
20 |
+
'Gender': Gender, 'MentalHealth': MentalHealth, 'MainBranch': MainBranch,
|
21 |
+
'YearsCode': YearsCode, 'PreviousSalary': PreviousSalary, 'ComputerSkills': ComputerSkills,
|
22 |
+
'Continent': Continent
|
23 |
+
}
|
24 |
+
df = pd.DataFrame([list(data.values())], columns=[
|
25 |
+
'Age', 'Accessibility', 'EdLevel', 'Employment', 'Gender', 'MentalHealth',
|
26 |
+
'MainBranch', 'YearsCode', 'PreviousSalary', 'ComputerSkills', 'Continent'
|
27 |
+
])
|
28 |
+
category_col = ['Age', 'Accessibility', 'EdLevel', 'Gender', 'MentalHealth', 'MainBranch', 'Continent']
|
29 |
+
for cat in encoder_dict:
|
30 |
+
for col in df.columns:
|
31 |
+
le = preprocessing.LabelEncoder()
|
32 |
+
if cat == col:
|
33 |
+
le.classes_ = np.array(encoder_dict[cat], dtype=object)
|
34 |
+
for unique_item in df[col].unique():
|
35 |
+
if unique_item not in le.classes_:
|
36 |
+
df[col] = ['Unknown' if x == unique_item else x for x in df[col]]
|
37 |
+
df[col] = le.transform(df[col].astype(str))
|
38 |
+
features_list = df.values.tolist()
|
39 |
+
prediction = gbc.predict(features_list)
|
40 |
+
return "Employable" if prediction[0] == 1 else "Less Employable"
|
41 |
+
|
42 |
+
iface = gr.Interface(
|
43 |
+
fn=predict_employability,
|
44 |
+
inputs=[
|
45 |
+
gr.Dropdown(['<35', '>35'], label="Age"),
|
46 |
+
gr.Dropdown(['No', 'Yes'], label="Accessibility"),
|
47 |
+
gr.Dropdown(['Master', 'NoHigherEd', 'Other', 'PhD', 'Undergraduate'], label="EdLevel"),
|
48 |
+
gr.Slider(0, 1, step=1, label="Employment"),
|
49 |
+
gr.Dropdown(['Man', 'NonBinary', 'Woman'], label="Gender"),
|
50 |
+
gr.Dropdown(['No', 'Yes'], label="MentalHealth"),
|
51 |
+
gr.Dropdown(['Dev', 'NotDev'], label="MainBranch"),
|
52 |
+
gr.Slider(0, 50, step=1, label="YearsCode"),
|
53 |
+
gr.Number(label="PreviousSalary"),
|
54 |
+
gr.Slider(0, 100, step=1, label="ComputerSkills"),
|
55 |
+
gr.Dropdown(['Africa', 'Asia', 'Europe', 'North_America', 'Oceania', 'Others', 'South_America'], label="Continent")
|
56 |
+
],
|
57 |
+
outputs="text",
|
58 |
+
title="Employability Prediction",
|
59 |
+
description="Predict employability based on various features."
|
60 |
+
)
|
61 |
+
|
62 |
+
iface.launch()
|