Zeyadd-Mostaffa commited on
Commit
a719e13
Β·
verified Β·
1 Parent(s): 2750f6c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -9
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
- department_encoded = [1 if dept == department else 0 for dept in departments]
 
 
36
 
37
- # Prepare the input with all 18 features
38
- input_data = np.array([
39
- satisfaction_level, last_evaluation, number_project,
40
- average_monthly_hours, time_spent_company, work_accident,
41
- promotion_last_5years, salary
42
- ] + department_encoded).reshape(1, -1)
 
 
 
 
 
 
 
 
 
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(input_data)
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