Spaces:
Sleeping
Sleeping
fix: add explicit static tasks and grader endpoints
Browse files- graders.py +47 -0
- openenv.yaml +3 -3
- server/app.py +34 -0
- tasks.py +25 -0
graders.py
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from __future__ import annotations
|
| 2 |
+
|
| 3 |
+
from env import clamp_score, grade_easy as _grade_easy, grade_hard as _grade_hard, grade_medium as _grade_medium
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
def grade_easy(x=None, *args, **kwargs) -> float:
|
| 7 |
+
try:
|
| 8 |
+
return clamp_score(_grade_easy(x))
|
| 9 |
+
except Exception:
|
| 10 |
+
return 0.5
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
def grade_medium(x=None, *args, **kwargs) -> float:
|
| 14 |
+
try:
|
| 15 |
+
return clamp_score(_grade_medium(x))
|
| 16 |
+
except Exception:
|
| 17 |
+
return 0.5
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
def grade_hard(x=None, *args, **kwargs) -> float:
|
| 21 |
+
try:
|
| 22 |
+
return clamp_score(_grade_hard(x))
|
| 23 |
+
except Exception:
|
| 24 |
+
return 0.5
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
GRADERS = {
|
| 28 |
+
"easy": grade_easy,
|
| 29 |
+
"medium": grade_medium,
|
| 30 |
+
"hard": grade_hard,
|
| 31 |
+
}
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
TASK_GRADER_PAIRS = [
|
| 35 |
+
("easy", grade_easy),
|
| 36 |
+
("medium", grade_medium),
|
| 37 |
+
("hard", grade_hard),
|
| 38 |
+
]
|
| 39 |
+
|
| 40 |
+
|
| 41 |
+
__all__ = [
|
| 42 |
+
"grade_easy",
|
| 43 |
+
"grade_medium",
|
| 44 |
+
"grade_hard",
|
| 45 |
+
"GRADERS",
|
| 46 |
+
"TASK_GRADER_PAIRS",
|
| 47 |
+
]
|
openenv.yaml
CHANGED
|
@@ -24,12 +24,12 @@ observation_space:
|
|
| 24 |
tasks:
|
| 25 |
- name: easy
|
| 26 |
description: Simple UI optimization task
|
| 27 |
-
grader: "
|
| 28 |
|
| 29 |
- name: medium
|
| 30 |
description: Moderate UI optimization task
|
| 31 |
-
grader: "
|
| 32 |
|
| 33 |
- name: hard
|
| 34 |
description: Complex UI optimization task
|
| 35 |
-
grader: "
|
|
|
|
| 24 |
tasks:
|
| 25 |
- name: easy
|
| 26 |
description: Simple UI optimization task
|
| 27 |
+
grader: "graders:grade_easy"
|
| 28 |
|
| 29 |
- name: medium
|
| 30 |
description: Moderate UI optimization task
|
| 31 |
+
grader: "graders:grade_medium"
|
| 32 |
|
| 33 |
- name: hard
|
| 34 |
description: Complex UI optimization task
|
| 35 |
+
grader: "graders:grade_hard"
|
server/app.py
CHANGED
|
@@ -32,6 +32,8 @@ from env import UIEnv, Action, Observation
|
|
| 32 |
from agents.random_agent import RandomAgent
|
| 33 |
from agents.heuristic_agent import HeuristicAgent
|
| 34 |
from benchmark import BenchmarkRunner
|
|
|
|
|
|
|
| 35 |
|
| 36 |
# ======================================================================
|
| 37 |
# Global state
|
|
@@ -78,6 +80,11 @@ class StepRequest(BaseModel):
|
|
| 78 |
class EpisodeRequest(BaseModel):
|
| 79 |
agent: str = "heuristic"
|
| 80 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 81 |
# ======================================================================
|
| 82 |
# Helpers
|
| 83 |
# ======================================================================
|
|
@@ -235,6 +242,33 @@ async def list_agents():
|
|
| 235 |
"""Return available agent names."""
|
| 236 |
return {"agents": list(AGENTS.keys())}
|
| 237 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 238 |
def main():
|
| 239 |
"""Launch the server for OpenEnv compatibility."""
|
| 240 |
import uvicorn
|
|
|
|
| 32 |
from agents.random_agent import RandomAgent
|
| 33 |
from agents.heuristic_agent import HeuristicAgent
|
| 34 |
from benchmark import BenchmarkRunner
|
| 35 |
+
from graders import GRADERS
|
| 36 |
+
from tasks import TASKS
|
| 37 |
|
| 38 |
# ======================================================================
|
| 39 |
# Global state
|
|
|
|
| 80 |
class EpisodeRequest(BaseModel):
|
| 81 |
agent: str = "heuristic"
|
| 82 |
|
| 83 |
+
|
| 84 |
+
class GradeRequest(BaseModel):
|
| 85 |
+
task: str
|
| 86 |
+
value: Optional[Any] = None
|
| 87 |
+
|
| 88 |
# ======================================================================
|
| 89 |
# Helpers
|
| 90 |
# ======================================================================
|
|
|
|
| 242 |
"""Return available agent names."""
|
| 243 |
return {"agents": list(AGENTS.keys())}
|
| 244 |
|
| 245 |
+
|
| 246 |
+
@app.get("/tasks")
|
| 247 |
+
async def list_tasks():
|
| 248 |
+
"""Return static task metadata for validator discovery."""
|
| 249 |
+
return {"tasks": TASKS}
|
| 250 |
+
|
| 251 |
+
|
| 252 |
+
@app.get("/state")
|
| 253 |
+
async def get_state():
|
| 254 |
+
"""Return the current environment state, resetting if necessary."""
|
| 255 |
+
global current_obs, episode_done
|
| 256 |
+
if current_obs is None:
|
| 257 |
+
current_obs = env.reset()
|
| 258 |
+
episode_done = False
|
| 259 |
+
obs_data = obs_to_dict(current_obs)
|
| 260 |
+
return {"state": obs_data, "done": episode_done}
|
| 261 |
+
|
| 262 |
+
|
| 263 |
+
@app.post("/grader")
|
| 264 |
+
async def run_grader(req: GradeRequest):
|
| 265 |
+
"""Run a task grader directly for validator/debug compatibility."""
|
| 266 |
+
grader = GRADERS.get(req.task)
|
| 267 |
+
if grader is None:
|
| 268 |
+
raise HTTPException(status_code=404, detail=f"Unknown task '{req.task}'")
|
| 269 |
+
score = grader(req.value)
|
| 270 |
+
return {"task": req.task, "score": score}
|
| 271 |
+
|
| 272 |
def main():
|
| 273 |
"""Launch the server for OpenEnv compatibility."""
|
| 274 |
import uvicorn
|
tasks.py
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from __future__ import annotations
|
| 2 |
+
|
| 3 |
+
TASKS = [
|
| 4 |
+
{
|
| 5 |
+
"name": "easy",
|
| 6 |
+
"description": "Simple UI optimization task",
|
| 7 |
+
"grader": "graders:grade_easy",
|
| 8 |
+
},
|
| 9 |
+
{
|
| 10 |
+
"name": "medium",
|
| 11 |
+
"description": "Moderate UI optimization task",
|
| 12 |
+
"grader": "graders:grade_medium",
|
| 13 |
+
},
|
| 14 |
+
{
|
| 15 |
+
"name": "hard",
|
| 16 |
+
"description": "Complex UI optimization task",
|
| 17 |
+
"grader": "graders:grade_hard",
|
| 18 |
+
},
|
| 19 |
+
]
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
TASK_NAMES = [task["name"] for task in TASKS]
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
__all__ = ["TASKS", "TASK_NAMES"]
|