Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,6 +1,7 @@
|
|
1 |
import gradio as gr
|
2 |
import xgboost as xgb
|
3 |
import numpy as np
|
|
|
4 |
import joblib
|
5 |
import os
|
6 |
import warnings
|
@@ -32,23 +33,34 @@ def predict_employee_status(satisfaction_level, last_evaluation, number_project,
|
|
32 |
'RandD', 'accounting', 'hr', 'management', 'marketing',
|
33 |
'product_mng', 'sales', 'support', 'technical'
|
34 |
]
|
35 |
-
|
|
|
|
|
36 |
|
37 |
-
# Prepare the input with all 18 features
|
38 |
-
input_data =
|
39 |
-
satisfaction_level
|
40 |
-
|
41 |
-
|
42 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
43 |
|
44 |
# Predict using the model
|
45 |
if model is None:
|
46 |
return "β No model found. Please upload the model file."
|
47 |
|
48 |
try:
|
49 |
-
dmatrix = xgb.DMatrix(
|
50 |
prediction = model.predict(dmatrix)
|
51 |
-
return "Employee is likely to quit." if prediction[0] > 0.5 else "Employee is likely to stay."
|
52 |
except Exception as e:
|
53 |
return f"β Error: {str(e)}"
|
54 |
|
|
|
1 |
import gradio as gr
|
2 |
import xgboost as xgb
|
3 |
import numpy as np
|
4 |
+
import pandas as pd
|
5 |
import joblib
|
6 |
import os
|
7 |
import warnings
|
|
|
33 |
'RandD', 'accounting', 'hr', 'management', 'marketing',
|
34 |
'product_mng', 'sales', 'support', 'technical'
|
35 |
]
|
36 |
+
department_features = {f"department_{dept}": 0 for dept in departments}
|
37 |
+
if department in departments:
|
38 |
+
department_features[f"department_{department}"] = 1
|
39 |
|
40 |
+
# Prepare the input with all 18 features as a DataFrame with column names
|
41 |
+
input_data = {
|
42 |
+
"satisfaction_level": [satisfaction_level],
|
43 |
+
"last_evaluation": [last_evaluation],
|
44 |
+
"number_project": [number_project],
|
45 |
+
"average_montly_hours": [average_monthly_hours],
|
46 |
+
"time_spend_company": [time_spent_company],
|
47 |
+
"Work_accident": [work_accident],
|
48 |
+
"promotion_last_5years": [promotion_last_5years],
|
49 |
+
"salary": [salary],
|
50 |
+
**department_features,
|
51 |
+
"satisfaction_evaluation": [satisfaction_level * last_evaluation]
|
52 |
+
}
|
53 |
+
|
54 |
+
input_df = pd.DataFrame(input_data)
|
55 |
|
56 |
# Predict using the model
|
57 |
if model is None:
|
58 |
return "β No model found. Please upload the model file."
|
59 |
|
60 |
try:
|
61 |
+
dmatrix = xgb.DMatrix(input_df)
|
62 |
prediction = model.predict(dmatrix)
|
63 |
+
return "β
Employee is likely to quit." if prediction[0] > 0.5 else "β
Employee is likely to stay."
|
64 |
except Exception as e:
|
65 |
return f"β Error: {str(e)}"
|
66 |
|