Update app.py
Browse files
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 |
-
#
|
| 7 |
model = joblib.load("model.joblib")
|
| 8 |
|
| 9 |
-
#
|
| 10 |
-
|
| 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 |
-
'
|
| 32 |
-
'
|
| 33 |
-
'
|
| 34 |
-
'
|
| 35 |
-
'
|
| 36 |
-
'
|
| 37 |
-
'
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
'
|
| 41 |
-
'
|
| 42 |
-
'
|
|
|
|
|
|
|
|
|
|
|
|
|
| 43 |
},
|
| 44 |
"Candle → QualityCheck": {
|
| 45 |
-
'
|
| 46 |
-
'
|
| 47 |
-
'
|
| 48 |
-
'
|
| 49 |
-
'
|
| 50 |
-
'
|
| 51 |
-
'
|
| 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 |
-
|
| 61 |
-
|
| 62 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 63 |
for team in teams:
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 73 |
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
|
|
|
| 84 |
|
| 85 |
-
|
|
|
|
|
|
| 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()
|