nodronm commited on
Commit
041833a
·
verified ·
1 Parent(s): 4006f84

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +52 -31
app.py CHANGED
@@ -1,36 +1,57 @@
1
  import gradio as gr
2
- import joblib, pandas as pd
 
 
3
 
4
- # Load your trained pipeline
5
- model = joblib.load("model.joblib") # or "models/model.joblib"
6
 
7
- def predict(**kwargs):
8
- # Build a single-row DataFrame from named inputs
9
- df = pd.DataFrame([kwargs])
10
- score = model.predict(df)[0]
11
- return float(score)
12
 
13
- # Expose UI controls matching your features
14
- iface = gr.Interface(
15
- fn=predict,
16
- inputs=[
17
- gr.Textbox(label="Team"),
18
- gr.Textbox(label="Specialty"),
19
- gr.Textbox(label="ProductType"),
20
- gr.Textbox(label="TaskType"),
21
- gr.Number(label="OrderQuantity"),
22
- gr.Number(label="DeadlineDays"),
23
- gr.Number(label="ExperienceYears"),
24
- gr.Number(label="AvgTaskTime_Minutes"),
25
- gr.Number(label="ErrorRate"),
26
- gr.Number(label="TrainingHours"),
27
- gr.Number(label="DayNumber"),
28
- gr.Number(label="ThroughputRate"),
29
- gr.Number(label="TimePressure"),
30
- gr.Number(label="PriorityLevel"),
31
- ],
32
- outputs=gr.Number(label="Predicted Productivity")
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