Zeyadd-Mostaffa commited on
Commit
f442952
Β·
verified Β·
1 Parent(s): d72133a

Delete app.py

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