Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -118,8 +118,33 @@ def analyze_productivity(task_completion, stress, satisfaction, support, collabo
|
|
| 118 |
|
| 119 |
return f"Cluster {cluster}: {cluster_description}", tip
|
| 120 |
|
| 121 |
-
|
| 122 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 123 |
|
| 124 |
# Function to save user feedback
|
| 125 |
def save_feedback(tip, feedback):
|
|
|
|
| 118 |
|
| 119 |
return f"Cluster {cluster}: {cluster_description}", tip
|
| 120 |
|
| 121 |
+
def analyze_what_if(what_if_task_completion, what_if_stress, what_if_satisfaction, what_if_support, what_if_collaboration):
|
| 122 |
+
"""
|
| 123 |
+
Analyzes 'what-if' user productivity metrics, predicts a cluster, and generates a tip.
|
| 124 |
+
"""
|
| 125 |
+
user_data = pd.DataFrame([{
|
| 126 |
+
"Task_Completion_Rate": what_if_task_completion,
|
| 127 |
+
"Stress_Level": what_if_stress,
|
| 128 |
+
"Job_Satisfaction": what_if_satisfaction,
|
| 129 |
+
"Manager_Support_Level": what_if_support,
|
| 130 |
+
"Team_Collaboration_Frequency": what_if_collaboration,
|
| 131 |
+
"Work_Life_Balance_Score": 0,
|
| 132 |
+
"Communication_Overhead": 0
|
| 133 |
+
}])
|
| 134 |
+
|
| 135 |
+
# One-hot encode the user input
|
| 136 |
+
user_processed = pd.get_dummies(user_data, columns=["Manager_Support_Level", "Team_Collaboration_Frequency"], drop_first=True)
|
| 137 |
+
user_aligned = user_processed.reindex(columns=df_processed.columns, fill_value=0)
|
| 138 |
+
scaled_input = scaler.transform(user_aligned)
|
| 139 |
+
|
| 140 |
+
# Predict the cluster
|
| 141 |
+
cluster = kmeans.predict(scaled_input)[0]
|
| 142 |
+
cluster_description = cluster_descriptions[cluster]
|
| 143 |
+
|
| 144 |
+
# Generate the tip
|
| 145 |
+
tip = generate_tip(what_if_task_completion, what_if_stress, what_if_satisfaction, what_if_support, what_if_collaboration, cluster_description)
|
| 146 |
+
|
| 147 |
+
return f"Cluster {cluster}: {cluster_description}", tip
|
| 148 |
|
| 149 |
# Function to save user feedback
|
| 150 |
def save_feedback(tip, feedback):
|