finished calc human evaluation updated calc configs with an extra sleep to guarantee the integrity of downloaded xlsx file
109 lines
3.3 KiB
Python
109 lines
3.3 KiB
Python
import datetime
|
|
import json
|
|
import logging
|
|
import os
|
|
import sys
|
|
import time
|
|
|
|
from desktop_env.envs.desktop_env import DesktopEnv
|
|
|
|
# Logger Configs {{{ #
|
|
logger = logging.getLogger()
|
|
logger.setLevel(logging.DEBUG)
|
|
|
|
datetime_str: str = datetime.datetime.now().strftime("%Y%m%d@%H%M%S")
|
|
|
|
file_handler = logging.FileHandler(os.path.join("logs", "normal-{:}.log".format(datetime_str)), encoding="utf-8")
|
|
debug_handler = logging.FileHandler(os.path.join("logs", "debug-{:}.log".format(datetime_str)), encoding="utf-8")
|
|
stdout_handler = logging.StreamHandler(sys.stdout)
|
|
sdebug_handler = logging.FileHandler(os.path.join("logs", "sdebug-{:}.log".format(datetime_str)), encoding="utf-8")
|
|
|
|
file_handler.setLevel(logging.INFO)
|
|
debug_handler.setLevel(logging.DEBUG)
|
|
stdout_handler.setLevel(logging.INFO)
|
|
sdebug_handler.setLevel(logging.DEBUG)
|
|
|
|
formatter = logging.Formatter(
|
|
fmt="\x1b[1;33m[%(asctime)s \x1b[31m%(levelname)s \x1b[32m%(module)s/%(lineno)d-%(processName)s\x1b[1;33m] \x1b[0m%(message)s")
|
|
file_handler.setFormatter(formatter)
|
|
debug_handler.setFormatter(formatter)
|
|
stdout_handler.setFormatter(formatter)
|
|
sdebug_handler.setFormatter(formatter)
|
|
|
|
stdout_handler.addFilter(logging.Filter("desktopenv"))
|
|
sdebug_handler.addFilter(logging.Filter("desktopenv"))
|
|
|
|
logger.addHandler(file_handler)
|
|
logger.addHandler(debug_handler)
|
|
logger.addHandler(stdout_handler)
|
|
logger.addHandler(sdebug_handler)
|
|
# }}} Logger Configs #
|
|
|
|
logger = logging.getLogger("desktopenv.main")
|
|
|
|
|
|
def human_agent():
|
|
"""
|
|
Runs the Gym environment with human input.
|
|
"""
|
|
|
|
with open("evaluation_examples/examples/libreoffice_calc/4f07fbe9-70de-4927-a4d5-bb28bc12c52c.json", "r") as f:
|
|
example = json.load(f)
|
|
example["snapshot"] = "Snapshot 30"
|
|
|
|
#env = DesktopEnv( path_to_vm="~/vmware/Windows 10 x64/Windows 10 x64.vmx"
|
|
env = DesktopEnv( path_to_vm="/mnt/data1/david/os-images/Ubuntu-1218/Ubuntu.vmx"
|
|
, action_space="computer_13"
|
|
, task_config=example
|
|
)
|
|
# reset the environment to certain snapshot
|
|
observation = env.reset()
|
|
done = False
|
|
|
|
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,
|
|
# }
|
|
logger.info(trajectory[i])
|
|
|
|
observation, reward, done, info = env.step(trajectory[i])
|
|
observation.pop("accessibility_tree")
|
|
logger.info("Observation: %s", observation)
|
|
logger.info("Reward: %.2f", reward)
|
|
logger.info("Info: %s", info)
|
|
|
|
logger.info("================================\n")
|
|
|
|
if done:
|
|
logger.info("The episode is done.")
|
|
break
|
|
|
|
input("Press Enter to start human operation...")
|
|
human_start_time = time.time()
|
|
input("Press Enter to finish human operation.")
|
|
print("Time elapsed of human operation: %.2f" % (time.time() - human_start_time))
|
|
|
|
result = env.evaluate()
|
|
logger.info("Result: %.2f", result)
|
|
|
|
# env.close()
|
|
logger.info("Environment closed.")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
human_agent()
|