File size: 1,344 Bytes
88ac8ef
 
 
 
0b0b6b0
 
 
88ac8ef
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
14a336b
 
 
88ac8ef
 
 
14a336b
 
 
 
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
"""FastAPI server for the BrowserGym environment."""

import os

from openenv_core.env_server.http_server import create_app
from browsergym_env.models import BrowserGymAction, BrowserGymObservation
from browsergym_env.server.browsergym_environment import BrowserGymEnvironment

# Get configuration from environment variables
benchmark = os.environ.get("BROWSERGYM_BENCHMARK", "miniwob")
task_name = os.environ.get("BROWSERGYM_TASK_NAME")  # Optional, can be None
headless = os.environ.get("BROWSERGYM_HEADLESS", "true").lower() == "true"
viewport_width = int(os.environ.get("BROWSERGYM_VIEWPORT_WIDTH", "1280"))
viewport_height = int(os.environ.get("BROWSERGYM_VIEWPORT_HEIGHT", "720"))
timeout = float(os.environ.get("BROWSERGYM_TIMEOUT", "10000"))
port = int(os.environ.get("BROWSERGYM_PORT", "8000"))

# Create the environment instance
env = BrowserGymEnvironment(
    benchmark=benchmark,
    task_name=task_name,
    headless=headless,
    viewport_width=viewport_width,
    viewport_height=viewport_height,
    timeout=timeout,
)

# Create the FastAPI app
app = create_app(
    env,
    BrowserGymAction,
    BrowserGymObservation,
    env_name="browsergym_env",
)


def main():
    """Main entry point for running the server."""
    import uvicorn

    uvicorn.run(app, host="0.0.0.0", port=port)


if __name__ == "__main__":
    main()