Merge branch 'main' into zdy
This commit is contained in:
81
main.py
81
main.py
@@ -1,59 +1,50 @@
|
||||
#from pprint import pprint
|
||||
from desktop_env.envs.desktop_env import DesktopEnv, Action, MouseClick
|
||||
|
||||
def get_human_action():
|
||||
"""
|
||||
Prompts the human player for an action and returns a structured action.
|
||||
"""
|
||||
print("\nAvailable actions:", [action.name for action in Action])
|
||||
action_type = None
|
||||
while action_type not in [action.value for action in Action]:
|
||||
action_type = Action[input("Enter the type of action: ".strip())].value
|
||||
|
||||
action = {"action_type": action_type}
|
||||
|
||||
if action_type == Action.CLICK.value or action_type == Action.MOUSE_DOWN.value or action_type == Action.MOUSE_UP.value:
|
||||
print("\n Available clicks:", [action.name for action in MouseClick])
|
||||
click_type = input("Enter click type: ")
|
||||
action["click_type"] = MouseClick[click_type].value
|
||||
|
||||
if action_type == Action.MOUSE_MOVE.value:
|
||||
x = int(input("Enter x-coordinate for mouse move: "))
|
||||
y = int(input("Enter y-coordinate for mouse move: "))
|
||||
action["x"] = x
|
||||
action["y"] = y
|
||||
|
||||
if action_type == Action.KEY.value:
|
||||
key = input("Enter the key to press: ")
|
||||
action["key"] = [ord(c) for c in key]
|
||||
|
||||
if action_type == Action.TYPE.value:
|
||||
text = input("Enter the text to type: ")
|
||||
action["text"] = [ord(c) for c in text]
|
||||
|
||||
return action
|
||||
import json
|
||||
from desktop_env.envs.desktop_env import DesktopEnv
|
||||
|
||||
|
||||
def human_agent():
|
||||
"""
|
||||
Runs the Gym environment with human input.
|
||||
"""
|
||||
|
||||
with open("evaluation_examples/examples/37608790-6147-45d0-9f20-1137bb35703d.json", "r") as f:
|
||||
example = json.load(f)
|
||||
|
||||
#env = DesktopEnv( path_to_vm="/home/yuri/vmware/Windows 10 x64/Windows 10 x64.vmx"
|
||||
# path_to_vm="/home/yuri/vmware/Ubuntu 64-bit/Ubuntu 64-bit.vmx",
|
||||
env = DesktopEnv( path_to_vm="/home/david/vmware/KUbuntu 64-bit/KUbuntu 64-bit.vmx"
|
||||
, username="david"
|
||||
, password="123456"
|
||||
, host="192.168.174.129"
|
||||
#host="http://192.168.7.129:5000",
|
||||
#vm_os="windows")
|
||||
, vm_os="ubuntu"
|
||||
, action_space="computer_13"
|
||||
, snapshot_path="base_setup"
|
||||
, instruction=example["instruction"]
|
||||
#, config=example["config"]
|
||||
#, evaluator=example["evaluator"]
|
||||
)
|
||||
|
||||
# reset the environment to certain snapshot
|
||||
observation = env.reset()
|
||||
done = False
|
||||
|
||||
while not done:
|
||||
action = get_human_action()
|
||||
observation, reward, done, info = env.step(action)
|
||||
trajectory = [
|
||||
{
|
||||
"action_type": "MOVE_TO",
|
||||
"parameters": {
|
||||
"x": 754,
|
||||
"y": 1057
|
||||
}
|
||||
},
|
||||
{"action_type": "CLICK", "parameters": {"button": "right", "num_clicks": 1}}
|
||||
]
|
||||
|
||||
for i in range(len(trajectory)):
|
||||
# action = get_human_action()
|
||||
|
||||
# action = {
|
||||
# "action_type": 0,
|
||||
# "click_type": 3,
|
||||
# }
|
||||
print(trajectory[i])
|
||||
|
||||
observation, reward, done, info = env.step(trajectory[i], pause=5)
|
||||
print("Observation:", observation)
|
||||
print("Reward:", reward)
|
||||
print("Info:", info)
|
||||
@@ -64,8 +55,12 @@ def human_agent():
|
||||
print("The episode is done.")
|
||||
break
|
||||
|
||||
result = env.evaluate()
|
||||
print("Result:", result)
|
||||
|
||||
env.close()
|
||||
print("Environment closed.")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
human_agent()
|
||||
|
||||
Reference in New Issue
Block a user