Update app.py
Browse files
app.py
CHANGED
|
@@ -1,36 +1,57 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
import joblib
|
|
|
|
|
|
|
| 3 |
|
| 4 |
-
# Load
|
| 5 |
-
model = joblib.load("
|
| 6 |
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
return float(score)
|
| 12 |
|
| 13 |
-
#
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
]
|
| 32 |
-
|
| 33 |
-
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 34 |
|
| 35 |
-
if __name__ == "__main__":
|
| 36 |
-
iface.launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
import joblib
|
| 3 |
+
import pandas as pd
|
| 4 |
+
import numpy as np
|
| 5 |
|
| 6 |
+
# Load the trained pipeline
|
| 7 |
+
model = joblib.load("models/model.joblib")
|
| 8 |
|
| 9 |
+
# Load team→specialty mapping from your dataset
|
| 10 |
+
df = pd.read_csv("minimal_messy_task_performance.csv")
|
| 11 |
+
team_specialty = df[['Team','Specialty']].drop_duplicates().set_index('Team')['Specialty'].to_dict()
|
| 12 |
+
teams = list(team_specialty.keys())
|
|
|
|
| 13 |
|
| 14 |
+
# Define the static task context
|
| 15 |
+
new_task_base = {
|
| 16 |
+
'ProductType': 'Mothball',
|
| 17 |
+
'TaskType': 'Packaging',
|
| 18 |
+
'OrderQuantity': 100,
|
| 19 |
+
'DeadlineDays': 3,
|
| 20 |
+
'ExperienceYears': 5,
|
| 21 |
+
'AvgTaskTime_Minutes': 25.4,
|
| 22 |
+
'ErrorRate': 0.05,
|
| 23 |
+
'TrainingHours': 20.0,
|
| 24 |
+
'DayNumber': 2,
|
| 25 |
+
'ThroughputRate': 100 / 25.4,
|
| 26 |
+
'TimePressure': 100 / (3 * 25.4),
|
| 27 |
+
'PriorityLevel': 3
|
| 28 |
+
}
|
| 29 |
+
|
| 30 |
+
def generate_rankings():
|
| 31 |
+
# Build one row per team, filling in Team and Specialty
|
| 32 |
+
rows = []
|
| 33 |
+
for team in teams:
|
| 34 |
+
row = new_task_base.copy()
|
| 35 |
+
row['Team'] = team
|
| 36 |
+
row['Specialty'] = team_specialty[team]
|
| 37 |
+
rows.append(row)
|
| 38 |
+
df_tasks = pd.DataFrame(rows)
|
| 39 |
+
|
| 40 |
+
# Predict productivity for every team
|
| 41 |
+
preds = model.predict(df_tasks)
|
| 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 Ranking for Today's Task")
|
| 52 |
+
btn = gr.Button("Generate Rankings")
|
| 53 |
+
table = gr.Dataframe(headers=["Team", "PredictedProductivity"])
|
| 54 |
+
btn.click(fn=generate_rankings, inputs=None, outputs=table)
|
| 55 |
+
|
| 56 |
+
demo.launch()
|
| 57 |
|
|
|
|
|
|