Skip to content
This repository was archived by the owner on Apr 3, 2025. It is now read-only.

Commit 2dd08af

Browse files
authored
Merge pull request #1102 from facebookresearch/form-builder-app
Mephisto v1.3
2 parents 5176bf0 + 9bad7f3 commit 2dd08af

File tree

240 files changed

+53662
-2930
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

240 files changed

+53662
-2930
lines changed

._data

-4 KB
Binary file not shown.

.gitignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,13 @@ examples/simple_static_task/hydra_configs/conf/*
2929
!examples/simple_static_task/hydra_configs/conf/prolific_example.yaml
3030
!examples/simple_static_task/hydra_configs/conf/onboarding_example*.yaml
3131
examples/**/build/*
32+
examples/form_composer_demo/preview/*_preview.html
33+
34+
# Form Composer
35+
mephisto/generators/form_composer/data/*.json
36+
mephisto/generators/form_composer/webapp/package-lock.json
37+
mephisto/generators/form_composer/hydra_configs/conf/*.yaml
38+
!mephisto/generators/form_composer/hydra_configs/conf/default.yaml
3239

3340
# PyCharm
3441
.idea

docker/entrypoints/server.mturk.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,12 @@
77
set -e
88

99
pip install pytest
10+
1011
cd /mephisto
12+
# Directory for Task results
1113
mkdir -p "data" && chmod 777 "data"
14+
# Directory for Cypress testing
15+
mkdir -p "/root/.cache/cypress" && chmod 777 "/root/.cache/cypress"
1216

1317
mephisto register mturk_sandbox \
1418
name=$MTURK_SANDBOX_NAME \

docker/entrypoints/server.prolific.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,12 @@
77
set -e
88

99
pip install pytest black
10+
1011
cd /mephisto
12+
# Directory for Task results
1113
mkdir -p "data" && chmod 777 "data"
14+
# Directory for Cypress testing
15+
mkdir -p "/root/.cache/cypress" && chmod 777 "/root/.cache/cypress"
1216

1317
mephisto register prolific name=prolific api_key=$PROLIFIC_API_KEY
1418

docker/envs/env.dev

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,11 @@
1-
PROLIFIC_API_KEY="dev"
1+
PROLIFIC_API_KEY="..."
2+
3+
MTURK_SANDBOX_NAME="..."
4+
MTURK_SANDBOX_ACCESS_KEY_ID="..."
5+
MTURK_SANDBOX_SECRET_ACCESS_KEY="..."
6+
7+
AWS_ACCESS_KEY_ID=...
8+
AWS_SECRET_ACCESS_KEY=...
9+
AWS_DEFAULT_REGION=...
10+
11+
S3_URL_EXPIRATION_MINUTES=60

docs/README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@
1212

1313
### Customization
1414

15-
- Are you interested in a simple task with barebones HTML files? Reference the **[simple static task](../examples/static_static_task/)**.
15+
- Are you interested in a simple task with barebones HTML files? Reference the **[simple static task](/examples/static_static_task/)**.
1616

17-
- Are you interested in building a rich frontend? Learn about how you can create a **[simple React task](../examples/static_react_task/)**.
18-
- Reference the docs for the **[`mephisto-task` helper package](../packages/mephisto-task/README.md)** for interfacing with the Mephisto server.
19-
- You may also want to use components offered in the **[`annotation-toolkit` component library](../packages/annotation-toolkit/README.md)** to get up-and-running quick. The components of the library can be **[demoed in the storybook](https://annotation-toolkit-storybook.vercel.app/)**.
17+
- Are you interested in building a rich frontend? Learn about how you can create a **[simple React task](/examples/static_react_task/)**.
18+
- Reference the docs for the **[`mephisto-task` helper package](/packages/mephisto-task/README.md)** for interfacing with the Mephisto server.
19+
- You may also want to use components offered in the **[`annotation-toolkit` component library](/packages/annotation-toolkit/README.md)** to get up-and-running quick. The components of the library can be **[demoed in the storybook](https://annotation-toolkit-storybook.vercel.app/)**.
2020

21-
- Are you interested in dialogue-based tasks using the ParlAI framework? You may want to check out the **[example ParlAI demo task](../examples/parlai_chat_task_demo/)**. For UI customizations, we heavily use the **[`bootstrap-chat` helper package](../packages/bootstrap-chat/)**, so you may want to reference the documentation for that as well.
21+
- Are you interested in dialogue-based tasks using the ParlAI framework? You may want to check out the **[example ParlAI demo task](/examples/parlai_chat_task_demo/)**. For UI customizations, we heavily use the **[`bootstrap-chat` helper package](/packages/bootstrap-chat/)**, so you may want to reference the documentation for that as well.

examples/README.md

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
-->
66

77
# Examples
8+
89
The Mephisto example folders within contain some sample starter code and tasks to demonstrate potential workflows for setting up and working on new tasks.
910

1011
Mephisto Tasks can be launched (each run is called TaskRun) with a single `docker-compose` command (you will need to have Docker [installed](https://docs.docker.com/engine/install/).)
@@ -70,6 +71,123 @@ A more complex example featuring worker-generated dynamic input: [mnist](/exampl
7071

7172
---
7273

74+
#### 3. Dynamic form-based task
75+
76+
You can create and modify auto-composed form-based tasks using FormComposer example (its full specs are in this [README](/mephisto/generators/form_composer/README.md)).
77+
78+
There are three FormComposer examples:
79+
80+
##### 3.1. Simple form
81+
82+
This is a single-version form containing no variable tokens.
83+
84+
- Default config file: [example_local_mock.yaml](/examples/form_composer_demo/hydra_configs/conf/example_local_mock.yaml).
85+
- Launch command:
86+
```shell
87+
docker-compose -f docker/docker-compose.dev.yml run \
88+
--build \
89+
--publish 3001:3000 \
90+
--rm mephisto_dc \
91+
python /mephisto/examples/form_composer_demo/run_task.py
92+
```
93+
- Browser page (for the first task unit): [http://localhost:3001/?worker_id=x&assignment_id=1](http://localhost:3001/?worker_id=x&assignment_id=1).
94+
- You should see a Bootstrap-themed form with fields and sections corresponding to the form config in its [task_data.json](/examples/form_composer_demo/data/simple/task_data.json) file.
95+
96+
##### 3.2. Dynamic form
97+
98+
Dynamic form means a multi-version form, where versions are generated by varying values of special tokens embedded into the form config.
99+
100+
- Default config file: [dynamic_example_local_mock.yaml](/examples/form_composer_demo/hydra_configs/conf/dynamic_example_local_mock.yaml).
101+
- Launch command:
102+
```shell
103+
docker-compose -f docker/docker-compose.dev.yml run \
104+
--build \
105+
--publish 3001:3000 \
106+
--rm mephisto_dc \
107+
python /mephisto/examples/form_composer_demo/run_task_dynamic.py
108+
```
109+
- Browser page is same as for the Simple form example
110+
111+
There are variations of dynamic form config that use different providers. To try that, change `run_task_dynamic.py` in the launch command to:
112+
113+
- `run_task_dynamic_ec2_prolific.py` for Prolific (requires valid EC2 credentials)
114+
- `run_task_dynamic_ec2_mturk_sandbox.py` for Mechanical Turk sandbox (requires valid EC2 credentials)
115+
116+
##### 3.3. Dynamic form with presigned URLs
117+
118+
This example builds further upon the Dynamic form example. Here we use presigned URLs (i.e. short-lived URLs for S3 AWS files) in the displayed forms, for data security.
119+
120+
- Set up environment variables (in file `docker/envs/env.dev`):
121+
- Required: valid AWS credentials: `AWS_ACCESS_KEY_ID`, `AWS_SECRET_ACCESS_KEY`, and `AWS_DEFAULT_REGION`
122+
- Required: a private S3 bucket with files that you will embed in the example form (either replace dummy URLs in the configs by hand, or automatically generate new ones with `mephisto form_composer_config` command)
123+
- Optional: `S3_URL_EXPIRATION_MINUTES` (default value is 60 minutes)
124+
- Default config file: [dynamic_example_local_mock.yaml](/examples/form_composer_demo/hydra_configs/conf/dynamic_example_local_mock.yaml).
125+
- Create config: see all options for `form_composer_config` command [here](/mephisto/generators/form_composer/README.md#using-formcomposerconfig-utility). Example command:
126+
```shell
127+
docker-compose -f docker/docker-compose.dev.yml run \
128+
--build \
129+
--publish 3001:3000 \
130+
--rm mephisto_dc \
131+
mephisto form_composer_config --verify --directory "/mephisto/examples/form_composer_demo/data/dynamic_presigned_urls"
132+
```
133+
- Launch command after you generated all configs:
134+
```shell
135+
docker-compose -f docker/docker-compose.dev.yml run \
136+
--build \
137+
--publish 3001:3000 \
138+
--rm mephisto_dc \
139+
python /mephisto/examples/form_composer_demo/run_task_dynamic_presigned_urls.py
140+
```
141+
142+
143+
# End-to-end example with AWS
144+
145+
Putting it altogether, let's prepare and launch a task featuring a form containing one embedded file plus a few other fields. Here we'll assume working in directory `/mephisto/examples/form_composer_demo/data/dynamic_presigned_urls`.
146+
147+
- Adjust `dynamic_presigned_urls_example_ec2_prolific.yaml` task config as needed
148+
- Create `form_config.json` file to define your form fields and layout
149+
- it should contain a token named `file_location`
150+
- for more details see `mephisto/generators/form_composer/README.md`
151+
- Create `separate_token_values_config.json` with desired token values
152+
- Specify your AWS credentials
153+
- Create file `docker/aws_credentials` and populate it with AWS keys info (for infrastructure and Mturk)
154+
- Populate your AWS credentials into `docker/envs/env.local` file (for presigning S3 URLs)
155+
- Clone file `docker/docker-compose.dev.yml` as `docker/docker-compose.local.yml`, and point its `env_file` to `envs/env.local`
156+
- Remove content of folder `/tmp` (if you didn't shut the previous Task run correctly)
157+
- Launch docker containers: `docker-compose -f docker/docker-compose.local.yml up`
158+
- SSH into the running container: `docker exec -it mephisto_dc bash`
159+
- Generate your task data config with these commands:
160+
```shell
161+
mephisto form_composer_config \
162+
--directory "/mephisto/examples/form_composer_demo/data/dynamic_presigned_urls" \
163+
--update-file-location-values "https://your-bucket.s3.amazonaws.com/..." \
164+
--use-presigned-urls
165+
166+
mephisto form_composer_config \
167+
--directory "/mephisto/examples/form_composer_demo/data/dynamic_presigned_urls" \
168+
--permutate-separate-tokens
169+
170+
mephisto form_composer_config \
171+
--directory "/mephisto/examples/form_composer_demo/data/dynamic_presigned_urls" \
172+
--extrapolate-token-sets
173+
174+
mephisto form_composer_config \
175+
--directory "/mephisto/examples/form_composer_demo/data/dynamic_presigned_urls" \
176+
--verify
177+
```
178+
- Launch your task:
179+
```shell
180+
cd /mephisto/examples/form_composer_demo && python run_task_dynamic_presigned_urls_ec2_prolific.py
181+
```
182+
- After the Task is completed by all workers, launch task review app and acces it at [http://localhost:8081](http://localhost:8081) (for more details see `mephisto/review_app/README.md`):
183+
```shell
184+
mephisto review_app -h 0.0.0.0 -p 8000 -d True -f True
185+
```
186+
187+
_Note: if a package build was terminated/failed, or related source code was changed, FormComposer needs to be rebuilt with this command: `mephisto scripts form_composer rebuild_all_apps`._
188+
189+
---
190+
73191
# Your Mephisto project
74192

75193
To read on steps for creating your own custom Mephisto task, please refer to README in the main Mephisto repo.
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
These form-based questionnaires are example of FormComposer task generator.
2+
3+
---
4+
5+
## How to run
6+
7+
1. In repo root, launch containers: `docker-compose -f docker/docker-compose.dev.yml up`
8+
2. SSH into running container to run server: `docker exec -it mephisto_dc bash`
9+
3. Inside the container, run the project with either of these commands:
10+
- Simple form: `cd /mephisto/examples/form_composer_demo && python ./run_task.py`
11+
- Dynamic form: `cd /mephisto/examples/form_composer_demo && python ./run_task_dynamic.py`
12+
- Dynamic form with Prolific on EC2: `cd /mephisto/examples/form_composer_demo && python ./run_task_dynamic_ec2_prolific.py`
13+
- Dynamic form with Mturk on EC2: `cd /mephisto/examples/form_composer_demo && python ./run_task_dynamic_ec2_mturk_sandbox.py`
14+
15+
---
16+
17+
## How to configure
18+
19+
1. For simple form config you need to provide FormComposer with one JSON file - a configuration of your form fields. An example is found in `examples/form_composer_demo/data/simple/task_data.json` file.
20+
2. For dynamic form configs you need two JSON files in `examples/form_composer_demo/data/dynamic` directory:
21+
- Form configuration `form_config.json`
22+
- Token sets values `token_sets_values_config.json`
23+
- To generate extrapolated `task_data.json` config, run this command: `mephisto form_composer_config --extrapolate-token-sets True`
24+
- Note that `task_data.json` file will be overwritten with the resulting config
25+
3. To generate `token_sets_values_config.json` file from token values permutations in `separate_token_values_config.json`, run this command: `mephisto form_composer_config --permutate-separate-tokens`
26+
- Note that `token_sets_values_config.json` file will be overwriten with new sets of tokens values
27+
28+
---
29+
30+
#### Form config
31+
32+
For details on how form config is composed, and how its data fields are validated, please see the main FormComposer's [README.md](/mephisto/generators/form_composer/README.md).
File renamed without changes.

0 commit comments

Comments
 (0)