Spaces:
Sleeping
Sleeping
Upload 2 files
Browse files- app.py +73 -0
- requirements.txt +6 -0
app.py
ADDED
@@ -0,0 +1,73 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import xgboost as xgb
|
3 |
+
import numpy as np
|
4 |
+
import joblib
|
5 |
+
import os
|
6 |
+
import warnings
|
7 |
+
|
8 |
+
# Suppress XGBoost warnings
|
9 |
+
warnings.filterwarnings("ignore", category=UserWarning, message=".*WARNING.*")
|
10 |
+
|
11 |
+
|
12 |
+
# Load your model (automatically detect XGBoost or joblib model)
|
13 |
+
def load_model():
|
14 |
+
if os.path.exists("models/best_model.json"):
|
15 |
+
model = xgb.Booster()
|
16 |
+
model.load_model("models/best_model.json")
|
17 |
+
print("β
Model loaded using XGBoost's native method.")
|
18 |
+
return model
|
19 |
+
elif os.path.exists("models/best_model.pkl"):
|
20 |
+
model = joblib.load("models/best_model.pkl")
|
21 |
+
print("β
Model loaded using Joblib.")
|
22 |
+
return model
|
23 |
+
else:
|
24 |
+
print("β No model file found.")
|
25 |
+
return None
|
26 |
+
|
27 |
+
|
28 |
+
model = load_model()
|
29 |
+
|
30 |
+
|
31 |
+
# Prediction function
|
32 |
+
def predict_employee_status(satisfaction_level, last_evaluation, number_project,
|
33 |
+
average_monthly_hours, time_spend_company,
|
34 |
+
work_accident, promotion_last_5years, salary):
|
35 |
+
input_data = np.array([[satisfaction_level, last_evaluation, number_project,
|
36 |
+
average_monthly_hours, time_spend_company,
|
37 |
+
work_accident, promotion_last_5years, salary]])
|
38 |
+
|
39 |
+
if model is None:
|
40 |
+
return "β No model found. Please upload the model file."
|
41 |
+
|
42 |
+
if isinstance(model, xgb.Booster):
|
43 |
+
dmatrix = xgb.DMatrix(input_data)
|
44 |
+
prediction = model.predict(dmatrix)[0]
|
45 |
+
result = "β
The employee is likely to Quit." if prediction > 0.5 else "β
The employee is likely to Stay."
|
46 |
+
else:
|
47 |
+
prediction = model.predict(input_data)[0]
|
48 |
+
result = "β
The employee is likely to Quit." if prediction == 1 else "β
The employee is likely to Stay."
|
49 |
+
|
50 |
+
return result
|
51 |
+
|
52 |
+
|
53 |
+
# Gradio interface with enhanced UI
|
54 |
+
interface = gr.Interface(
|
55 |
+
fn=predict_employee_status,
|
56 |
+
inputs=[
|
57 |
+
gr.Number(label="Satisfaction Level (0.0 - 1.0)", value=0.5),
|
58 |
+
gr.Number(label="Last Evaluation (0.0 - 1.0)", value=0.6),
|
59 |
+
gr.Number(label="Number of Projects (1 - 10)", value=3),
|
60 |
+
gr.Number(label="Average Monthly Hours (80 - 320)", value=150),
|
61 |
+
gr.Number(label="Time Spent at Company (Years)", value=3),
|
62 |
+
gr.Radio([0, 1], label="Work Accident (0 = No, 1 = Yes)"),
|
63 |
+
gr.Radio([0, 1], label="Promotion in Last 5 Years (0 = No, 1 = Yes)"),
|
64 |
+
gr.Dropdown(choices=[0, 1, 2], label="Salary Level (0 = Low, 1 = Medium, 2 = High)")
|
65 |
+
],
|
66 |
+
outputs="text",
|
67 |
+
title="π Employee Retention Prediction System",
|
68 |
+
description="Predict whether an employee is likely to stay or quit based on their profile.",
|
69 |
+
live=False
|
70 |
+
)
|
71 |
+
|
72 |
+
# Launch Gradio app
|
73 |
+
interface.launch()
|
requirements.txt
ADDED
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
gradio==3.15.0
|
2 |
+
xgboost>=1.6.0
|
3 |
+
numpy
|
4 |
+
joblib
|
5 |
+
matplotlib
|
6 |
+
pandas
|