CoolFace
Apppublic

openenv/browsergym_env

sourceHugging Faceupdated 3mo agoView on Hugging Face
0likes
__init__.py106 linesDownload Raw Back to root
1"""BrowserGym Environment for OpenEnv.2 3BrowserGym is a unified framework for web-based agent tasks that provides4access to multiple benchmarks under a single Gymnasium-compatible API.5 6Included Benchmarks:7- **MiniWoB++**: 100+ simple web tasks for training (no external infrastructure!)8- **WebArena**: 812 realistic evaluation tasks (requires backend setup)9- **VisualWebArena**: Visual web navigation tasks10- **WorkArena**: Enterprise task automation11 12Key Features:13- Unified API across all benchmarks14- Gymnasium-compatible interface15- Support for multiple observation types (text, visual, DOM)16- Action spaces for natural language commands17- Perfect for training (MiniWoB) and evaluation (WebArena)18 19Training Example (MiniWoB - works immediately):20    ```python21    from envs.browsergym_env import BrowserGymEnv, BrowserGymAction22 23    # Create training environment - no backend setup needed!24    env = BrowserGymEnv.from_docker_image(25        "browsergym-env:latest",26        environment={27            "BROWSERGYM_BENCHMARK": "miniwob",28            "BROWSERGYM_TASK_NAME": "click-test",29        }30    )31 32    # Train your agent33    for episode in range(1000):34        result = env.reset()35        while not result.done:36            action = agent.get_action(result.observation)37            result = env.step(action)38 39    env.close()40    ```41 42Evaluation Example (WebArena - requires backend):43    ```python44    from envs.browsergym_env import BrowserGymEnv, BrowserGymAction45 46    # Create evaluation environment47    env = BrowserGymEnv.from_docker_image(48        "browsergym-env:latest",49        environment={50            "BROWSERGYM_BENCHMARK": "webarena",51            "BROWSERGYM_TASK_NAME": "0",52            "SHOPPING": "http://your-server:7770",53            # ... other backend URLs54        }55    )56 57    # Evaluate your trained agent58    result = env.reset()59    # ... run evaluation60    env.close()61    ```62"""63 64from __future__ import annotations65 66from importlib import import_module67from typing import TYPE_CHECKING68 69from .client import BrowserGymEnv70from .models import BrowserGymAction, BrowserGymObservation, BrowserGymState71 72if TYPE_CHECKING:73    from .harness import BrowserGymSessionFactory, build_browsergym_action_tool_call74 75__all__ = [76    "BrowserGymEnv",77    "BrowserGymAction",78    "BrowserGymObservation",79    "BrowserGymState",80    "BrowserGymSessionFactory",81    "build_browsergym_action_tool_call",82]83 84_LAZY_ATTRS = {85    "BrowserGymSessionFactory": (".harness", "BrowserGymSessionFactory"),86    "build_browsergym_action_tool_call": (87        ".harness",88        "build_browsergym_action_tool_call",89    ),90}91 92 93def __getattr__(name: str):94    if name not in _LAZY_ATTRS:95        raise AttributeError(f"module {__name__!r} has no attribute {name!r}")96 97    module_path, attr_name = _LAZY_ATTRS[name]98    module = import_module(module_path, __name__)99    value = getattr(module, attr_name)100    globals()[name] = value101    return value102 103 104def __dir__() -> list[str]:105    return sorted(set(globals().keys()) | set(__all__))106