bs3va commited on
Commit
83e82c8
·
verified ·
1 Parent(s): 9d6622c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -18
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(ValueDiversity,AdequateResources,Voice,GrowthAdvancement,Workload,WorkLifeBalance):
17
- new_row = pd.DataFrame.from_dict({'ValueDiversity':ValueDiversity,'AdequateResources':AdequateResources,
18
- 'Voice':Voice,'GrowthAdvancement':GrowthAdvancement,'Workload':Workload,
19
- 'WorkLifeBalance':WorkLifeBalance}, orient = 'index').transpose()
 
 
 
 
 
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 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
  """
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
- ValueDiversity = gr.Slider(label="ValueDiversity Score", minimum=1, maximum=5, value=4, step=.1)
55
- AdequateResources = gr.Slider(label="AdequateResources Score", minimum=1, maximum=5, value=4, step=.1)
56
- Voice = gr.Slider(label="Voice Score", minimum=1, maximum=5, value=4, step=.1)
57
- GrowthAdvancement = gr.Slider(label="GrowthAdvancement Score", minimum=1, maximum=5, value=4, step=.1)
58
- Workload = gr.Slider(label="Workload Score", minimum=1, maximum=5, value=4, step=.1)
59
- WorkLifeBalance = gr.Slider(label="WorkLifeBalance 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")
63
- local_plot = gr.Plot(label = 'Shap:')
64
 
 
 
 
 
65
  submit_btn.click(
66
  main_func,
67
- [ValueDiversity,AdequateResources,Voice,GrowthAdvancement,Workload,WorkLifeBalance],
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
- [ValueDiversity,AdequateResources,Voice,GrowthAdvancement,Workload,WorkLifeBalance],
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()