Mpodszus commited on
Commit
ccb396a
·
verified ·
1 Parent(s): f22bada

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -15
app.py CHANGED
@@ -18,10 +18,10 @@ def safe_convert(value, default, min_val, max_val):
18
  except (TypeError, ValueError):
19
  return default # Use default if conversion fails
20
 
21
- # Create the main function for server
22
  def main_func(Department, ChainScale, SupportiveGM, Merit, LearningDevelopment, WorkEnvironment, Engagement, WellBeing):
23
 
24
- # ChainScale mapping
25
  ChainScale_mapping = {
26
  'Luxury': 1,
27
  'Upper Midscale': 2,
@@ -29,10 +29,7 @@ def main_func(Department, ChainScale, SupportiveGM, Merit, LearningDevelopment,
29
  'Upscale': 4,
30
  'Independent': 5,
31
  }
32
- default_ChainScale = 4
33
- ChainScale_value = ChainScale_mapping.get(ChainScale, default_ChainScale)
34
-
35
- # Department mapping
36
  department_mapping = {
37
  "Guest Services": 1,
38
  "Food and Beverage": 2,
@@ -40,9 +37,8 @@ def main_func(Department, ChainScale, SupportiveGM, Merit, LearningDevelopment,
40
  "Front Office Operations": 4,
41
  "Guest Activities": 5,
42
  }
43
- default_department = 5
44
- department_value = department_mapping.get(Department, default_department)
45
 
 
46
  LearningDevelopment = safe_convert(LearningDevelopment, 3.0, 1, 5)
47
  SupportiveGM = safe_convert(SupportiveGM, 3.0, 1, 5)
48
  Merit = safe_convert(Merit, 3.0, 1, 5)
@@ -50,9 +46,8 @@ def main_func(Department, ChainScale, SupportiveGM, Merit, LearningDevelopment,
50
  Engagement = safe_convert(Engagement, 3.0, 1, 5)
51
  WellBeing = safe_convert(WellBeing, 3.0, 1, 5)
52
 
 
53
  new_row = pd.DataFrame({
54
- 'Department': [int(department_value)],
55
- 'ChainScale': [int(ChainScale_value)],
56
  'SupportiveGM': [SupportiveGM],
57
  'Merit': [Merit],
58
  'LearningDevelopment': [LearningDevelopment],
@@ -61,9 +56,9 @@ def main_func(Department, ChainScale, SupportiveGM, Merit, LearningDevelopment,
61
  'WellBeing': [WellBeing]
62
  }).astype(float)
63
 
 
64
  prob = loaded_model.predict_proba(new_row)
65
 
66
- # Ensure probabilities return correctly
67
  if prob.shape[1] == 2:
68
  leave_prob = float(prob[0][0])
69
  stay_prob = float(prob[0][1])
@@ -71,6 +66,7 @@ def main_func(Department, ChainScale, SupportiveGM, Merit, LearningDevelopment,
71
  leave_prob = float(prob[0])
72
  stay_prob = 1 - leave_prob
73
 
 
74
  shap_values = explainer(new_row)
75
 
76
  fig, ax = plt.subplots(figsize=(8, 4))
@@ -88,7 +84,7 @@ def main_func(Department, ChainScale, SupportiveGM, Merit, LearningDevelopment,
88
  # Create the UI
89
  title = "**Mod 3 Team 5: Employee Turnover Predictor & Interpreter**"
90
  description1 = """
91
- This app predicts whether an employee intends to stay or leave based on satisfaction factors and department.
92
  """
93
 
94
  description2 = """
@@ -106,12 +102,12 @@ with gr.Blocks(title=title) as demo:
106
  with gr.Column():
107
  Department = gr.Radio(
108
  ["Guest Services", "Food and Beverage", "Housekeeping", "Front Office Operations", "Guest Activities"],
109
- label="Department",
110
  value="Guest Services"
111
  )
112
  ChainScale = gr.Dropdown(
113
  ["Luxury", "Upper Midscale", "Upper Upscale", "Upscale", "Independent"],
114
- label="ChainScale",
115
  value="Upper Upscale"
116
  )
117
  SupportiveGM = gr.Slider(
@@ -166,4 +162,3 @@ with gr.Blocks(title=title) as demo:
166
  )
167
 
168
  demo.launch()
169
-
 
18
  except (TypeError, ValueError):
19
  return default # Use default if conversion fails
20
 
21
+ # Create the main function for the model
22
  def main_func(Department, ChainScale, SupportiveGM, Merit, LearningDevelopment, WorkEnvironment, Engagement, WellBeing):
23
 
24
+ # These mappings are EXAMPLES only, not used in the model
25
  ChainScale_mapping = {
26
  'Luxury': 1,
27
  'Upper Midscale': 2,
 
29
  'Upscale': 4,
30
  'Independent': 5,
31
  }
32
+
 
 
 
33
  department_mapping = {
34
  "Guest Services": 1,
35
  "Food and Beverage": 2,
 
37
  "Front Office Operations": 4,
38
  "Guest Activities": 5,
39
  }
 
 
40
 
41
+ # Convert inputs to safe numeric values
42
  LearningDevelopment = safe_convert(LearningDevelopment, 3.0, 1, 5)
43
  SupportiveGM = safe_convert(SupportiveGM, 3.0, 1, 5)
44
  Merit = safe_convert(Merit, 3.0, 1, 5)
 
46
  Engagement = safe_convert(Engagement, 3.0, 1, 5)
47
  WellBeing = safe_convert(WellBeing, 3.0, 1, 5)
48
 
49
+ # Only include model-relevant features
50
  new_row = pd.DataFrame({
 
 
51
  'SupportiveGM': [SupportiveGM],
52
  'Merit': [Merit],
53
  'LearningDevelopment': [LearningDevelopment],
 
56
  'WellBeing': [WellBeing]
57
  }).astype(float)
58
 
59
+ # Predict probabilities
60
  prob = loaded_model.predict_proba(new_row)
61
 
 
62
  if prob.shape[1] == 2:
63
  leave_prob = float(prob[0][0])
64
  stay_prob = float(prob[0][1])
 
66
  leave_prob = float(prob[0])
67
  stay_prob = 1 - leave_prob
68
 
69
+ # Generate SHAP values
70
  shap_values = explainer(new_row)
71
 
72
  fig, ax = plt.subplots(figsize=(8, 4))
 
84
  # Create the UI
85
  title = "**Mod 3 Team 5: Employee Turnover Predictor & Interpreter**"
86
  description1 = """
87
+ This app predicts whether an employee intends to stay or leave based on satisfaction factors.
88
  """
89
 
90
  description2 = """
 
102
  with gr.Column():
103
  Department = gr.Radio(
104
  ["Guest Services", "Food and Beverage", "Housekeeping", "Front Office Operations", "Guest Activities"],
105
+ label="Department (Example Only)",
106
  value="Guest Services"
107
  )
108
  ChainScale = gr.Dropdown(
109
  ["Luxury", "Upper Midscale", "Upper Upscale", "Upscale", "Independent"],
110
+ label="ChainScale (Example Only)",
111
  value="Upper Upscale"
112
  )
113
  SupportiveGM = gr.Slider(
 
162
  )
163
 
164
  demo.launch()