File size: 1,479 Bytes
dcdd52f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
fbefaec
dcdd52f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
55
56
57
58
"""FastAPI entry point for TraceFix-RL."""

import gradio as gr
from vision_ui import demo

try:
    from openenv.core.env_server.http_server import create_app
except Exception as e:  # pragma: no cover
    raise ImportError(
        "openenv is required for the web interface. Install dependencies with '\n    uv sync\n'"
    ) from e

try:
    from core.models import CodeAction, CodeObservation
    from server.tracefix_rl_environment import TraceFixRLEnvironment
except ImportError:
    import sys
    from pathlib import Path

    sys.path.insert(0, str(Path(__file__).resolve().parents[1]))
    from core.models import CodeAction, CodeObservation
    from server.tracefix_rl_environment import TraceFixRLEnvironment


app = create_app(
    TraceFixRLEnvironment,
    CodeAction,
    CodeObservation,
    env_name="tracefix_rl",
    max_concurrent_envs=100,
)

from fastapi.responses import RedirectResponse

@app.get("/", include_in_schema=False)
async def root_redirect():
    return RedirectResponse(url="/web/")

@app.get("/web", include_in_schema=False)
async def web_no_slash_redirect():
    return RedirectResponse(url="/web/")

app = gr.mount_gradio_app(app, demo, path="/web")


def main() -> None:
    """Entry point for local and container execution."""
    import os
    import uvicorn

    host = os.environ.get("HOST", "0.0.0.0")
    port = int(os.environ.get("PORT", "7860"))
    uvicorn.run(app, host=host, port=port)


if __name__ == "__main__":
    main()