Files
sci-gui-agent-benchmark/main.py
David Chang 857f73f61d ver Nov23rd
trying to set up the environment
2023-11-24 20:39:08 +08:00

72 lines
2.4 KiB
Python

#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
def human_agent():
"""
Runs the Gym environment with human input.
"""
#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"
)
observation = env.reset()
done = False
while not done:
action = get_human_action()
observation, reward, done, info = env.step(action)
print("Observation:", observation)
print("Reward:", reward)
print("Info:", info)
print("================================\n")
if done:
print("The episode is done.")
break
env.close()
print("Environment closed.")
if __name__ == "__main__":
human_agent()