bs3va commited on
Commit
a1d84e4
ยท
verified ยท
1 Parent(s): a5752fb

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +37 -64
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
- # 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 = """
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("""![marketing](types-of-employee-turnover.jpg)""")
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 to make improvements", 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="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
- 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("### Example Predictions:")
79
 
80
- # Add labeled example categories
81
- gr.Markdown("""
82
- | Example Label | GM3 | WorkEnv3 | WellBeing2 | GM2 | JobSecurity | WellBeing1 |
83
- |----------------|-----|---------|------------|----|-------------|------------|
84
- | ๐ŸŸข **Well Engaged** | 4.5 | 4.5 | 4.6 | 4.7 | 5.0 | 4.9 |
85
- | ๐ŸŸก **Marginal** | 5.0 | 4.0 | 5.0 | 4.0 | 4.0 | 4.0 |
86
- | ๐Ÿ”ด **At Risk** | 4.0 | 4.0 | 4.0 | 4.0 | 5.0 | 5.0 |
87
- """)
88
 
89
- # Display interactive examples
90
- gr.Examples(
91
- examples=[
92
- [4.5, 4.5, 4.6, 4.7, 5, 4.9], # Well Engaged
93
- [5, 4, 5, 4, 4, 4], # Marginal
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
- # Add background image using CSS
103
- gr.Markdown("""
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()