Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -12,6 +12,16 @@ loaded_model = pickle.load(open("filtered_xgb_model.pkl", 'rb'))
|
|
12 |
# Setup SHAP
|
13 |
explainer = shap.Explainer(loaded_model) # PLEASE DO NOT CHANGE THIS.
|
14 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
15 |
# Create the main function for server
|
16 |
def main_func(GM3, WorkEnv3, WellBeing2, GM2, JobSecurity, WellBeing1):
|
17 |
new_row = pd.DataFrame.from_dict({
|
@@ -37,77 +47,40 @@ def main_func(GM3, WorkEnv3, WellBeing2, GM2, JobSecurity, WellBeing1):
|
|
37 |
|
38 |
return {"Leave": float(prob[0][0]), "Stay": 1-float(prob[0][0])}, local_plot
|
39 |
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
It also provides a SHAP visualization to show how each factor influences the prediction.
|
45 |
-
"""
|
46 |
-
|
47 |
-
description2 = """
|
48 |
-
To use the app, click on one of the examples, or adjust the values of the six employee satisfaction factors, and click on Analyze. โจ
|
49 |
-
"""
|
50 |
|
51 |
-
with gr.Blocks(title=title) as demo:
|
52 |
-
gr.Markdown(f"## {title}")
|
53 |
-
# gr.Markdown("""""")
|
54 |
-
gr.Markdown(description1)
|
55 |
-
gr.Markdown("""---""")
|
56 |
-
gr.Markdown(description2)
|
57 |
-
gr.Markdown("""---""")
|
58 |
with gr.Row():
|
59 |
with gr.Column():
|
60 |
-
GM3 = gr.Slider(label="My General Manager is an effective leader", minimum=1, maximum=5, value=4, step=0.1)
|
61 |
-
WorkEnv3 = gr.Slider(label="My Work Environment is comfortable and welcoming", minimum=1, maximum=5, value=4, step=0.1)
|
62 |
-
WellBeing2 = gr.Slider(label="I feel balanced and healthy", minimum=1, maximum=5, value=4, step=0.1)
|
63 |
-
GM2 = gr.Slider(label="My General Manager uses feedback from Team Members
|
64 |
-
JobSecurity = gr.Slider(label="Job Security", minimum=1, maximum=5, value=4, step=0.1)
|
65 |
-
WellBeing1 = gr.Slider(label="My mental health is good", minimum=1, maximum=5, value=4, step=0.1)
|
66 |
-
submit_btn = gr.Button("Analyze")
|
67 |
-
|
68 |
-
with gr.Column(visible=True, scale=1, min_width=600) as output_col:
|
69 |
-
label = gr.Label(label="Predicted Intent")
|
70 |
-
local_plot = gr.Plot(label='SHAP Analysis')
|
71 |
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
[label, local_plot], api_name="IntentToStay_Predictor"
|
76 |
-
)
|
77 |
-
|
78 |
-
gr.Markdown("### Example Predictions:")
|
79 |
|
80 |
-
#
|
81 |
-
gr.Markdown(""
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
| ๐ด **At Risk** | 4.0 | 4.0 | 4.0 | 4.0 | 5.0 | 5.0 |
|
87 |
-
""")
|
88 |
|
89 |
-
#
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
[4, 4, 4, 4, 5, 5] # At Risk
|
95 |
-
],
|
96 |
-
inputs=[GM3, WorkEnv3, WellBeing2, GM2, JobSecurity, WellBeing1],
|
97 |
-
outputs=[label, local_plot],
|
98 |
-
fn=main_func,
|
99 |
-
cache_examples=True
|
100 |
)
|
101 |
|
102 |
-
#
|
103 |
-
|
104 |
-
<style>
|
105 |
-
body {
|
106 |
-
background-image: url('https://www.hilton.com/im/en/NoHotel/22512376/hhr-brand-tile-0125.jpg?impolicy=crop&cw=4500&ch=3000&gravity=NorthWest&xposition=0&yposition=0&rw=1280&rh=854');
|
107 |
-
background-size: cover;
|
108 |
-
background-position: center;
|
109 |
-
}
|
110 |
-
</style>
|
111 |
-
""")
|
112 |
|
113 |
demo.launch()
|
|
|
12 |
# Setup SHAP
|
13 |
explainer = shap.Explainer(loaded_model) # PLEASE DO NOT CHANGE THIS.
|
14 |
|
15 |
+
example_options = {
|
16 |
+
"๐ข Well Engaged": [4.5, 4.5, 4.6, 4.7, 5, 4.9],
|
17 |
+
"๐ก Marginal": [5, 4, 5, 4, 4, 4],
|
18 |
+
"๐ด At Risk": [4, 4, 4, 4, 5, 5]
|
19 |
+
}
|
20 |
+
|
21 |
+
# Function to apply the example values
|
22 |
+
def fill_example(example_label):
|
23 |
+
return example_options[example_label]
|
24 |
+
|
25 |
# Create the main function for server
|
26 |
def main_func(GM3, WorkEnv3, WellBeing2, GM2, JobSecurity, WellBeing1):
|
27 |
new_row = pd.DataFrame.from_dict({
|
|
|
47 |
|
48 |
return {"Leave": float(prob[0][0]), "Stay": 1-float(prob[0][0])}, local_plot
|
49 |
|
50 |
+
with gr.Blocks(title="๐ Intent to Stay Prediction") as demo:
|
51 |
+
gr.Markdown("# ๐ Employee Retention Predictor")
|
52 |
+
gr.Markdown("Predict if an employee will **Stay** or **Leave** based on key workplace factors.")
|
53 |
+
gr.Markdown("---")
|
|
|
|
|
|
|
|
|
|
|
|
|
54 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
55 |
with gr.Row():
|
56 |
with gr.Column():
|
57 |
+
GM3 = gr.Slider(label="๐จโ๐ผ My General Manager is an effective leader", minimum=1, maximum=5, value=4, step=0.1)
|
58 |
+
WorkEnv3 = gr.Slider(label="๐ข My Work Environment is comfortable and welcoming", minimum=1, maximum=5, value=4, step=0.1)
|
59 |
+
WellBeing2 = gr.Slider(label="๐ I feel balanced and healthy", minimum=1, maximum=5, value=4, step=0.1)
|
60 |
+
GM2 = gr.Slider(label="๐ My General Manager uses feedback from Team Members", minimum=1, maximum=5, value=4, step=0.1)
|
61 |
+
JobSecurity = gr.Slider(label="๐ Job Security", minimum=1, maximum=5, value=4, step=0.1)
|
62 |
+
WellBeing1 = gr.Slider(label="๐ง My mental health is good", minimum=1, maximum=5, value=4, step=0.1)
|
63 |
+
submit_btn = gr.Button("๐ Analyze Now", variant="primary")
|
|
|
|
|
|
|
|
|
64 |
|
65 |
+
with gr.Column():
|
66 |
+
label = gr.Label(label="๐ฎ Prediction Result")
|
67 |
+
local_plot = gr.Plot(label="SHAP Analysis")
|
|
|
|
|
|
|
|
|
68 |
|
69 |
+
# Dropdown for labeled examples
|
70 |
+
gr.Markdown("### ๐ท๏ธ Select an Example:")
|
71 |
+
example_dropdown = gr.Dropdown(
|
72 |
+
label="Choose a scenario",
|
73 |
+
choices=list(example_options.keys())
|
74 |
+
)
|
|
|
|
|
75 |
|
76 |
+
# Apply example values when selected
|
77 |
+
example_dropdown.change(
|
78 |
+
fill_example,
|
79 |
+
inputs=[example_dropdown],
|
80 |
+
outputs=[GM3, WorkEnv3, WellBeing2, GM2, JobSecurity, WellBeing1]
|
|
|
|
|
|
|
|
|
|
|
|
|
81 |
)
|
82 |
|
83 |
+
# Submit button functionality
|
84 |
+
submit_btn.click(main_func, [GM3, WorkEnv3, WellBeing2, GM2, JobSecurity, WellBeing1], [label, local_plot])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
85 |
|
86 |
demo.launch()
|