File size: 1,468 Bytes
d1221ff
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
f8a321a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
d1221ff
 
 
 
 
 
 
 
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
"""FastAPI application entry point for the Summarization environment."""
import sys
import os

import uvicorn

# Ensure project root is on the path so server/environment.py can import models, tasks, etc.
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))

from openenv.core.env_server import create_fastapi_app
from server.environment import SummarizationEnvironment
from models import SummarizationAction, SummarizationObservation

# Keep one environment instance for HTTP requests so /reset and /step share state.
_ENV = SummarizationEnvironment()


def _env_factory() -> SummarizationEnvironment:
    return _ENV


app = create_fastapi_app(
    _env_factory,
    action_cls=SummarizationAction,
    observation_cls=SummarizationObservation,
)


@app.get("/")
def root() -> dict:
    """Friendly landing page for Spaces and browser visits."""
    return {
        "name": "Long-Context Summarization",
        "status": "healthy",
        "docs": {
            "health": "/health",
            "schema": "/schema",
            "metadata": "/metadata",
            "reset": "POST /reset",
            "step": "POST /step",
            "state": "GET /state",
        },
    }


def main() -> None:
    """Run the environment server for local validation and script entrypoints."""
    port = int(os.environ.get("PORT", "7860"))
    uvicorn.run("server.app:app", host="0.0.0.0", port=port, workers=1)


if __name__ == "__main__":
    main()