Spaces:
Sleeping
Sleeping
| # Copyright (c) Meta Platforms, Inc. and affiliates. | |
| # All rights reserved. | |
| """FastAPI application for the PostMortem Environment.""" | |
| try: | |
| from openenv.core.env_server.http_server import create_app | |
| except Exception as e: # pragma: no cover | |
| raise ImportError( | |
| "openenv-core is required. Install with 'pip install openenv-core'." | |
| ) from e | |
| try: | |
| from ..models import PostmortemAction, PostmortemObservation | |
| from .postmortem_env_environment import PostmortemEnvironment | |
| except (ImportError, ModuleNotFoundError): # Docker / direct-run fallback | |
| import os, sys | |
| sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) | |
| from models import PostmortemAction, PostmortemObservation # type: ignore | |
| from server.postmortem_env_environment import PostmortemEnvironment # type: ignore | |
| app = create_app( | |
| PostmortemEnvironment, | |
| PostmortemAction, | |
| PostmortemObservation, | |
| env_name="postmortem_env", | |
| max_concurrent_envs=1, | |
| ) | |
| def main(host: str = "0.0.0.0", port: int = 8000) -> None: | |
| """Entry point for direct execution.""" | |
| import uvicorn | |
| uvicorn.run(app, host=host, port=port) | |
| if __name__ == "__main__": | |
| import argparse | |
| parser = argparse.ArgumentParser() | |
| parser.add_argument("--port", type=int, default=8000) | |
| parser.add_argument("--host", type=str, default="0.0.0.0") | |
| args, _ = parser.parse_known_args() | |
| if args.host == "0.0.0.0" and args.port == 8000: | |
| main() | |
| else: | |
| main(host=args.host, port=args.port) | |