Update app.py
Browse files
app.py
CHANGED
|
@@ -3,55 +3,83 @@ import joblib
|
|
| 3 |
import pandas as pd
|
| 4 |
import numpy as np
|
| 5 |
|
| 6 |
-
# Load
|
| 7 |
model = joblib.load("model.joblib")
|
| 8 |
|
| 9 |
-
# 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 |
-
# Define
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 28 |
}
|
| 29 |
|
| 30 |
-
def generate_rankings():
|
| 31 |
-
|
| 32 |
rows = []
|
| 33 |
for team in teams:
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
rows.append(
|
| 38 |
df_tasks = pd.DataFrame(rows)
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
df_tasks['PredictedProductivity'] = np.round(preds, 2)
|
| 43 |
-
|
| 44 |
-
# Return a sorted DataFrame
|
| 45 |
-
return df_tasks[['Team', 'PredictedProductivity']].sort_values(
|
| 46 |
-
'PredictedProductivity', ascending=False
|
| 47 |
).reset_index(drop=True)
|
| 48 |
|
| 49 |
-
# Gradio interface: single button → ranked table
|
| 50 |
with gr.Blocks() as demo:
|
| 51 |
-
gr.Markdown("## Team Productivity
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 52 |
btn = gr.Button("Generate Rankings")
|
| 53 |
-
table = gr.Dataframe(headers=["Team", "
|
| 54 |
-
btn.click(fn=generate_rankings, inputs=
|
| 55 |
-
|
| 56 |
-
demo.launch()
|
| 57 |
|
|
|
|
|
|
| 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()
|