Spaces:
Sleeping
Sleeping
Upload main.py with huggingface_hub
Browse files
main.py
CHANGED
|
@@ -4,9 +4,6 @@ import os
|
|
| 4 |
sys.path.insert(0, os.path.dirname(__file__))
|
| 5 |
|
| 6 |
from fastapi import FastAPI, HTTPException
|
| 7 |
-
from fastapi.staticfiles import StaticFiles
|
| 8 |
-
from fastapi.responses import FileResponse
|
| 9 |
-
import os
|
| 10 |
from fastapi.middleware.cors import CORSMiddleware
|
| 11 |
from typing import Dict, Any
|
| 12 |
from models import Action, StepResult, Reward
|
|
@@ -25,10 +22,6 @@ app = FastAPI(
|
|
| 25 |
version="1.0.0"
|
| 26 |
)
|
| 27 |
|
| 28 |
-
# Serve UI
|
| 29 |
-
os.makedirs("static", exist_ok=True)
|
| 30 |
-
app.mount("/static", StaticFiles(directory="static"), name="static")
|
| 31 |
-
|
| 32 |
app.add_middleware(
|
| 33 |
CORSMiddleware,
|
| 34 |
allow_origins=["*"],
|
|
@@ -43,8 +36,7 @@ app.add_middleware(
|
|
| 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] = {
|
|
@@ -69,10 +61,6 @@ def get_env(task_id: str) -> DataCleaningEnv:
|
|
| 69 |
# ROUTES
|
| 70 |
# βββββββββββββββββββββββββββββββββββββββββ
|
| 71 |
|
| 72 |
-
@app.get("/ui")
|
| 73 |
-
def ui():
|
| 74 |
-
return FileResponse("static/index.html")
|
| 75 |
-
|
| 76 |
@app.get("/")
|
| 77 |
def root():
|
| 78 |
return {
|
|
@@ -136,21 +124,6 @@ def list_tasks():
|
|
| 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,75 +220,3 @@ def validate():
|
|
| 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 |
-
}
|
|
|
|
| 4 |
sys.path.insert(0, os.path.dirname(__file__))
|
| 5 |
|
| 6 |
from fastapi import FastAPI, HTTPException
|
|
|
|
|
|
|
|
|
|
| 7 |
from fastapi.middleware.cors import CORSMiddleware
|
| 8 |
from typing import Dict, Any
|
| 9 |
from models import Action, StepResult, Reward
|
|
|
|
| 22 |
version="1.0.0"
|
| 23 |
)
|
| 24 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
app.add_middleware(
|
| 26 |
CORSMiddleware,
|
| 27 |
allow_origins=["*"],
|
|
|
|
| 36 |
VALID_TASKS = [
|
| 37 |
"easy_dedup_rename",
|
| 38 |
"medium_missing_dtype",
|
| 39 |
+
"hard_full_pipeline"
|
|
|
|
| 40 |
]
|
| 41 |
|
| 42 |
envs: Dict[str, DataCleaningEnv] = {
|
|
|
|
| 61 |
# ROUTES
|
| 62 |
# βββββββββββββββββββββββββββββββββββββββββ
|
| 63 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 64 |
@app.get("/")
|
| 65 |
def root():
|
| 66 |
return {
|
|
|
|
| 124 |
"remove_duplicates", "fill_missing", "fix_dtype",
|
| 125 |
"remove_outliers", "validate_schema", "finish"
|
| 126 |
]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 127 |
}
|
| 128 |
]
|
| 129 |
}
|
|
|
|
| 220 |
"openenv_valid": all_passed,
|
| 221 |
"tasks": results
|
| 222 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|