Team Ai
Apppublic

razak123/code-migration-env

sourceHugging Faceupdated 6mo agoView on Hugging Face
0likes
app.py82 linesDownload Raw Back to server
1 2# code_migration_env\server\app.py3# Copyright (c) Meta Platforms, Inc. and affiliates.4# All rights reserved.5#6# This source code is licensed under the BSD-style license found in the7# LICENSE file in the root directory of this source tree.8 9"""10FastAPI application for the Code Migration Env Environment.11 12This module creates an HTTP server that exposes the CodeMigrationEnvironment13over HTTP and WebSocket endpoints, compatible with EnvClient.14 15Endpoints:16    - POST /reset: Reset the environment17    - POST /step: Execute an action18    - GET /state: Get current environment state19    - GET /schema: Get action/observation schemas20    - WS /ws: WebSocket endpoint for persistent sessions21 22Usage:23    # Development (with auto-reload):24    uvicorn server.app:app --reload --host 0.0.0.0 --port 800025 26    # Production:27    uvicorn server.app:app --host 0.0.0.0 --port 8000 --workers 428 29    # Or run directly:30    python -m server.app31"""32 33try:34    from openenv.core.env_server.http_server import create_app35except Exception as e:  # pragma: no cover36    raise ImportError(37        "openenv is required for the web interface. Install dependencies with '\n    uv sync\n'"38    ) from e39 40try:41    from ..models import CodeMigrationAction, CodeMigrationObservation42    from .code_migration_env_environment import CodeMigrationEnvironment43except ImportError:44    from models import CodeMigrationAction, CodeMigrationObservation45    from server.code_migration_env_environment import CodeMigrationEnvironment46 47 48# Create the app with web interface and README integration49app = create_app(50    CodeMigrationEnvironment,51    CodeMigrationAction,52    CodeMigrationObservation,53    env_name="code_migration_env",54    max_concurrent_envs=1,  # increase this number to allow more concurrent WebSocket sessions55)56 57 58def main(host: str = "0.0.0.0", port: int = 8000):59    """60    Entry point for direct execution via uv run or python -m.61 62    This function enables running the server without Docker:63        uv run --project . server64        uv run --project . server --port 800165        python -m code_migration_env.server.app66 67    Args:68        host: Host address to bind to (default: "0.0.0.0")69        port: Port number to listen on (default: 8000)70 71    For production deployments, consider using uvicorn directly with72    multiple workers:73        uvicorn code_migration_env.server.app:app --workers 474    """75    import uvicorn76 77    uvicorn.run(app, host=host, port=port)78 79 80if __name__ == '__main__':81    main()82 
razak123/code-migration-env · Team Ai