|
| 1 | +# =========== Copyright 2024 @ CAMEL-AI.org. All Rights Reserved. =========== |
| 2 | +# Licensed under the Apache License, Version 2.0 (the “License”); |
| 3 | +# you may not use this file except in compliance with the License. |
| 4 | +# You may obtain a copy of the License at |
| 5 | +# |
| 6 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 7 | +# |
| 8 | +# Unless required by applicable law or agreed to in writing, software |
| 9 | +# distributed under the License is distributed on an “AS IS” BASIS, |
| 10 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 11 | +# See the License for the specific language governing permissions and |
| 12 | +# limitations under the License. |
| 13 | +# =========== Copyright 2024 @ CAMEL-AI.org. All Rights Reserved. =========== |
| 14 | +import warnings |
| 15 | + |
| 16 | +from crab import ( |
| 17 | + BenchmarkConfig, |
| 18 | + create_benchmark, |
| 19 | +) |
| 20 | +from crab.actions.crab_actions import complete |
| 21 | +from crab.actions.visual_prompt_actions import ( |
| 22 | + get_elements_prompt, |
| 23 | + groundingdino_easyocr, |
| 24 | +) |
| 25 | +from crab.environments.macos import mac_env |
| 26 | +from gui.envs import ANDROID_ENV, UBUNTU_ENV, WINDOWS_ENV |
| 27 | +from gui.host_os import HostOS |
| 28 | + |
| 29 | +warnings.filterwarnings("ignore") |
| 30 | + |
| 31 | + |
| 32 | +def check_host_os() -> HostOS: |
| 33 | + return HostOS.WINDOWS |
| 34 | + |
| 35 | + |
| 36 | +def get_benchmark(env: str, ubuntu_url: str): |
| 37 | + ubuntu_tool = { |
| 38 | + "screenshot": groundingdino_easyocr(font_size=16) >> get_elements_prompt |
| 39 | + } |
| 40 | + android_tool = { |
| 41 | + "screenshot": groundingdino_easyocr(font_size=40) >> get_elements_prompt |
| 42 | + } |
| 43 | + mac_tool = { |
| 44 | + "screenshot": groundingdino_easyocr(font_size=24) >> get_elements_prompt |
| 45 | + } |
| 46 | + |
| 47 | + if env == "ubuntu": |
| 48 | + prompting_tools = {"ubuntu": ubuntu_tool} |
| 49 | + benchmark_config = BenchmarkConfig( |
| 50 | + name="ubuntu_benchmark", |
| 51 | + tasks=[], |
| 52 | + environments=[UBUNTU_ENV], |
| 53 | + prompting_tools=prompting_tools, |
| 54 | + root_action_space=[complete], |
| 55 | + multienv=True, |
| 56 | + ) |
| 57 | + elif env == "android": |
| 58 | + prompting_tools = {"android": android_tool} |
| 59 | + benchmark_config = BenchmarkConfig( |
| 60 | + name="android_benchmark", |
| 61 | + tasks=[], |
| 62 | + environments=[ANDROID_ENV], |
| 63 | + prompting_tools=prompting_tools, |
| 64 | + root_action_space=[complete], |
| 65 | + multienv=True, |
| 66 | + ) |
| 67 | + elif env == "cross": |
| 68 | + prompting_tools = { |
| 69 | + "android": android_tool, |
| 70 | + "ubuntu": ubuntu_tool, |
| 71 | + } |
| 72 | + benchmark_config = BenchmarkConfig( |
| 73 | + name="ubuntu_android_benchmark", |
| 74 | + tasks=[], |
| 75 | + environments=[UBUNTU_ENV, ANDROID_ENV], |
| 76 | + prompting_tools=prompting_tools, |
| 77 | + root_action_space=[complete], |
| 78 | + multienv=True, |
| 79 | + ) |
| 80 | + elif env == "mac": |
| 81 | + prompting_tools = {"macos": mac_tool} |
| 82 | + benchmark_config = BenchmarkConfig( |
| 83 | + name="mac_benchmark", |
| 84 | + tasks=[], |
| 85 | + environments=[mac_env, ANDROID_ENV], |
| 86 | + prompting_tools=prompting_tools, |
| 87 | + root_action_space=[complete], |
| 88 | + multienv=True, |
| 89 | + ) |
| 90 | + elif env == "windows": |
| 91 | + prompting_tools = {"windows": ubuntu_tool} |
| 92 | + benchmark_config = BenchmarkConfig( |
| 93 | + name="windows_benchmark", |
| 94 | + tasks=[], |
| 95 | + environments=[WINDOWS_ENV], |
| 96 | + prompting_tools=prompting_tools, |
| 97 | + root_action_space=[complete], |
| 98 | + multienv=True, |
| 99 | + ) |
| 100 | + else: |
| 101 | + raise ValueError("Env not support") |
| 102 | + |
| 103 | + benchmark_config.step_limit = 15 |
| 104 | + return create_benchmark(benchmark_config) |
| 105 | + |
| 106 | + |
| 107 | +def main(): |
| 108 | + host_os = check_host_os() |
| 109 | + print(f"Host OS: {host_os}") |
| 110 | + |
| 111 | + |
| 112 | +if __name__ == "__main__": |
| 113 | + main() |
0 commit comments