diff --git a/miniwob-sandbox b/miniwob-sandbox new file mode 120000 index 0000000..b1cc093 --- /dev/null +++ b/miniwob-sandbox @@ -0,0 +1 @@ +third-party/miniwob-sandbox/ \ No newline at end of file diff --git a/miniwob-sandbox/.gitignore b/miniwob-sandbox/.gitignore deleted file mode 100644 index 8e9972c..0000000 --- a/miniwob-sandbox/.gitignore +++ /dev/null @@ -1,5 +0,0 @@ -*.swp -*~ -*.bak -*.pyc -/out diff --git a/miniwob-sandbox/README.md b/miniwob-sandbox/README.md deleted file mode 100644 index d95a5c4..0000000 --- a/miniwob-sandbox/README.md +++ /dev/null @@ -1,115 +0,0 @@ -# MiniWoB Sandbox - -## Viewing the Tasks - -There are 2 ways to access the tasks: - -* **Use the `file://` protocol (Recommended):** open `miniwob-sandbox/html/miniwob/` in the browser. - * The URL should now be something like - - file:///path/to/web-agents/miniwob-sandbox/html/miniwob/ - - * This should show the directory listing of all task HTML files. - -* **Run a simple server:** go to `miniwob-sandbox/html/` and run `./http-server`. - * The tasks should now be accessible at `http://localhost:8080/miniwob/` - * The port can be specified like this: `./http-server -p 8765` - -## Recording Demonstrations - -1. Start the recording server: - - # Create an output directory - mkdir out/ - ./record.py out/ - -2. Append `?record=true` to the URL of the task you want to record. For example, for the `click-test` task, go to - - file:///path/to/web-agents/miniwob-sandbox/html/miniwob/click-test.html?record=true - -3. To view the results, open `viewer/viewer.html` while the recording server is running. The URL should be like - - file:///path/to/web-agents/miniwob-sandbox/html/viewer/viewer.html - ---- - -# JavaScript Utilities - -This version of MiniWoB incorporates a few additional JavaScript utilities. - -## `Math.seedrandom([seed])` - -Set the global random seed of the environment. The optional argument `seed` can be an object. - -## `getDOMInfo()` - -Returns a nested object containing information about the current DOM states. -The returned object corresponds to the `
` element. Its children can be accessed under the `children` field. - -In Python, the `step` method in `MiniWoBInstance` calls this function to build the `MiniWoBState`. - -### Output Format - -Each visible DOM element is converted into an object with the following fields: - -* `tag` (string): Tag name - * For normal elements, this is the uppercased tag name (e.g., `"DIV"`) - * For `` elements, the input type is appended (e.g., `"INPUT_text"`) - * Each non-empty text node is converted into pseudo-elements with tag `"t"`, - where each pseudo-element represents one line of text. - However, if the text node is the only child of the parent. The text pseudo-element is not created, - and its text is assigned to the parent element instead. -* `ref` (number): Reference number - * Within each episode, the `ref` number of the same object stays the same - * For the same random seed, the `ref` number of the same object should be the same - * `ref` for normal elements start from 1, while `ref` for text psuedo-elements counts down from -1 -* `children` (list): Recursive list of objects corresponding to the children -* `left`, `top`, `width`, `height` (number): Geometry of the element -* `id` (string): Element's `id` -* `classes` (string): Element's `class`es (space-separated) -* `bgColor`, `fgColor` (string): Background and foreground colors -* `focused` (boolean): Indicates if the element is being focused on -* `tampered` (boolean): Indicates if the element is tampered (clicked, focused, typed, etc.) -* `value`: For ``, this contains the input value - * For `checkbox` and `radio` types, this contains a boolean whether the input is selected - * For other input types, this contains a text value -* `text` (string): For child nodes and text pseudo-elements, this contains the text content - -## `flattenDOMInfo(rootDomInfo)` - -Can be called on the result of `getDOMInfo()` to get a flattened representation. -Useful for debugging in Chrome console. - -## `elementClick(ref)` - -Click on an element regardless of its location and visibility. -The argument `ref` is the ref value generated by the previous call to `getDOMInfo()`. - -## `visualizeAttention(values)` - -Visualize the attention weights on the screen. -The argument `values` is a 2D array of shape 20 × 20. - ---- - -# Demonstration Format - -Each demonstration is saved as a JSON file. The root object generated by `core/record.js` contains the following fields: - -* `taskName` (string) -* `utterance` (string) -* `reward` (number): Reward as defined by the task -* `rawReward` (number): 1 if succeeded and -1 if failed -* `states`: a list of state objects - * One state is recorded for the initial state - * Two states are recorded for each event, one before the event resolves and one after the event resolves - -Each state object has the following fields: - -* `time` (number): Time elapsed since the episode started -* `action`: An action-specific object (not present for the initial state) with the following common keys: - * `type` (string) - * `timing` (number): the `eventPhase` property of the JS event object. - This is 1 before the event resolves (capturing state) and 3 after the event resolves (bubbling state). -* `dom`: The DOM info as generated by `getDOMInfo()` - * The event target will have a special key `recordingTarget` set to `true`. diff --git a/miniwob-sandbox/bot/click-test-2-bot.py b/miniwob-sandbox/bot/click-test-2-bot.py deleted file mode 100755 index d39c525..0000000 --- a/miniwob-sandbox/bot/click-test-2-bot.py +++ /dev/null @@ -1,84 +0,0 @@ -#!/usr/bin/env python -# -*- coding: utf-8 -*- - -import sys, os, shutil, re, argparse, json, time, traceback, urlparse -from codecs import open -from itertools import izip -from collections import defaultdict, Counter - -from selenium import webdriver -from selenium.webdriver.common.keys import Keys -from selenium.webdriver.common.by import By -from selenium.webdriver.support.ui import WebDriverWait -from selenium.webdriver.support import expected_conditions as EC - - -def get_options(headless=False): - options = webdriver.ChromeOptions() - if headless: - options.add_argument('headless') - options.add_argument('disable-gpu') - options.add_argument('no-sandbox') - return options - - -def main(): - parser = argparse.ArgumentParser() - parser.add_argument('-s', '--screenshot', - help='dump screenshot to this directory') - parser.add_argument('-H', '--headless', action='store_true', - help='do not render the Chrome interface') - parser.add_argument('-n', type=int, default=30, - help='number of episodes') - parser.add_argument('-b', '--base-url', - default='http://localhost:8000/miniwob/', - help='base URL of the task') - args = parser.parse_args() - - if args.screenshot: - assert os.path.isdir(args.screenshot) - - print 'Opening Chrome' - options = get_options(headless=args.headless) - driver = webdriver.Chrome(chrome_options=options) - driver.implicitly_wait(1) - url = urlparse.urljoin(args.base_url, 'click-test-2.html') - print 'Go to {}'.format(url) - driver.get(url) - - for i in xrange(args.n): - print 'Instance {}'.format(i) - element = WebDriverWait(driver, 3).until( - EC.element_to_be_clickable((By.ID, "sync-task-cover"))) - driver.find_element_by_id('sync-task-cover').click() - if args.screenshot: - driver.save_screenshot(os.path.join(args.screenshot, '{}.png'.format(i))) - buttons = driver.find_elements_by_tag_name('button') - one_buttons = [x for x in buttons if x.text == 'ONE'] - clicked = False - for x in one_buttons: - try: - x.click() - clicked = True - break - except Exception as e: - # May fail if TWO is in front of ONE! - traceback.print_exc() - if not clicked: - print 'Attempt to click other things' - for x in buttons: - try: - x.click() - clicked = True - break - except Exception as e: - traceback.print_exc() - print 'Cliked = {}'.format(clicked) - - print 'DONE!' - driver.close() - - -if __name__ == '__main__': - main() - diff --git a/miniwob-sandbox/bot/parallel-bot.py b/miniwob-sandbox/bot/parallel-bot.py deleted file mode 100755 index 50a851c..0000000 --- a/miniwob-sandbox/bot/parallel-bot.py +++ /dev/null @@ -1,35 +0,0 @@ -#!/usr/bin/env python -# -*- coding: utf-8 -*- - -import sys, os, shutil, re, argparse, json -from codecs import open -from itertools import izip -from collections import defaultdict, Counter - -from selenium import webdriver -from selenium.webdriver.common.keys import Keys - - -def main(): - parser = argparse.ArgumentParser() - - args = parser.parse_args() - - drivers = [] - for i in xrange(5): - drivers.append(webdriver.Remote( - desired_capabilities={'browserName': 'chrome'})) - print 'Created 5 drivers' - - for driver in drivers: - driver.get("https://github.com") - print(driver.title) - assert "GitHub" in driver.title - - for driver in drivers: - driver.close() - - -if __name__ == '__main__': - main() - diff --git a/miniwob-sandbox/docker/Dockerfile b/miniwob-sandbox/docker/Dockerfile deleted file mode 100644 index 542d4ca..0000000 --- a/miniwob-sandbox/docker/Dockerfile +++ /dev/null @@ -1,16 +0,0 @@ -FROM python:2.7-slim -RUN pip install selenium - -RUN apt-get update && apt-get install wget unzip xvfb -y - -RUN wget -q -O /tmp/linux_signing_key.pub https://dl-ssl.google.com/linux/linux_signing_key.pub \ - && apt-key add /tmp/linux_signing_key.pub \ - && echo "deb http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google-chrome.list \ - && apt-get update && apt-get install google-chrome-stable -y - -RUN wget -q https://chromedriver.storage.googleapis.com/2.30/chromedriver_linux64.zip -O /tmp/chromedriver.zip \ - && mkdir -p /opt/bin/ \ - && unzip /tmp/chromedriver.zip -d /opt/bin/ -ENV PATH /opt/bin/:$PATH - -VOLUME ["/miniwob"] diff --git a/miniwob-sandbox/html/.gitignore b/miniwob-sandbox/html/.gitignore deleted file mode 100644 index 914bb2d..0000000 --- a/miniwob-sandbox/html/.gitignore +++ /dev/null @@ -1 +0,0 @@ -twistd.pid diff --git a/miniwob-sandbox/html/common/shapes.js b/miniwob-sandbox/html/common/shapes.js deleted file mode 100644 index 1b761a3..0000000 --- a/miniwob-sandbox/html/common/shapes.js +++ /dev/null @@ -1,235 +0,0 @@ -/* -Utilities for generating and describing shapes/digits/letters in a grid -that have various properties. -*/ - -var shapes = {}; - -// env variables -shapes.SZ_X = 7; // number of bins for shapes -shapes.SZ_Y = 7; -shapes.MAX_SIZE = 20; // max render size of shapes in pixels. Note by default grid is 160x160, so 8*20=160. - -shapes.MAX_NUM_SHAPES = 20; -shapes.MIN_NUM_SHAPES = 3; -shapes.COLORS = ['red', 'green', 'blue', 'aqua', 'black', 'magenta', 'yellow']; -shapes.LETTERS = 'qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM'; -shapes.DIGITS = '1234567890'; -shapes.SHAPES = ['circle', 'rectangle', 'triangle']; - -// helper function that creates a grid of shapes -shapes.genGrid = function(n) { - - var grid = {}; - grid.shapes = []; - - var taken_positions = []; - var num_shapes = typeof n !== 'undefined' ? n : core.randi(shapes.MIN_NUM_SHAPES, shapes.MAX_NUM_SHAPES); - for(var i=0;i=0&&d<=1.001&&g>=0&&g<=1.001&&(r?it++:it.push({x:f.x,y:f.y,t1:l(d,1),t2:l(g,1)}))}}return it}function gi(n,t,r){var e,o,s,h,b,k,d,g,c,l,y,p,nt,a,w,tt,v,u,f,it;for(n=i._path2curve(n),t=i._path2curve(t),y=r?0:[],p=0,nt=n.length;p =n.x&&t<=n.x2&&i>=n.y&&i<=n.y2};i.isBBoxIntersect=function(n,t){var r=i.isPointInsideBBox;return r(t,n.x,n.y)||r(t,n.x2,n.y)||r(t,n.x,n.y2)||r(t,n.x2,n.y2)||r(n,t.x,t.y)||r(n,t.x2,t.y)||r(n,t.x,t.y2)||r(n,t.x2,t.y2)||(n.x 1&&(tt=u.sqrt(tt),i=tt*i,r=tt*r);var ht=i*i,ct=r*r,vt=(e==o?-1:1)*u.sqrt(y((ht*ct-ht*d*d-ct*b*b)/(ht*d*d+ct*b*b))),rt=vt*i*d/r+(n+h)/2,ft=vt*-r*b/i+(t+c)/2,v=u.asin(((t-ft)/r).toFixed(9)),a=u.asin(((c-ft)/r).toFixed(9));v=n