nodronm commited on
Commit
5b97424
·
verified ·
1 Parent(s): e52f116

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +67 -70
app.py CHANGED
@@ -1,85 +1,82 @@
1
  import gradio as gr
2
- import joblib
3
  import pandas as pd
4
  import numpy as np
 
 
5
 
6
- # 1) Load your trained pipeline
7
  model = joblib.load("model.joblib")
8
 
9
- # 2) Load team→specialty mapping
10
- df = pd.read_csv("dataset.csv")
11
- team_specialty = df[['Team','Specialty']].drop_duplicates().set_index('Team')['Specialty'].to_dict()
12
- teams = list(team_specialty.keys())
13
-
14
- # 3) Define several example task scenarios
15
- SCENARIOS = {
16
- "Mothball → Packaging": {
17
- 'ProductType': 'Mothball',
18
- 'TaskType': 'Packaging',
19
- 'OrderQuantity': 100,
20
- 'DeadlineDays': 3,
21
- 'ExperienceYears': 5,
22
- 'AvgTaskTime_Minutes': 25.4,
23
- 'ErrorRate': 0.05,
24
- 'TrainingHours': 20.0,
25
- 'DayNumber': 2,
26
- 'ThroughputRate': 100 / 25.4,
27
- 'TimePressure': 100 / (3 * 25.4),
28
- 'PriorityLevel': 3
29
- },
30
  "Soap → Molding": {
31
- 'ProductType': 'Soap',
32
- 'TaskType': 'Molding',
33
- 'OrderQuantity': 250,
34
- 'DeadlineDays': 5,
35
- 'ExperienceYears': 4,
36
- 'AvgTaskTime_Minutes': 40.0,
37
- 'ErrorRate': 0.10,
38
- 'TrainingHours': 15.0,
39
- 'DayNumber': 1,
40
- 'ThroughputRate': 250 / 40.0,
41
- 'TimePressure': 250 / (5 * 40.0),
42
- 'PriorityLevel': 2
 
 
 
 
43
  },
44
  "Candle → QualityCheck": {
45
- 'ProductType': 'Candle',
46
- 'TaskType': 'QualityCheck',
47
- 'OrderQuantity': 150,
48
- 'DeadlineDays': 2,
49
- 'ExperienceYears': 6,
50
- 'AvgTaskTime_Minutes': 20.0,
51
- 'ErrorRate': 0.02,
52
- 'TrainingHours': 30.0,
53
- 'DayNumber': 3,
54
- 'ThroughputRate': 150 / 20.0,
55
- 'TimePressure': 150 / (2 * 20.0),
56
- 'PriorityLevel': 3
57
  }
58
  }
59
 
60
- def generate_rankings(scenario_name):
61
- base = SCENARIOS[scenario_name]
62
- rows = []
 
 
 
 
 
63
  for team in teams:
64
- r = base.copy()
65
- r['Team'] = team
66
- r['Specialty'] = team_specialty[team]
67
- rows.append(r)
68
- df_tasks = pd.DataFrame(rows)
69
- df_tasks['PredictedProd'] = np.round(model.predict(df_tasks), 2)
70
- return df_tasks[['Team', 'PredictedProd']].sort_values(
71
- 'PredictedProd', ascending=False
72
- ).reset_index(drop=True)
 
 
 
 
 
 
 
 
 
73
 
74
- with gr.Blocks() as demo:
75
- gr.Markdown("## 🚀 Team Productivity Rankings")
76
- scenario = gr.Dropdown(
77
- choices=list(SCENARIOS.keys()),
78
- label="Select a task scenario",
79
- value=list(SCENARIOS.keys())[0]
80
- )
81
- btn = gr.Button("Generate Rankings")
82
- table = gr.Dataframe(headers=["Team", "PredictedProd"])
83
- btn.click(fn=generate_rankings, inputs=scenario, outputs=table)
 
84
 
85
- demo.launch()
 
 
1
  import gradio as gr
 
2
  import pandas as pd
3
  import numpy as np
4
+ import matplotlib.pyplot as plt
5
+ import joblib
6
 
7
+ # Load model
8
  model = joblib.load("model.joblib")
9
 
10
+ # Define example tasks
11
+ example_tasks = {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
12
  "Soap → Molding": {
13
+ 'quarter': 'Q2', 'department': 'sewing', 'day': 'Monday',
14
+ 'no_of_workers': 48, 'incentive': 2.5, 'idle_time': 0.3,
15
+ 'idle_men': 4, 'smv': 30.0, 'month': 5, 'day_of_week': 0,
16
+ 'is_weekend': 0, 'smv_per_worker': 30.0/48,
17
+ 'effort_index': 30.0 + 2.5 + 1.0 - 0.3,
18
+ 'log_wip': np.log1p(50), 'log_overtime': np.log1p(1.0),
19
+ 'no_of_style_change': 0, 'targeted_productivity': 0.75
20
+ },
21
+ "Mothball → Packaging": {
22
+ 'quarter': 'Q3', 'department': 'finishing', 'day': 'Wednesday',
23
+ 'no_of_workers': 60, 'incentive': 3.0, 'idle_time': 0.5,
24
+ 'idle_men': 6, 'smv': 25.0, 'month': 7, 'day_of_week': 2,
25
+ 'is_weekend': 0, 'smv_per_worker': 25.0/60,
26
+ 'effort_index': 25.0 + 3.0 + 1.0 - 0.5,
27
+ 'log_wip': np.log1p(40), 'log_overtime': np.log1p(2.0),
28
+ 'no_of_style_change': 1, 'targeted_productivity': 0.68
29
  },
30
  "Candle → QualityCheck": {
31
+ 'quarter': 'Q1', 'department': 'quality', 'day': 'Friday',
32
+ 'no_of_workers': 42, 'incentive': 1.5, 'idle_time': 0.1,
33
+ 'idle_men': 2, 'smv': 20.0, 'month': 3, 'day_of_week': 4,
34
+ 'is_weekend': 0, 'smv_per_worker': 20.0/42,
35
+ 'effort_index': 20.0 + 1.5 + 1.0 - 0.1,
36
+ 'log_wip': np.log1p(70), 'log_overtime': np.log1p(1.5),
37
+ 'no_of_style_change': 0, 'targeted_productivity': 0.80
 
 
 
 
 
38
  }
39
  }
40
 
41
+ # Define team list
42
+ teams = [f"team_{i}" for i in range(1, 13)]
43
+
44
+ # Prediction function
45
+ def predict_productivity(task_name):
46
+ base = example_tasks[task_name]
47
+ predictions = []
48
+
49
  for team in teams:
50
+ row = base.copy()
51
+ row['Team'] = team
52
+ df_row = pd.DataFrame([row])
53
+ pred = model.predict(df_row)[0]
54
+ predictions.append((team, round(pred, 5)))
55
+
56
+ result_df = pd.DataFrame(predictions, columns=["Team", "Predicted Productivity"])
57
+ result_df = result_df.sort_values(by="Predicted Productivity", ascending=False)
58
+
59
+ # Plot bar chart
60
+ fig, ax = plt.subplots(figsize=(10, 6))
61
+ ax.barh(result_df["Team"], result_df["Predicted Productivity"], color="skyblue")
62
+ ax.set_xlabel("Predicted Productivity")
63
+ ax.set_title(f"Team Ranking for: {task_name}")
64
+ ax.invert_yaxis()
65
+ plt.tight_layout()
66
+
67
+ return result_df, fig
68
 
69
+ # Gradio UI
70
+ demo = gr.Interface(
71
+ fn=predict_productivity,
72
+ inputs=gr.Dropdown(choices=list(example_tasks.keys()), label="Select Task Scenario"),
73
+ outputs=[
74
+ gr.Dataframe(label="🏆 Team Productivity Rankings:"),
75
+ gr.Plot(label="📈 Team Productivity Graph")
76
+ ],
77
+ title="👷 Team Assignment Predictor",
78
+ description="Select a task to predict productivity scores for all teams. The best team will be at the top!"
79
+ )
80
 
81
+ if __name__ == "__main__":
82
+ demo.launch()