|
5 | 5 | --> |
6 | 6 |
|
7 | 7 | # Examples |
| 8 | + |
8 | 9 | The Mephisto example folders within contain some sample starter code and tasks to demonstrate potential workflows for setting up and working on new tasks. |
9 | 10 |
|
10 | 11 | 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 |
70 | 71 |
|
71 | 72 | --- |
72 | 73 |
|
| 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 | + |
73 | 191 | # Your Mephisto project |
74 | 192 |
|
75 | 193 | To read on steps for creating your own custom Mephisto task, please refer to README in the main Mephisto repo. |
0 commit comments