Create a minimal working project using Toloka-Kit.
Normally, it's more convenient to create a project using Toloka interface. Nevertheless, it's still possible to create a project, write instructions, set up input and output data fields, and configure the task interface via Toloka-Kit.
Connect the Toloka-Kit library to your script.
import toloka.client as toloka
Replace the sample API key with your own one.
toloka_client = toloka.TolokaClient('PlaceYourRealApiKey_Here', 'PRODUCTION');
Configure the task interface using the view_spec
parameter of the TaskSpec class, define input and output data. See comments in the code below and the Task interface section for more information.
image
input field contains URLs of images that need to be labeled.result
output field will receive color values.task_spec = toloka.project.task_spec.TaskSpec( # The input data contains URLs to the images you want to label. input_spec = {'image': toloka.project.field_spec.UrlSpec()}, # The output data contains the 'result' filled with received color values. output_spec = {'result': toloka.project.field_spec.StringSpec()}, # The task interface is created using the HTML/JS/CSS editor. You can select Toloka Template Builder instead if you want. view_spec = toloka.project.ClassicViewSpec( # Define the external assets that the interface requires. assets = { 'script_urls': ['library1.js', 'library2.js'] }, # Specify the interface markup: image src and dimensions, title text, and input field. markup = '''{{img src=image width="400px" height="300px"}} <p class="headerClass">Elephant color:</p> {{field type="input" name="result"}} ''', # Add scripts and styles. script = '', styles = '.headerClass { font-size: 22px; };', # Configure additional settings. settings = { 'showSkip': True, 'showTimer': True, 'showTitle': True, 'showSubmit': True, 'showFullscreen': True, 'showInstructions': True, 'showFinish': True, 'showMessage': True, 'showReward': True } ))
All the code manipulations at steps 3–4 occur in your device memory. The data will only be sent to the server after calling the create_project()
method at step 5.
Specify a public name, description, and instructions that the Tolokers will see.
new_project = toloka.Project(
public_name = '<your_project_public_name>',
public_description = '<your_project_public_description>',
public_instructions = '<your_project_instructions_for_Tolokers>',
task_spec = task_spec
)
This actually creates a project in Toloka.
new_project = toloka_client.create_project(new_project)
The create_project()
request will return the Project class object. You can use its attributes to print the information you need.
print(new_project.id)
You should get an output with the created project ID which looks like this.
120798
import toloka.client as tolokatoloka_client = toloka.TolokaClient('PlaceYourRealApiKey_Here', 'PRODUCTION')task_spec = toloka.project.task_spec.TaskSpec( input_spec={'image': toloka.project.field_spec.UrlSpec()}, output_spec={'result': toloka.project.field_spec.StringSpec()}, view_spec=toloka.project.ClassicViewSpec( assets={ 'script_urls': ['library1.js', 'library2.js'] }, markup='''{{img src=image width="400px" height="300px"}} <p class="headerClass">Elephant color:</p> {{field type="input" name="result"}} ''', script='', styles='.headerClass {font-size: 22px;};', settings={ 'showSkip': True, 'showTimer': True, 'showTitle': True, 'showSubmit': True, 'showFullscreen': True, 'showInstructions': True, 'showFinish': True, 'showMessage': True, 'showReward': True } ))new_project = toloka.project.Project( public_name = '<your_project_public_name>', public_description = '<your_project_public_description>', public_instructions = '<your_project_instructions_for_Tolokers>', task_spec = task_spec)new_project = toloka_client.create_project(new_project)print(new_project.id)
Last updated: February 7, 2023