File size: 943 Bytes
bd67f06
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
"""FastAPI application for the SimLab HR OpenEnv environment."""

from pathlib import Path

from fastapi import FastAPI
from fastapi.responses import HTMLResponse
from openenv.core.env_server import create_app

from simlab_hr.models import HRAction, HRObservation
from simlab_hr.server.environment import HREnvironment

_openenv_app = create_app(HREnvironment, HRAction, HRObservation, env_name="simlab-hr")

app = FastAPI(title="SimLab HR")

_landing_html = None
_landing_path = Path(__file__).resolve().parent.parent / "landing.py"
if _landing_path.exists():
    _ns = {}
    exec(compile(_landing_path.read_text(), _landing_path, "exec"), _ns)
    _landing_html = _ns.get("LANDING_HTML")


@app.get("/", response_class=HTMLResponse, include_in_schema=False)
async def landing_page():
    if _landing_html:
        return _landing_html
    return '<h1>SimLab HR</h1><p><a href="/api/docs">API Docs</a></p>'


app.mount("/api", _openenv_app)