Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,157 +1,55 @@
|
|
1 |
-
|
2 |
-
import
|
3 |
-
import
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
'
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
prediction = loaded_model.predict(input_data)[0]
|
58 |
-
|
59 |
-
return {"Leave": prediction, "Stay": 1 - prediction}
|
60 |
-
|
61 |
-
|
62 |
-
# Create sliders for user input
|
63 |
-
|
64 |
-
|
65 |
-
engagement_slider = gr.Slider(minimum=1, maximum=5, value=3, label="Engagement")
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
work_environment_slider = gr.Slider(minimum=1, maximum=5, value=3, label="Work Environment")
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
upper_level_management_slider = gr.Slider(minimum=1, maximum=5, value=3, label="Upper Level Management")
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
rewards_benefits_slider = gr.Slider(minimum=1, maximum=5, value=3, label="Rewards Benefits")
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
employee_wellbeing_slider = gr.Slider(minimum=1, maximum=5, value=3, label="Employee Well-Being")
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
workload_slider = gr.Slider(minimum=1, maximum=5, value=3, label="Workload")
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
learning_development_slider = gr.Slider(minimum=1, maximum=5, value=3, label="Learning & Development")
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
# Create the interface
|
98 |
-
interface = gr.Interface(
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
fn=predict_intent_to_stay,
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
inputs=[
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
engagement_slider,
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
work_environment_slider,
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
upper_level_management_slider,
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
rewards_benefits_slider,
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
employee_wellbeing_slider,
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
workload_slider,
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
learning_development_slider
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
],
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
outputs="text"
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
)
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
# Launch the interface
|
155 |
-
|
156 |
-
interface.launch()
|
157 |
-
|
|
|
1 |
+
import pandas as pd
|
2 |
+
import gradio as gr
|
3 |
+
import pickle
|
4 |
+
|
5 |
+
|
6 |
+
# Load the XGBoost model from disk
|
7 |
+
loaded_model = pickle.load(open("xgb_h.pkl", 'rb'))
|
8 |
+
|
9 |
+
|
10 |
+
# Function to predict intent to stay
|
11 |
+
def predict_intent_to_stay(Engagement, WorkEnvironment, UpperLevelManagement, RewardsBenefits, EmployeeWellBeing, Workload, LearningDevelopment):
|
12 |
+
|
13 |
+
# Create input DataFrame
|
14 |
+
input_data = pd.DataFrame({
|
15 |
+
'Engagement': [Engagement],
|
16 |
+
'WorkEnvironment': [WorkEnvironment],
|
17 |
+
'UpperLevelManagement': [UpperLevelManagement],
|
18 |
+
'RewardsBenefits': [RewardsBenefits],
|
19 |
+
'EmployeeWellBeing': [EmployeeWellBeing],
|
20 |
+
'Workload': [Workload],
|
21 |
+
'LearningDevelopment': [LearningDevelopment]
|
22 |
+
})
|
23 |
+
|
24 |
+
# Perform prediction using the loaded model
|
25 |
+
prediction = loaded_model.predict_proba(input_data)[0]
|
26 |
+
|
27 |
+
return {"Leave": prediction[0], "Stay": prediction[1]}
|
28 |
+
|
29 |
+
|
30 |
+
# Create sliders for user input
|
31 |
+
engagement_slider = gr.Slider(minimum=1, maximum=5, value=3, label="Engagement")
|
32 |
+
work_environment_slider = gr.Slider(minimum=1, maximum=5, value=3, label="Work Environment")
|
33 |
+
upper_level_management_slider = gr.Slider(minimum=1, maximum=5, value=3, label="Upper Level Management")
|
34 |
+
rewards_benefits_slider = gr.Slider(minimum=1, maximum=5, value=3, label="Rewards Benefits")
|
35 |
+
employee_wellbeing_slider = gr.Slider(minimum=1, maximum=5, value=3, label="Employee Well-Being")
|
36 |
+
workload_slider = gr.Slider(minimum=1, maximum=5, value=3, label="Workload")
|
37 |
+
learning_development_slider = gr.Slider(minimum=1, maximum=5, value=3, label="Learning & Development")
|
38 |
+
|
39 |
+
# Create the interface
|
40 |
+
interface = gr.Interface(
|
41 |
+
fn=predict_intent_to_stay,
|
42 |
+
inputs=[
|
43 |
+
engagement_slider,
|
44 |
+
work_environment_slider,
|
45 |
+
upper_level_management_slider,
|
46 |
+
rewards_benefits_slider,
|
47 |
+
employee_wellbeing_slider,
|
48 |
+
workload_slider,
|
49 |
+
learning_development_slider
|
50 |
+
],
|
51 |
+
outputs="text"
|
52 |
+
)
|
53 |
+
|
54 |
+
# Launch the interface
|
55 |
+
interface.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|