Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -13,10 +13,15 @@ loaded_model = pickle.load(open("h25Team12_xgb.pkl", 'rb'))
|
|
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 |
|
@@ -35,7 +40,8 @@ def main_func(ValueDiversity,AdequateResources,Voice,GrowthAdvancement,Workload,
|
|
35 |
# Create the UI
|
36 |
title = "**Employee Turnover Predictor & Interpreter** 🪐"
|
37 |
description1 = """
|
38 |
-
This app
|
|
|
39 |
"""
|
40 |
|
41 |
description2 = """
|
@@ -51,26 +57,27 @@ 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")
|
63 |
-
local_plot = gr.Plot(label = 'Shap:')
|
64 |
|
|
|
|
|
|
|
|
|
65 |
submit_btn.click(
|
66 |
main_func,
|
67 |
-
[
|
68 |
-
[label,local_plot], api_name="
|
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()
|
|
|
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({
|
18 |
+
'GM3': GM3,
|
19 |
+
'WorkEnv3': WorkEnv3,
|
20 |
+
'WellBeing2': WellBeing2,
|
21 |
+
'GM2': GM2,
|
22 |
+
'JobSecurity': JobSecurity,
|
23 |
+
'WellBeing1': WellBeing1
|
24 |
+
}, orient='index').transpose()
|
25 |
|
26 |
prob = loaded_model.predict_proba(new_row)
|
27 |
|
|
|
40 |
# Create the UI
|
41 |
title = "**Employee Turnover Predictor & Interpreter** 🪐"
|
42 |
description1 = """
|
43 |
+
This app predicts whether an employee is likely to stay or leave based on selected workplace factors.
|
44 |
+
It also provides a SHAP visualization to show how each factor influences the prediction.
|
45 |
"""
|
46 |
|
47 |
description2 = """
|
|
|
57 |
gr.Markdown("""---""")
|
58 |
with gr.Row():
|
59 |
with gr.Column():
|
60 |
+
GM3 = gr.Slider(label="GM3", minimum=1, maximum=5, value=4, step=0.1)
|
61 |
+
WorkEnv3 = gr.Slider(label="Work Environment 3", minimum=1, maximum=5, value=4, step=0.1)
|
62 |
+
WellBeing2 = gr.Slider(label="Well-Being 2", minimum=1, maximum=5, value=4, step=0.1)
|
63 |
+
GM2 = gr.Slider(label="GM2", minimum=1, maximum=5, value=4, step=0.1)
|
64 |
+
JobSecurity = gr.Slider(label="Job Security", minimum=1, maximum=5, value=4, step=0.1)
|
65 |
+
WellBeing1 = gr.Slider(label="Well-Being 1", 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 |
submit_btn.click(
|
73 |
main_func,
|
74 |
+
[GM3, WorkEnv3, WellBeing2, GM2, JobSecurity, WellBeing1],
|
75 |
+
[label, local_plot], api_name="IntentToStay_Predictor"
|
76 |
)
|
77 |
|
78 |
gr.Markdown("### Click on any of the examples below to see how it works:")
|
79 |
gr.Examples([[4,4,4,4,5,5], [5,4,5,4,4,4]],
|
80 |
+
[GM3, WorkEnv3, WellBeing2, GM2, JobSecurity, WellBeing1],
|
81 |
+
[label, local_plot], main_func, cache_examples=True)
|
82 |
|
83 |
demo.launch()
|