gym interface
This commit is contained in:
73
main.py
73
main.py
@@ -1,14 +1,65 @@
|
||||
from controller import Controller, Action, MouseClick
|
||||
from pprint import pprint
|
||||
from desktop_env.envs.desktop_env import DesktopEnv, Action, MouseClick
|
||||
|
||||
controller = Controller(vm_name="KUbuntu-23.10", username="username", password="password", host="192.168.56.101")
|
||||
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
|
||||
|
||||
input("enter to continue")
|
||||
img = controller.get_state()
|
||||
print(img)
|
||||
input("enter to continue")
|
||||
controller.step(action=Action.MOUSE_MOVE, x=100, y=100)
|
||||
input("enter to continue")
|
||||
controller.step(action=Action.CLICK, click=MouseClick.LEFT)
|
||||
input("enter to continue")
|
||||
controller.step(action=Action.TYPE, text="hello world")
|
||||
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="~/vmware/Ubuntu 64-bit/Ubuntu 64-bit.vmx",
|
||||
username="user",
|
||||
password="password",
|
||||
host="192.168.7.128")
|
||||
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()
|
||||
|
||||
Reference in New Issue
Block a user