Spaces:
Sleeping
Sleeping
Commit Β·
99cd67c
1
Parent(s): 6f8436d
fix: expose OpenEnv endpoints on port 7860 to satisfy hackathon validator
Browse files- Dockerfile +2 -2
- backend/app/main.py +45 -1
Dockerfile
CHANGED
|
@@ -45,5 +45,5 @@ EXPOSE 7860
|
|
| 45 |
# Set production mode at runtime only (not at build time)
|
| 46 |
ENV NODE_ENV=production
|
| 47 |
|
| 48 |
-
# Run backend
|
| 49 |
-
CMD ["
|
|
|
|
| 45 |
# Set production mode at runtime only (not at build time)
|
| 46 |
ENV NODE_ENV=production
|
| 47 |
|
| 48 |
+
# Run backend as the primary app for OpenEnv validation
|
| 49 |
+
CMD ["uvicorn", "backend.app.main:app", "--host", "0.0.0.0", "--port", "7860"]
|
backend/app/main.py
CHANGED
|
@@ -7,15 +7,24 @@ from typing import Any, Dict, List, Optional
|
|
| 7 |
from fastapi import FastAPI, HTTPException
|
| 8 |
from pydantic import BaseModel
|
| 9 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
# Import the existing inference runner so we can reuse run_episode
|
| 11 |
try:
|
| 12 |
-
# inference.py lives at project root and exports run_episode
|
| 13 |
import inference
|
| 14 |
except Exception:
|
| 15 |
inference = None
|
| 16 |
|
| 17 |
app = FastAPI(title="LifeLine AI API", version="1.0.0")
|
| 18 |
|
|
|
|
|
|
|
|
|
|
| 19 |
# Configure logging for startup visibility
|
| 20 |
logger = logging.getLogger("lifeline.backend")
|
| 21 |
logging.basicConfig(level=logging.INFO)
|
|
@@ -46,6 +55,41 @@ def health() -> Dict[str, str]:
|
|
| 46 |
return {"status": "ok", "project": "LifeLine AI"}
|
| 47 |
|
| 48 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 49 |
@app.post("/run-benchmark")
|
| 50 |
def run_benchmark(req: BenchmarkRequest) -> Dict[str, Any]:
|
| 51 |
"""Run the existing inference benchmark and return structured JSON results.
|
|
|
|
| 7 |
from fastapi import FastAPI, HTTPException
|
| 8 |
from pydantic import BaseModel
|
| 9 |
|
| 10 |
+
import sys
|
| 11 |
+
# Ensure project root is in path for environment and models
|
| 12 |
+
sys.path.append(os.getcwd())
|
| 13 |
+
|
| 14 |
+
from environment import MediRouteEnv
|
| 15 |
+
from models import Action, Observation, StepResult
|
| 16 |
+
|
| 17 |
# Import the existing inference runner so we can reuse run_episode
|
| 18 |
try:
|
|
|
|
| 19 |
import inference
|
| 20 |
except Exception:
|
| 21 |
inference = None
|
| 22 |
|
| 23 |
app = FastAPI(title="LifeLine AI API", version="1.0.0")
|
| 24 |
|
| 25 |
+
# Global environment instance for the OpenEnv validator
|
| 26 |
+
env = MediRouteEnv()
|
| 27 |
+
|
| 28 |
# Configure logging for startup visibility
|
| 29 |
logger = logging.getLogger("lifeline.backend")
|
| 30 |
logging.basicConfig(level=logging.INFO)
|
|
|
|
| 55 |
return {"status": "ok", "project": "LifeLine AI"}
|
| 56 |
|
| 57 |
|
| 58 |
+
# ββ OpenEnv Endpoints ββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 59 |
+
|
| 60 |
+
class ResetRequest(BaseModel):
|
| 61 |
+
difficulty: str = "easy"
|
| 62 |
+
|
| 63 |
+
|
| 64 |
+
@app.post("/reset")
|
| 65 |
+
async def reset(req: ResetRequest = ResetRequest()) -> Observation:
|
| 66 |
+
"""Reset the environment to a fresh state with the given difficulty."""
|
| 67 |
+
logger.info(f"OpenEnv: resetting to difficulty={req.difficulty}")
|
| 68 |
+
obs = env.reset(difficulty=req.difficulty)
|
| 69 |
+
return obs
|
| 70 |
+
|
| 71 |
+
|
| 72 |
+
@app.post("/step")
|
| 73 |
+
async def step(action: Action) -> StepResult:
|
| 74 |
+
"""Advance the environment by one step using the provided action."""
|
| 75 |
+
logger.info(f"OpenEnv: step with action={action.action_type}")
|
| 76 |
+
try:
|
| 77 |
+
result = env.step(action)
|
| 78 |
+
return result
|
| 79 |
+
except Exception as e:
|
| 80 |
+
logger.error(f"OpenEnv step failed: {e}")
|
| 81 |
+
raise HTTPException(status_code=500, detail=str(e))
|
| 82 |
+
|
| 83 |
+
|
| 84 |
+
@app.get("/state")
|
| 85 |
+
async def get_state() -> Observation:
|
| 86 |
+
"""Return the current snapshot of the environment's observation."""
|
| 87 |
+
try:
|
| 88 |
+
return env.state()
|
| 89 |
+
except Exception as e:
|
| 90 |
+
raise HTTPException(status_code=400, detail=str(e))
|
| 91 |
+
|
| 92 |
+
|
| 93 |
@app.post("/run-benchmark")
|
| 94 |
def run_benchmark(req: BenchmarkRequest) -> Dict[str, Any]:
|
| 95 |
"""Run the existing inference benchmark and return structured JSON results.
|