Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -2,7 +2,6 @@ import gradio as gr
|
|
2 |
import numpy as np
|
3 |
import pandas as pd
|
4 |
import joblib
|
5 |
-
import os
|
6 |
import warnings
|
7 |
from huggingface_hub import hf_hub_download
|
8 |
|
@@ -27,12 +26,11 @@ def predict_employee_status(
|
|
27 |
average_monthly_hours, time_spend_company,
|
28 |
work_accident, promotion_last_5years, salary, department, threshold=0.5
|
29 |
):
|
30 |
-
# List of all departments as encoded during training
|
31 |
departments = [
|
32 |
-
'
|
33 |
-
'
|
34 |
]
|
35 |
-
|
36 |
# One-hot encode department
|
37 |
department_features = {f"department_{dept}": 0 for dept in departments}
|
38 |
if department in departments:
|
@@ -42,7 +40,7 @@ def predict_employee_status(
|
|
42 |
satisfaction_evaluation = satisfaction_level * last_evaluation
|
43 |
work_balance = average_monthly_hours / number_project
|
44 |
|
45 |
-
#
|
46 |
input_data = {
|
47 |
"satisfaction_level": [satisfaction_level],
|
48 |
"last_evaluation": [last_evaluation],
|
@@ -59,6 +57,22 @@ def predict_employee_status(
|
|
59 |
|
60 |
input_df = pd.DataFrame(input_data)
|
61 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
62 |
try:
|
63 |
prob = model.predict_proba(input_df)[0][1]
|
64 |
result = "β
Employee is likely to quit." if prob >= threshold else "β
Employee is likely to stay."
|
@@ -80,8 +94,8 @@ def gradio_interface():
|
|
80 |
gr.Radio([0, 1], label="Promotion in Last 5 Years (0 = No, 1 = Yes)"),
|
81 |
gr.Radio([0, 1, 2], label="Salary (0 = Low, 1 = Medium, 2 = High)"),
|
82 |
gr.Dropdown(
|
83 |
-
['
|
84 |
-
'
|
85 |
label="Department"
|
86 |
),
|
87 |
gr.Slider(0.1, 0.9, value=0.5, step=0.05, label="Prediction Threshold")
|
|
|
2 |
import numpy as np
|
3 |
import pandas as pd
|
4 |
import joblib
|
|
|
5 |
import warnings
|
6 |
from huggingface_hub import hf_hub_download
|
7 |
|
|
|
26 |
average_monthly_hours, time_spend_company,
|
27 |
work_accident, promotion_last_5years, salary, department, threshold=0.5
|
28 |
):
|
|
|
29 |
departments = [
|
30 |
+
'sales', 'accounting', 'hr', 'technical', 'support',
|
31 |
+
'management', 'IT', 'product_mng', 'marketing', 'RandD'
|
32 |
]
|
33 |
+
|
34 |
# One-hot encode department
|
35 |
department_features = {f"department_{dept}": 0 for dept in departments}
|
36 |
if department in departments:
|
|
|
40 |
satisfaction_evaluation = satisfaction_level * last_evaluation
|
41 |
work_balance = average_monthly_hours / number_project
|
42 |
|
43 |
+
# Input data
|
44 |
input_data = {
|
45 |
"satisfaction_level": [satisfaction_level],
|
46 |
"last_evaluation": [last_evaluation],
|
|
|
57 |
|
58 |
input_df = pd.DataFrame(input_data)
|
59 |
|
60 |
+
# Match training column order exactly
|
61 |
+
expected_columns = [
|
62 |
+
'satisfaction_level', 'last_evaluation', 'number_project', 'average_monthly_hours',
|
63 |
+
'time_spend_company', 'Work_accident', 'promotion_last_5years', 'salary',
|
64 |
+
'satisfaction_evaluation', 'work_balance',
|
65 |
+
'department_IT', 'department_RandD', 'department_accounting', 'department_hr',
|
66 |
+
'department_management', 'department_marketing', 'department_product_mng',
|
67 |
+
'department_sales', 'department_support', 'department_technical'
|
68 |
+
]
|
69 |
+
|
70 |
+
for col in expected_columns:
|
71 |
+
if col not in input_df.columns:
|
72 |
+
input_df[col] = 0
|
73 |
+
input_df = input_df[expected_columns]
|
74 |
+
|
75 |
+
# Predict
|
76 |
try:
|
77 |
prob = model.predict_proba(input_df)[0][1]
|
78 |
result = "β
Employee is likely to quit." if prob >= threshold else "β
Employee is likely to stay."
|
|
|
94 |
gr.Radio([0, 1], label="Promotion in Last 5 Years (0 = No, 1 = Yes)"),
|
95 |
gr.Radio([0, 1, 2], label="Salary (0 = Low, 1 = Medium, 2 = High)"),
|
96 |
gr.Dropdown(
|
97 |
+
['sales', 'accounting', 'hr', 'technical', 'support',
|
98 |
+
'management', 'IT', 'product_mng', 'marketing', 'RandD'],
|
99 |
label="Department"
|
100 |
),
|
101 |
gr.Slider(0.1, 0.9, value=0.5, step=0.05, label="Prediction Threshold")
|