A project defines the task structure and the visual interface. You can use the template_builder (aliased as tb) to construct complex layouts like SideBySideLayoutV1.
Steps to create a project:
- Define the
main_interface using layout components (e.g., ImageViewV1) and controls (e.g., ButtonRadioGroupFieldV1). - Add plugins like
HotkeysPluginV1 to improve performer efficiency. - Define the
input_specification and output_specification using field types like UrlSpec() and StringSpec(). - Wrap the configuration in a
TemplateBuilderViewSpec. - Assign the
task_spec to the project and call toloka_client.create_project(project).
import toloka.client.project.template_builder as tb
import toloka.client as toloka
# 1. Define Interface
main_interface = tb.SideBySideLayoutV1(
items=[
tb.ImageViewV1(url=tb.InputData(path='image_left'), full_height=True),
tb.ImageViewV1(url=tb.InputData(path='image_right'), full_height=True),
],
controls=tb.ButtonRadioGroupFieldV1(
data=tb.OutputData(path='result'),
label='Which icon do you like more?',
options=[
tb.GroupFieldOption(label='Left', value='LEFT'),
tb.GroupFieldOption(label='Right', value='RIGHT'),
tb.GroupFieldOption(label='Loading error', value='ERROR'),
]
)
)
# 2. Add Plugins
hot_keys_plugin = tb.HotkeysPluginV1(
key_0=tb.SetActionV1(data=tb.OutputData(path='result'), payload='ERROR'),
key_1=tb.SetActionV1(data=tb.OutputData(path='result'), payload='LEFT'),
key_2=tb.SetActionV1(data=tb.OutputData(path='result'), payload='RIGHT'),
)
# 3. Build View Spec
project_interface = toloka.project.view_spec.TemplateBuilderViewSpec(
config=tb.TemplateBuilder(
view=main_interface,
plugins=[hot_keys_plugin],
)
)
# 4. Set Data Specs and Task Spec
input_specification = {
'image_left': toloka.project.field_spec.UrlSpec(),
'image_right': toloka.project.field_spec.UrlSpec(),
}
output_specification = {'result': toloka.project.field_spec.StringSpec()}
project = toloka.Project(
assignments_issuing_type='AUTOMATED',
public_name='Which icon do you like more?',
public_description='Look at the icons and decide which one you like more.',
)
project.task_spec = toloka.project.task_spec.TaskSpec(
input_spec=input_specification,
output_spec=output_specification,
view_spec=project_interface,
)
# 5. Create on Toloka
project = toloka_client.create_project(project)