Spaces:
Sleeping
Sleeping
Upload main.py with huggingface_hub
Browse files
main.py
CHANGED
|
@@ -43,7 +43,8 @@ app.add_middleware(
|
|
| 43 |
VALID_TASKS = [
|
| 44 |
"easy_dedup_rename",
|
| 45 |
"medium_missing_dtype",
|
| 46 |
-
"hard_full_pipeline"
|
|
|
|
| 47 |
]
|
| 48 |
|
| 49 |
envs: Dict[str, DataCleaningEnv] = {
|
|
@@ -135,6 +136,21 @@ def list_tasks():
|
|
| 135 |
"remove_duplicates", "fill_missing", "fix_dtype",
|
| 136 |
"remove_outliers", "validate_schema", "finish"
|
| 137 |
]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 138 |
}
|
| 139 |
]
|
| 140 |
}
|
|
@@ -231,3 +247,75 @@ def validate():
|
|
| 231 |
"openenv_valid": all_passed,
|
| 232 |
"tasks": results
|
| 233 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 43 |
VALID_TASKS = [
|
| 44 |
"easy_dedup_rename",
|
| 45 |
"medium_missing_dtype",
|
| 46 |
+
"hard_full_pipeline",
|
| 47 |
+
"expert_sales_pipeline"
|
| 48 |
]
|
| 49 |
|
| 50 |
envs: Dict[str, DataCleaningEnv] = {
|
|
|
|
| 136 |
"remove_duplicates", "fill_missing", "fix_dtype",
|
| 137 |
"remove_outliers", "validate_schema", "finish"
|
| 138 |
]
|
| 139 |
+
},
|
| 140 |
+
{
|
| 141 |
+
"task_id": "expert_sales_pipeline",
|
| 142 |
+
"difficulty": "expert",
|
| 143 |
+
"description": (
|
| 144 |
+
"Expert level: Full sales data cleaning pipeline "
|
| 145 |
+
"requiring correct order of operations including "
|
| 146 |
+
"case standardization, outlier removal, and schema validation."
|
| 147 |
+
),
|
| 148 |
+
"max_steps": 25,
|
| 149 |
+
"operations": [
|
| 150 |
+
"remove_duplicates", "fill_missing", "fix_dtype",
|
| 151 |
+
"remove_outliers", "rename_columns",
|
| 152 |
+
"validate_schema", "finish"
|
| 153 |
+
]
|
| 154 |
}
|
| 155 |
]
|
| 156 |
}
|
|
|
|
| 247 |
"openenv_valid": all_passed,
|
| 248 |
"tasks": results
|
| 249 |
}
|
| 250 |
+
|
| 251 |
+
|
| 252 |
+
# In memory leaderboard
|
| 253 |
+
leaderboard_data = []
|
| 254 |
+
|
| 255 |
+
@app.post("/leaderboard/submit")
|
| 256 |
+
def submit_score(entry: Dict[str, Any]):
|
| 257 |
+
"""Submit a score to the leaderboard."""
|
| 258 |
+
required = ["model_name", "task_id", "score"]
|
| 259 |
+
for field in required:
|
| 260 |
+
if field not in entry:
|
| 261 |
+
raise HTTPException(
|
| 262 |
+
status_code=400,
|
| 263 |
+
detail=f"Missing field: {field}"
|
| 264 |
+
)
|
| 265 |
+
if not 0.0 <= float(entry["score"]) <= 1.0:
|
| 266 |
+
raise HTTPException(
|
| 267 |
+
status_code=400,
|
| 268 |
+
detail="Score must be between 0.0 and 1.0"
|
| 269 |
+
)
|
| 270 |
+
leaderboard_data.append({
|
| 271 |
+
"model_name": entry["model_name"],
|
| 272 |
+
"task_id": entry["task_id"],
|
| 273 |
+
"score": round(float(entry["score"]), 4),
|
| 274 |
+
"steps": entry.get("steps", 0),
|
| 275 |
+
"timestamp": __import__("datetime").datetime.utcnow().isoformat()
|
| 276 |
+
})
|
| 277 |
+
return {"status": "submitted", "entry": leaderboard_data[-1]}
|
| 278 |
+
|
| 279 |
+
|
| 280 |
+
@app.get("/leaderboard")
|
| 281 |
+
def get_leaderboard():
|
| 282 |
+
"""Get current leaderboard rankings."""
|
| 283 |
+
if not leaderboard_data:
|
| 284 |
+
# Return baseline scores
|
| 285 |
+
return {
|
| 286 |
+
"leaderboard": [
|
| 287 |
+
{
|
| 288 |
+
"rank": 1,
|
| 289 |
+
"model_name": "gpt-4o-mini (baseline)",
|
| 290 |
+
"easy_score": 1.0000,
|
| 291 |
+
"medium_score": 0.6643,
|
| 292 |
+
"hard_score": 0.8386,
|
| 293 |
+
"avg_score": 0.8343
|
| 294 |
+
}
|
| 295 |
+
],
|
| 296 |
+
"total_submissions": 1
|
| 297 |
+
}
|
| 298 |
+
|
| 299 |
+
# Group by model
|
| 300 |
+
from collections import defaultdict
|
| 301 |
+
model_scores = defaultdict(dict)
|
| 302 |
+
for entry in leaderboard_data:
|
| 303 |
+
model_scores[entry["model_name"]][entry["task_id"]] = entry["score"]
|
| 304 |
+
|
| 305 |
+
ranked = []
|
| 306 |
+
for model, scores in model_scores.items():
|
| 307 |
+
avg = sum(scores.values()) / len(scores) if scores else 0
|
| 308 |
+
ranked.append({
|
| 309 |
+
"model_name": model,
|
| 310 |
+
"scores": scores,
|
| 311 |
+
"avg_score": round(avg, 4)
|
| 312 |
+
})
|
| 313 |
+
|
| 314 |
+
ranked.sort(key=lambda x: x["avg_score"], reverse=True)
|
| 315 |
+
for i, r in enumerate(ranked):
|
| 316 |
+
r["rank"] = i + 1
|
| 317 |
+
|
| 318 |
+
return {
|
| 319 |
+
"leaderboard": ranked,
|
| 320 |
+
"total_submissions": len(leaderboard_data)
|
| 321 |
+
}
|