Update app.py
Browse files
app.py
CHANGED
@@ -7,16 +7,16 @@ import numpy as np
|
|
7 |
import matplotlib.pyplot as plt
|
8 |
|
9 |
# load the model from disk
|
10 |
-
loaded_model = pickle.load(open("
|
11 |
|
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(
|
17 |
-
new_row = pd.DataFrame.from_dict({'
|
18 |
-
'
|
19 |
-
'
|
20 |
|
21 |
prob = loaded_model.predict_proba(new_row)
|
22 |
|
@@ -33,7 +33,7 @@ def main_func(ValueDiversity,AdequateResources,Voice,GrowthAdvancement,Workload,
|
|
33 |
return {"Leave": float(prob[0][0]), "Stay": 1-float(prob[0][0])}, local_plot
|
34 |
|
35 |
# Create the UI
|
36 |
-
title = "
|
37 |
description1 = """
|
38 |
This app takes six inputs about employees' satisfaction with different aspects of their work (such as work-life balance, ...) and predicts whether the employee intends to stay with the employer or leave. There are two outputs from the app: 1- the predicted probability of stay or leave, 2- Shapley's force-plot which visualizes the extent to which each factor impacts the stay/ leave prediction.
|
39 |
"""
|
@@ -51,12 +51,12 @@ with gr.Blocks(title=title) as demo:
|
|
51 |
gr.Markdown("""---""")
|
52 |
with gr.Row():
|
53 |
with gr.Column():
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
submit_btn = gr.Button("Analyze")
|
61 |
with gr.Column(visible=True,scale=1, min_width=600) as output_col:
|
62 |
label = gr.Label(label = "Predicted Label")
|
@@ -64,13 +64,13 @@ with gr.Blocks(title=title) as demo:
|
|
64 |
|
65 |
submit_btn.click(
|
66 |
main_func,
|
67 |
-
[
|
68 |
[label,local_plot], api_name="Employee_Turnover"
|
69 |
)
|
70 |
|
71 |
gr.Markdown("### Click on any of the examples below to see how it works:")
|
72 |
gr.Examples([[4,4,4,4,5,5], [5,4,5,4,4,4]],
|
73 |
-
[
|
74 |
[label,local_plot], main_func, cache_examples=True)
|
75 |
|
76 |
demo.launch(share=True)
|
|
|
7 |
import matplotlib.pyplot as plt
|
8 |
|
9 |
# load the model from disk
|
10 |
+
loaded_model = pickle.load(open("clf.pkl", 'rb'))
|
11 |
|
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(RewardsBenefit2,JobSatisfaction,RecommendToWork,Tenure,Generation,LearningDevelopment1):
|
17 |
+
new_row = pd.DataFrame.from_dict({'RewardsBenefit2':RewardsBenefit2,'JobSatisfaction':JobSatisfaction,
|
18 |
+
'RecommendToWork':RecommentToWork,'Tenure':Tenure,'Generation':Generation,
|
19 |
+
'LearningDevelopment1':LearningDevelopment1}, orient = 'index').transpose()
|
20 |
|
21 |
prob = loaded_model.predict_proba(new_row)
|
22 |
|
|
|
33 |
return {"Leave": float(prob[0][0]), "Stay": 1-float(prob[0][0])}, local_plot
|
34 |
|
35 |
# Create the UI
|
36 |
+
title = "Worlds Greatest Employee Predictor of Turnover"
|
37 |
description1 = """
|
38 |
This app takes six inputs about employees' satisfaction with different aspects of their work (such as work-life balance, ...) and predicts whether the employee intends to stay with the employer or leave. There are two outputs from the app: 1- the predicted probability of stay or leave, 2- Shapley's force-plot which visualizes the extent to which each factor impacts the stay/ leave prediction.
|
39 |
"""
|
|
|
51 |
gr.Markdown("""---""")
|
52 |
with gr.Row():
|
53 |
with gr.Column():
|
54 |
+
RewardsBenefit2 = gr.Slider(label="Rewards Benefit 2 Score", minimum=1, maximum=5, value=4, step=.1)
|
55 |
+
JobSatisfaction = gr.Slider(label="Job Satisfaction Score", minimum=1, maximum=5, value=4, step=.1)
|
56 |
+
RecommendToWork = gr.Slider(label="Recommend to Work Score", minimum=1, maximum=5, value=4, step=.1)
|
57 |
+
Tenure = gr.Slider(label="Tenure Score", minimum=1, maximum=5, value=4, step=.1)
|
58 |
+
Generation = gr.Slider(label="Generation Score", minimum=1, maximum=5, value=4, step=.1)
|
59 |
+
LearningDevelopment1 = gr.Slider(label="Learning Development Score", minimum=1, maximum=5, value=4, step=.1)
|
60 |
submit_btn = gr.Button("Analyze")
|
61 |
with gr.Column(visible=True,scale=1, min_width=600) as output_col:
|
62 |
label = gr.Label(label = "Predicted Label")
|
|
|
64 |
|
65 |
submit_btn.click(
|
66 |
main_func,
|
67 |
+
[RewardsBenefit2,JobSatisfcation,RecommendToWork,Tenure,Generation,LearningDevelopment1],
|
68 |
[label,local_plot], api_name="Employee_Turnover"
|
69 |
)
|
70 |
|
71 |
gr.Markdown("### Click on any of the examples below to see how it works:")
|
72 |
gr.Examples([[4,4,4,4,5,5], [5,4,5,4,4,4]],
|
73 |
+
[RewardsBenefit2,JobSatisfcation,RecommendToWork,Tenure,Generation,LearningDevelopment1],
|
74 |
[label,local_plot], main_func, cache_examples=True)
|
75 |
|
76 |
demo.launch(share=True)
|