Skip to content

Commit

Permalink
[Form Builder] Factored out config utilities into form_builder_config…
Browse files Browse the repository at this point in the history
… command, added more options, updated README
  • Loading branch information
meta-paul committed Feb 6, 2024
1 parent 397fce5 commit 0da7255
Show file tree
Hide file tree
Showing 25 changed files with 1,092 additions and 671 deletions.
56 changes: 16 additions & 40 deletions examples/form_composer_demo/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
This form-based questionnaire is a simple example of Form Composer task generator.
These form-based questionnaires are example of FormComposer task generator.

---

Expand All @@ -7,50 +7,26 @@ This form-based questionnaire is a simple example of Form Composer task generato
1. In repo root, launch containers: `docker-compose -f docker/docker-compose.dev.yml up`
2. SSH into running container to run server: `docker exec -it mephisto_dc bash`
3. Inside the container, run the project with either of these commands:
- simple form: `cd /mephisto/examples/form_composer_demo && python ./run_task.py`
- dynamic form: `cd /mephisto/examples/form_composer_demo && python ./run_task_dynamic.py`
- dynamic form with Prolific on EC2: `cd /mephisto/examples/form_composer_demo && python ./run_task_dynamic_ec2_prolific.py`
- dynamic form with Mturk on EC2: `cd /mephisto/examples/form_composer_demo && python ./run_task_dynamic_ec2_mturk_sandbox.py`
- Simple form: `cd /mephisto/examples/form_composer_demo && python ./run_task.py`
- Dynamic form: `cd /mephisto/examples/form_composer_demo && python ./run_task_dynamic.py`
- Dynamic form with Prolific on EC2: `cd /mephisto/examples/form_composer_demo && python ./run_task_dynamic_ec2_prolific.py`
- Dynamic form with Mturk on EC2: `cd /mephisto/examples/form_composer_demo && python ./run_task_dynamic_ec2_mturk_sandbox.py`

---

## How to configure

1. For simple form config you need to provide Form Composer with one JSON file - a configuration of your form fields.
An example is found in `examples/form_composer_demo/data/simple/data.json` file.
2. For dynamic form configs you need two JSON files:
- form configuration `examples/form_composer_demo/data/dynamic/form_config.json`
- tokens values `examples/form_composer_demo/data/dynamic/tokens_values_config.json`

Note that during bulding a Task with dynamic form config, the resulting data config will be placed in `data.json` file, i.e. `examples/form_composer_demo/data/dynamic/data.json` (in this example it's already been created and will be overwritten when you build a Task).
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/data.json` file.
2. For dynamic form configs you need two JSON files in `examples/form_composer_demo/data/dynamic` directory:
- Form configuration `form_config.json`
- Token sets values `token_sets_values_config.json`
- To generate extrapolated `data.json` config, run this command: `mephisto form_composer_config --extrapolate-token-sets True`
- Note that `data.json` file will be overwritten with the resulting config
3. To generate `token_sets_values_config.json` file from token values permutations in `single_token_values_config.json`, run this command: `mephisto form_composer_config --permutate-single-tokens True`
- Note that `token_sets_values_config.json` file will be overwriten with new sets of tokens values

---

### Form config

For details on how form config is composed, and how data fields are validated please see the main Form Composer's README.

Here's a sample part of form config:

```json
{
"fields": [
{
"id": "id_name_first",
"label": "First name",
"name": "name_first",
"placeholder": "Type first name",
"title": "First name of a person",
"type": "input",
"validators": {
"required": true,
"minLength": 2,
"maxLength": 20,
"regexp": ["^[a-zA-Z0-9._-]+@mephisto\\.ai$", "ig"]
// or just string "regexp": "^[a-zA-Z0-9._-]+@mephisto\\.ai$"
},
"value": ""
}
]
}
```
#### Form config

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).
4 changes: 2 additions & 2 deletions examples/form_composer_demo/data/dynamic/data.json
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@
"label": "Biography",
"name": "bio",
"placeholder": "",
"tooltip": "Your bio in a few apragraphs",
"tooltip": "Your bio in a few paragraphs",
"type": "textarea",
"validators": {
"required": false
Expand Down Expand Up @@ -470,7 +470,7 @@
"label": "Biography",
"name": "bio",
"placeholder": "",
"tooltip": "Your bio in a few apragraphs",
"tooltip": "Your bio in a few paragraphs",
"type": "textarea",
"validators": {
"required": false
Expand Down
9 changes: 3 additions & 6 deletions examples/form_composer_demo/data/dynamic/form_config.json
Original file line number Diff line number Diff line change
Expand Up @@ -151,10 +151,10 @@
{
"help": "",
"id": "id_bio",
"label": "Biography",
"label": "Biography since age of {{ since_age }}",
"name": "bio",
"placeholder": "",
"tooltip": "Your bio in a few apragraphs",
"tooltip": "Your bio in a few paragraphs",
"type": "textarea",
"validators": {
"required": false
Expand Down Expand Up @@ -249,7 +249,7 @@
"placeholder": "Select a file",
"tooltip": "Your profile photo",
"type": "file",
"validators": {"required": true, "fileExtension": ["jpg", "jpeg", "png"]},
"validators": {"required": true, "fileExtension": ["png", "jpg", "jpeg"]},
"value": ""
},
{
Expand Down Expand Up @@ -285,17 +285,14 @@
{
"fields": [
{
"help": "",
"id": "id_motto",
"label": "Personal Motto",
"name": "motto",
"placeholder": "",
"tooltip": "Your personal motto",
"type": "input",
"validators": {
"required": true
},
"value": ""
}
],
"help": "Please type in your favorite personal motto"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"company_name": ["Facebook", "Mephisto"],
"since_age": [18]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[
{
"tokens_values": {
"company_name": "Mephisto",
"since_age": 18
}
},
{
"tokens_values": {
"company_name": "Facebook",
"since_age": 18
}
}
]
12 changes: 0 additions & 12 deletions examples/form_composer_demo/data/dynamic/tokens_values_config.json

This file was deleted.

4 changes: 2 additions & 2 deletions examples/form_composer_demo/data/simple/data.json
Original file line number Diff line number Diff line change
Expand Up @@ -144,10 +144,10 @@
{
"help": "",
"id": "id_bio",
"label": "Biography",
"label": "Biography since age of 18",
"name": "bio",
"placeholder": "",
"tooltip": "Your bio in a few apragraphs",
"tooltip": "Your bio in a few paragraphs",
"type": "textarea",
"validators": {"required": false},
"value": ""
Expand Down
10 changes: 5 additions & 5 deletions examples/form_composer_demo/run_task_dynamic.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

from omegaconf import DictConfig

from mephisto.generators.form_composer.configs_validation.extrapolated_config import (
from mephisto.generators.form_composer.config_validation.task_data_config import (
create_extrapolated_config
)
from mephisto.operations.operator import Operator
Expand Down Expand Up @@ -76,13 +76,13 @@ def generate_data_json_config():
data_path = os.path.join(app_path, "data")

form_config_path = os.path.join(data_path, "dynamic", "form_config.json")
tokens_values_config_path = os.path.join(data_path, "dynamic", "tokens_values_config.json")
extrapolated_form_config_path = os.path.join(data_path, "dynamic", "data.json")
token_sets_values_config_path = os.path.join(data_path, "dynamic", "token_sets_values_config.json")
task_data_config_path = os.path.join(data_path, "dynamic", "data.json")

create_extrapolated_config(
form_config_path=form_config_path,
tokens_values_config_path=tokens_values_config_path,
extrapolated_form_config_path=extrapolated_form_config_path,
token_sets_values_config_path=token_sets_values_config_path,
task_data_config_path=task_data_config_path,
)


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from mephisto.abstractions.blueprints.abstract.static_task.static_blueprint import (
SharedStaticTaskState,
)
from mephisto.generators.form_composer.configs_validation.extrapolated_config import (
from mephisto.generators.form_composer.config_validation.task_data_config import (
create_extrapolated_config
)
from mephisto.operations.operator import Operator
Expand Down Expand Up @@ -94,13 +94,13 @@ def generate_data_json_config():
data_path = os.path.join(app_path, "data")

form_config_path = os.path.join(data_path, "dynamic", "form_config.json")
tokens_values_config_path = os.path.join(data_path, "dynamic", "tokens_values_config.json")
extrapolated_form_config_path = os.path.join(data_path, "dynamic", "data.json")
token_sets_values_config_path = os.path.join(data_path, "dynamic", "token_sets_values_config.json")
task_data_config_path = os.path.join(data_path, "dynamic", "data.json")

create_extrapolated_config(
form_config_path=form_config_path,
tokens_values_config_path=tokens_values_config_path,
extrapolated_form_config_path=extrapolated_form_config_path,
token_sets_values_config_path=token_sets_values_config_path,
task_data_config_path=task_data_config_path,
)


Expand Down
10 changes: 5 additions & 5 deletions examples/form_composer_demo/run_task_dynamic_ec2_prolific.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
SharedStaticTaskState,
)
from mephisto.data_model.qualification import QUAL_GREATER_EQUAL
from mephisto.generators.form_composer.configs_validation.extrapolated_config import (
from mephisto.generators.form_composer.config_validation.task_data_config import (
create_extrapolated_config
)
from mephisto.operations.operator import Operator
Expand Down Expand Up @@ -98,13 +98,13 @@ def generate_data_json_config():
data_path = os.path.join(app_path, "data")

form_config_path = os.path.join(data_path, "dynamic", "form_config.json")
tokens_values_config_path = os.path.join(data_path, "dynamic", "tokens_values_config.json")
extrapolated_form_config_path = os.path.join(data_path, "dynamic", "data.json")
token_sets_values_config_path = os.path.join(data_path, "dynamic", "token_sets_values_config.json")
task_data_config_path = os.path.join(data_path, "dynamic", "data.json")

create_extrapolated_config(
form_config_path=form_config_path,
tokens_values_config_path=tokens_values_config_path,
extrapolated_form_config_path=extrapolated_form_config_path,
token_sets_values_config_path=token_sets_values_config_path,
task_data_config_path=task_data_config_path,
)


Expand Down
Loading

0 comments on commit 0da7255

Please sign in to comment.