rapidata 1.10.1__py3-none-any.whl → 2.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of rapidata might be problematic. Click here for more details.
- rapidata/__init__.py +22 -17
- rapidata/api_client/__init__.py +16 -5
- rapidata/api_client/api/coco_api.py +14 -29
- rapidata/api_client/api/dataset_api.py +6 -6
- rapidata/api_client/api/identity_api.py +3 -3
- rapidata/api_client/api/pipeline_api.py +1008 -95
- rapidata/api_client/api/rapid_api.py +6 -6
- rapidata/api_client/api/validation_api.py +12 -42
- rapidata/api_client/models/__init__.py +16 -5
- rapidata/api_client/models/add_campaign_model.py +5 -5
- rapidata/api_client/models/add_validation_text_rapid_model.py +1 -1
- rapidata/api_client/models/age_group.py +5 -4
- rapidata/api_client/models/base_error.py +1 -4
- rapidata/api_client/models/compare_workflow_config.py +9 -24
- rapidata/api_client/models/compare_workflow_config_model.py +9 -29
- rapidata/api_client/models/compare_workflow_config_model_pair_maker_config.py +140 -0
- rapidata/api_client/models/compare_workflow_config_pair_maker_config.py +140 -0
- rapidata/api_client/models/compare_workflow_model.py +7 -3
- rapidata/api_client/models/compare_workflow_model1.py +7 -3
- rapidata/api_client/models/compare_workflow_model1_pair_maker_information.py +140 -0
- rapidata/api_client/models/compare_workflow_model_pair_maker_config.py +140 -0
- rapidata/api_client/models/create_order_model.py +4 -2
- rapidata/api_client/models/create_order_model_user_filters_inner.py +25 -11
- rapidata/api_client/models/custom_user_filter_model.py +98 -0
- rapidata/api_client/models/file_asset_model_metadata_inner.py +8 -22
- rapidata/api_client/models/get_classify_workflow_result_overview_result.py +144 -0
- rapidata/api_client/models/get_pipeline_by_id_result.py +13 -3
- rapidata/api_client/models/identity_read_bridge_token_get202_response.py +140 -0
- rapidata/api_client/models/not_available_yet_result.py +96 -0
- rapidata/api_client/models/online_pair_maker_config.py +98 -0
- rapidata/api_client/models/online_pair_maker_config_model.py +98 -0
- rapidata/api_client/models/online_pair_maker_information.py +100 -0
- rapidata/api_client/models/pipeline_id_workflow_put_request.py +140 -0
- rapidata/api_client/models/pre_arranged_pair_maker_config.py +100 -0
- rapidata/api_client/models/pre_arranged_pair_maker_config_model.py +96 -0
- rapidata/api_client/models/pre_arranged_pair_maker_information.py +102 -0
- rapidata/api_client/models/read_bridge_token_keys_result.py +11 -2
- rapidata/api_client/models/simple_workflow_config.py +7 -26
- rapidata/api_client/models/simple_workflow_config_model.py +4 -28
- rapidata/api_client/models/simple_workflow_get_result_overview_get200_response.py +16 -16
- rapidata/api_client/models/simple_workflow_model1.py +3 -3
- rapidata/api_client/models/update_campaign_model.py +99 -0
- rapidata/api_client/models/validation_import_post_request_blueprint.py +1 -1
- rapidata/api_client_README.md +21 -7
- rapidata/rapidata_client/__init__.py +20 -10
- rapidata/rapidata_client/assets/__init__.py +5 -4
- rapidata/rapidata_client/assets/{media_asset.py → _media_asset.py} +32 -11
- rapidata/rapidata_client/assets/{multi_asset.py → _multi_asset.py} +1 -1
- rapidata/rapidata_client/assets/{text_asset.py → _text_asset.py} +1 -1
- rapidata/rapidata_client/assets/data_type_enum.py +7 -0
- rapidata/rapidata_client/filter/__init__.py +2 -1
- rapidata/rapidata_client/filter/_base_filter.py +10 -0
- rapidata/rapidata_client/filter/age_filter.py +12 -5
- rapidata/rapidata_client/filter/campaign_filter.py +12 -3
- rapidata/rapidata_client/filter/country_filter.py +10 -3
- rapidata/rapidata_client/filter/custom_filter.py +29 -0
- rapidata/rapidata_client/filter/gender_filter.py +12 -5
- rapidata/rapidata_client/filter/language_filter.py +14 -3
- rapidata/rapidata_client/filter/models/age_group.py +26 -0
- rapidata/rapidata_client/filter/models/gender.py +19 -0
- rapidata/rapidata_client/filter/rapidata_filters.py +35 -0
- rapidata/rapidata_client/filter/user_score_filter.py +20 -4
- rapidata/rapidata_client/metadata/__init__.py +5 -5
- rapidata/rapidata_client/metadata/{base_metadata.py → _base_metadata.py} +2 -1
- rapidata/rapidata_client/metadata/{private_text_metadata.py → _private_text_metadata.py} +2 -2
- rapidata/rapidata_client/metadata/{prompt_metadata.py → _prompt_metadata.py} +3 -2
- rapidata/rapidata_client/metadata/{public_text_metadata.py → _public_text_metadata.py} +2 -2
- rapidata/rapidata_client/metadata/{select_words_metadata.py → _select_words_metadata.py} +3 -2
- rapidata/rapidata_client/{dataset/rapidata_dataset.py → order/_rapidata_dataset.py} +7 -8
- rapidata/rapidata_client/order/_rapidata_order_builder.py +365 -0
- rapidata/rapidata_client/order/rapidata_order.py +50 -32
- rapidata/rapidata_client/order/rapidata_order_manager.py +461 -0
- rapidata/rapidata_client/rapidata_client.py +12 -201
- rapidata/rapidata_client/referee/__init__.py +3 -3
- rapidata/rapidata_client/referee/{base_referee.py → _base_referee.py} +3 -3
- rapidata/rapidata_client/referee/{early_stopping_referee.py → _early_stopping_referee.py} +14 -11
- rapidata/rapidata_client/referee/{naive_referee.py → _naive_referee.py} +9 -9
- rapidata/rapidata_client/selection/__init__.py +1 -1
- rapidata/rapidata_client/{filter/base_filter.py → selection/_base_selection.py} +2 -2
- rapidata/rapidata_client/selection/capped_selection.py +15 -5
- rapidata/rapidata_client/selection/conditional_validation_selection.py +17 -4
- rapidata/rapidata_client/selection/demographic_selection.py +18 -7
- rapidata/rapidata_client/selection/labeling_selection.py +10 -3
- rapidata/rapidata_client/selection/rapidata_selections.py +21 -0
- rapidata/rapidata_client/selection/validation_selection.py +11 -4
- rapidata/rapidata_client/settings/__init__.py +9 -2
- rapidata/rapidata_client/settings/_rapidata_setting.py +11 -0
- rapidata/rapidata_client/settings/alert_on_fast_response.py +21 -0
- rapidata/rapidata_client/settings/custom_setting.py +16 -0
- rapidata/rapidata_client/settings/free_text_minimum_characters.py +16 -0
- rapidata/rapidata_client/settings/models/__init__.py +1 -0
- rapidata/rapidata_client/settings/models/translation_behaviour_options.py +14 -0
- rapidata/rapidata_client/settings/no_shuffle.py +16 -0
- rapidata/rapidata_client/settings/play_video_until_the_end.py +16 -0
- rapidata/rapidata_client/settings/rapidata_settings.py +31 -0
- rapidata/rapidata_client/settings/translation_behaviour.py +18 -0
- rapidata/rapidata_client/validation/__init__.py +1 -0
- rapidata/rapidata_client/{dataset/validation_rapid_parts.py → validation/_validation_rapid_parts.py} +7 -6
- rapidata/rapidata_client/validation/_validation_set_builder.py +371 -0
- rapidata/rapidata_client/{dataset → validation}/rapidata_validation_set.py +54 -50
- rapidata/rapidata_client/validation/rapids/__init__.py +1 -0
- rapidata/rapidata_client/validation/rapids/box.py +17 -0
- rapidata/rapidata_client/validation/rapids/rapids.py +94 -0
- rapidata/rapidata_client/validation/rapids/rapids_manager.py +163 -0
- rapidata/rapidata_client/validation/validation_set_manager.py +338 -0
- rapidata/rapidata_client/workflow/__init__.py +8 -6
- rapidata/rapidata_client/workflow/_base_workflow.py +25 -0
- rapidata/rapidata_client/workflow/{classify_workflow.py → _classify_workflow.py} +6 -6
- rapidata/rapidata_client/workflow/{compare_workflow.py → _compare_workflow.py} +10 -16
- rapidata/rapidata_client/workflow/_draw_workflow.py +22 -0
- rapidata/rapidata_client/workflow/_evaluation_workflow.py +26 -0
- rapidata/rapidata_client/workflow/{free_text_workflow.py → _free_text_workflow.py} +10 -16
- rapidata/rapidata_client/workflow/_locate_workflow.py +22 -0
- rapidata/rapidata_client/workflow/{select_words_workflow.py → _select_words_workflow.py} +2 -8
- rapidata/service/credential_manager.py +11 -1
- rapidata/service/openapi_service.py +23 -4
- {rapidata-1.10.1.dist-info → rapidata-2.1.0.dist-info}/METADATA +2 -1
- {rapidata-1.10.1.dist-info → rapidata-2.1.0.dist-info}/RECORD +122 -96
- rapidata/constants.py +0 -1
- rapidata/rapidata_client/dataset/rapid_builders/__init__.py +0 -4
- rapidata/rapidata_client/dataset/rapid_builders/base_rapid_builder.py +0 -33
- rapidata/rapidata_client/dataset/rapid_builders/classify_rapid_builders.py +0 -166
- rapidata/rapidata_client/dataset/rapid_builders/compare_rapid_builders.py +0 -145
- rapidata/rapidata_client/dataset/rapid_builders/rapids.py +0 -33
- rapidata/rapidata_client/dataset/rapid_builders/select_words_rapid_builders.py +0 -124
- rapidata/rapidata_client/dataset/validation_set_builder.py +0 -336
- rapidata/rapidata_client/order/order_builder.py +0 -25
- rapidata/rapidata_client/order/rapidata_order_builder.py +0 -463
- rapidata/rapidata_client/selection/base_selection.py +0 -9
- rapidata/rapidata_client/settings/feature_flags.py +0 -125
- rapidata/rapidata_client/settings/settings.py +0 -124
- rapidata/rapidata_client/simple_builders/__init__.py +0 -0
- rapidata/rapidata_client/simple_builders/simple_classification_builders.py +0 -271
- rapidata/rapidata_client/simple_builders/simple_compare_builders.py +0 -267
- rapidata/rapidata_client/simple_builders/simple_free_text_builders.py +0 -192
- rapidata/rapidata_client/simple_builders/simple_select_words_builders.py +0 -196
- rapidata/rapidata_client/workflow/base_workflow.py +0 -42
- rapidata/rapidata_client/workflow/evaluation_workflow.py +0 -15
- /rapidata/rapidata_client/assets/{base_asset.py → _base_asset.py} +0 -0
- /rapidata/rapidata_client/{dataset → filter/models}/__init__.py +0 -0
- {rapidata-1.10.1.dist-info → rapidata-2.1.0.dist-info}/LICENSE +0 -0
- {rapidata-1.10.1.dist-info → rapidata-2.1.0.dist-info}/WHEEL +0 -0
|
@@ -1,192 +0,0 @@
|
|
|
1
|
-
from rapidata.constants import MAX_TIME_IN_SECONDS_FOR_ONE_SESSION
|
|
2
|
-
from rapidata.rapidata_client.order.rapidata_order import RapidataOrder
|
|
3
|
-
from rapidata.rapidata_client.order.rapidata_order_builder import RapidataOrderBuilder
|
|
4
|
-
from rapidata.rapidata_client.referee.naive_referee import NaiveReferee
|
|
5
|
-
from rapidata.rapidata_client.selection.base_selection import Selection
|
|
6
|
-
from rapidata.rapidata_client.workflow import FreeTextWorkflow
|
|
7
|
-
from rapidata.rapidata_client.selection.validation_selection import ValidationSelection
|
|
8
|
-
from rapidata.rapidata_client.selection.labeling_selection import LabelingSelection
|
|
9
|
-
from rapidata.service.openapi_service import OpenAPIService
|
|
10
|
-
from rapidata.rapidata_client.assets import MediaAsset, TextAsset, BaseAsset
|
|
11
|
-
from rapidata.rapidata_client.filter import Filter, CountryFilter, LanguageFilter
|
|
12
|
-
from rapidata.rapidata_client.settings import Settings, TranslationBehaviour
|
|
13
|
-
|
|
14
|
-
class FreeTextOrderBuilder:
|
|
15
|
-
def __init__(self,
|
|
16
|
-
name: str,
|
|
17
|
-
question: str,
|
|
18
|
-
media_assets: list[BaseAsset],
|
|
19
|
-
openapi_service: OpenAPIService,
|
|
20
|
-
time_effort: int):
|
|
21
|
-
self._order_builder = RapidataOrderBuilder(name=name, openapi_service=openapi_service)
|
|
22
|
-
self._question = question
|
|
23
|
-
self._media_assets = media_assets
|
|
24
|
-
self._referee = NaiveReferee()
|
|
25
|
-
self._settings = Settings()
|
|
26
|
-
self._filters: list[Filter] = []
|
|
27
|
-
self._time_effort = time_effort
|
|
28
|
-
|
|
29
|
-
def responses(self, responses_required: int) -> 'FreeTextOrderBuilder':
|
|
30
|
-
"""Set the number of responses required per datapoint for the free text order. Will default to 10."""
|
|
31
|
-
self._referee = NaiveReferee(responses=responses_required)
|
|
32
|
-
return self
|
|
33
|
-
|
|
34
|
-
def minimum_characters(self, minimum_characters: int) -> 'FreeTextOrderBuilder':
|
|
35
|
-
"""Set the minimum number of characters for the free text."""
|
|
36
|
-
self._settings.free_text_minimum_characters(minimum_characters)
|
|
37
|
-
return self
|
|
38
|
-
|
|
39
|
-
def countries(self, country_codes: list[str]) -> 'FreeTextOrderBuilder':
|
|
40
|
-
"""Set the countries where order will be shown as country codes."""
|
|
41
|
-
self._filters.append(CountryFilter(country_codes))
|
|
42
|
-
return self
|
|
43
|
-
|
|
44
|
-
def languages(self, language_codes: list[str]) -> 'FreeTextOrderBuilder':
|
|
45
|
-
"""Set the languages where order will be shown as language codes."""
|
|
46
|
-
self._filters.append(LanguageFilter(language_codes))
|
|
47
|
-
return self
|
|
48
|
-
|
|
49
|
-
def translation(self, disable: bool = False, show_both: bool = False) -> 'FreeTextOrderBuilder':
|
|
50
|
-
"""Disable the translation of the order.
|
|
51
|
-
Only the question will be translated.
|
|
52
|
-
|
|
53
|
-
Args:
|
|
54
|
-
disable (bool): Whether to disable the translation. Defaults to False.
|
|
55
|
-
show_both (bool): Whether to show the original text alongside the translation. Defaults to False.
|
|
56
|
-
ATTENTION: this can lead to cluttering of the UI if the texts are long, leading to bad results."""
|
|
57
|
-
|
|
58
|
-
if not isinstance(disable, bool) or not isinstance(show_both, bool):
|
|
59
|
-
raise ValueError("disable and show_both must be booleans.")
|
|
60
|
-
|
|
61
|
-
if disable and show_both:
|
|
62
|
-
raise ValueError("You can't disable the translation and show both at the same time.")
|
|
63
|
-
|
|
64
|
-
if show_both:
|
|
65
|
-
self._settings.translation_behaviour(TranslationBehaviour.BOTH)
|
|
66
|
-
return self
|
|
67
|
-
|
|
68
|
-
if disable:
|
|
69
|
-
self._settings.translation_behaviour(TranslationBehaviour.ONLY_ORIGINAL)
|
|
70
|
-
|
|
71
|
-
else:
|
|
72
|
-
self._settings.translation_behaviour(TranslationBehaviour.ONLY_TRANSLATED)
|
|
73
|
-
|
|
74
|
-
return self
|
|
75
|
-
|
|
76
|
-
def run(self, submit: bool = True, disable_link: bool = False) -> 'RapidataOrder':
|
|
77
|
-
"""Run the free text order.
|
|
78
|
-
|
|
79
|
-
Args:
|
|
80
|
-
submit (bool): Whether to submit the order. Defaults to True. \
|
|
81
|
-
Set this to False if you first want to see the order on your dashboard before running it.
|
|
82
|
-
disable_link (bool): Whether to disable the printing of the link to the order. Defaults to False.
|
|
83
|
-
|
|
84
|
-
Returns:
|
|
85
|
-
RapidataOrder: The created free text order."""
|
|
86
|
-
return self.submit(submit=submit, disable_link=disable_link)
|
|
87
|
-
|
|
88
|
-
def submit(self, submit: bool = True, disable_link: bool = False) -> 'RapidataOrder':
|
|
89
|
-
"""Submit the free text order to be labeled.
|
|
90
|
-
|
|
91
|
-
Args:
|
|
92
|
-
submit (bool): Whether to submit the order. Defaults to True. \
|
|
93
|
-
Set this to False if you first want to see the order on your dashboard before running it.
|
|
94
|
-
disable_link (bool): Whether to disable the printing of the link to the order. Defaults to False.
|
|
95
|
-
|
|
96
|
-
Returns:
|
|
97
|
-
RapidataOrder: The created free text order."""
|
|
98
|
-
|
|
99
|
-
if MAX_TIME_IN_SECONDS_FOR_ONE_SESSION//self._time_effort < 1:
|
|
100
|
-
raise ValueError(f"The Labelers only have {MAX_TIME_IN_SECONDS_FOR_ONE_SESSION} seconds to do the task. \
|
|
101
|
-
Your taks is too complex. Try to break it down into simpler tasks.")
|
|
102
|
-
|
|
103
|
-
selection: list[Selection] = [LabelingSelection(amount=MAX_TIME_IN_SECONDS_FOR_ONE_SESSION//self._time_effort)]
|
|
104
|
-
|
|
105
|
-
order = (self._order_builder
|
|
106
|
-
.workflow(
|
|
107
|
-
FreeTextWorkflow(
|
|
108
|
-
question=self._question
|
|
109
|
-
)
|
|
110
|
-
)
|
|
111
|
-
.referee(self._referee)
|
|
112
|
-
.media(self._media_assets)
|
|
113
|
-
.selections(selection)
|
|
114
|
-
.settings(self._settings)
|
|
115
|
-
.filters(self._filters)
|
|
116
|
-
.create(submit=submit, disable_link=disable_link))
|
|
117
|
-
|
|
118
|
-
return order
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
class FreeTextMediaBuilder:
|
|
122
|
-
def __init__(self, name: str, question: str, openapi_service: OpenAPIService):
|
|
123
|
-
self._openapi_service = openapi_service
|
|
124
|
-
self._name = name
|
|
125
|
-
self._question = question
|
|
126
|
-
self._media_assets: list[BaseAsset] = []
|
|
127
|
-
self._time_effort = 20
|
|
128
|
-
|
|
129
|
-
def media(self, media_paths: list[str], time_effort: int = 20) -> FreeTextOrderBuilder:
|
|
130
|
-
"""Set the media assets for the free text order by providing the local paths to the files or a link.
|
|
131
|
-
|
|
132
|
-
Args:
|
|
133
|
-
media_paths (list[str]): Either a local file path or a link.
|
|
134
|
-
time_effort (int): Estimated time in seconds to solve one free text task for the first time. Defaults to 20.
|
|
135
|
-
|
|
136
|
-
Returns:
|
|
137
|
-
FreeTextOrderBuilder: The free text order builder instance.
|
|
138
|
-
|
|
139
|
-
Raises:
|
|
140
|
-
ValueError: If the media paths are not a list of strings."""
|
|
141
|
-
|
|
142
|
-
if not isinstance(media_paths, list) or not all(isinstance(path, str) for path in media_paths):
|
|
143
|
-
raise ValueError("Media paths must be a list of strings, the strings being file paths or image links.")
|
|
144
|
-
|
|
145
|
-
invalid_paths: list[str] = []
|
|
146
|
-
for path in media_paths:
|
|
147
|
-
try:
|
|
148
|
-
self._media_assets.append(MediaAsset(path))
|
|
149
|
-
except FileNotFoundError:
|
|
150
|
-
invalid_paths.append(path)
|
|
151
|
-
|
|
152
|
-
if invalid_paths:
|
|
153
|
-
raise FileNotFoundError(f"Could not find the following files: {invalid_paths}")
|
|
154
|
-
|
|
155
|
-
self._time_effort = time_effort
|
|
156
|
-
return self._build()
|
|
157
|
-
|
|
158
|
-
def text(self, texts: list[str], time_effort: int = 20) -> FreeTextOrderBuilder:
|
|
159
|
-
"""Set the text assets for the free text order by.
|
|
160
|
-
|
|
161
|
-
Args:
|
|
162
|
-
texts (list[str]): The texts to be shown.
|
|
163
|
-
time_effort (int): Estimated time in seconds to solve one free text task for the first time. Defaults to 20.
|
|
164
|
-
|
|
165
|
-
Returns:
|
|
166
|
-
FreeTextOrderBuilder: The free text order builder instance."""
|
|
167
|
-
for text in texts:
|
|
168
|
-
self._media_assets.append(TextAsset(text))
|
|
169
|
-
self._time_effort = time_effort
|
|
170
|
-
return self._build()
|
|
171
|
-
|
|
172
|
-
def _build(self) -> FreeTextOrderBuilder:
|
|
173
|
-
if not self._media_assets:
|
|
174
|
-
raise ValueError("Please provide either a text or an media to be shown with the question")
|
|
175
|
-
return FreeTextOrderBuilder(self._name, self._question, self._media_assets, openapi_service=self._openapi_service, time_effort=self._time_effort)
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
class FreeTextQuestionBuilder:
|
|
179
|
-
def __init__(self, name: str, openapi_service: OpenAPIService):
|
|
180
|
-
self._openapi_service = openapi_service
|
|
181
|
-
self._name = name
|
|
182
|
-
self._question = None
|
|
183
|
-
|
|
184
|
-
def question(self, question: str) -> FreeTextMediaBuilder:
|
|
185
|
-
"""Set the question for the free text order."""
|
|
186
|
-
self._question = question
|
|
187
|
-
return self._build()
|
|
188
|
-
|
|
189
|
-
def _build(self) -> FreeTextMediaBuilder:
|
|
190
|
-
if self._question is None:
|
|
191
|
-
raise ValueError("Question is required")
|
|
192
|
-
return FreeTextMediaBuilder(self._name, self._question, self._openapi_service)
|
|
@@ -1,196 +0,0 @@
|
|
|
1
|
-
from rapidata.constants import MAX_TIME_IN_SECONDS_FOR_ONE_SESSION
|
|
2
|
-
from rapidata.rapidata_client.order.rapidata_order import RapidataOrder
|
|
3
|
-
from rapidata.rapidata_client.order.rapidata_order_builder import RapidataOrderBuilder
|
|
4
|
-
from rapidata.rapidata_client.referee.naive_referee import NaiveReferee
|
|
5
|
-
from rapidata.rapidata_client.selection.base_selection import Selection
|
|
6
|
-
from rapidata.rapidata_client.workflow import SelectWordsWorkflow
|
|
7
|
-
from rapidata.rapidata_client.selection.validation_selection import ValidationSelection
|
|
8
|
-
from rapidata.rapidata_client.selection.labeling_selection import LabelingSelection
|
|
9
|
-
from rapidata.service.openapi_service import OpenAPIService
|
|
10
|
-
from rapidata.rapidata_client.assets import MediaAsset, BaseAsset
|
|
11
|
-
from rapidata.rapidata_client.filter import Filter, CountryFilter, LanguageFilter
|
|
12
|
-
from rapidata.rapidata_client.metadata import SelectWordsMetadata
|
|
13
|
-
from rapidata.rapidata_client.settings import Settings, TranslationBehaviour
|
|
14
|
-
|
|
15
|
-
class SelectWordsOrderBuilder:
|
|
16
|
-
def __init__(self,
|
|
17
|
-
name: str,
|
|
18
|
-
instruction: str,
|
|
19
|
-
media_assets: list[BaseAsset],
|
|
20
|
-
texts: list[SelectWordsMetadata],
|
|
21
|
-
openapi_service: OpenAPIService,
|
|
22
|
-
time_effort: int):
|
|
23
|
-
self._order_builder = RapidataOrderBuilder(name=name, openapi_service=openapi_service)
|
|
24
|
-
self._instruction = instruction
|
|
25
|
-
self._media_assets = media_assets
|
|
26
|
-
self._texts = texts
|
|
27
|
-
self._validation_set_id = None
|
|
28
|
-
self._referee = NaiveReferee()
|
|
29
|
-
self._settings = Settings()
|
|
30
|
-
self._filters: list[Filter] = []
|
|
31
|
-
self._time_effort = time_effort
|
|
32
|
-
|
|
33
|
-
def responses(self, responses_required: int) -> 'SelectWordsOrderBuilder':
|
|
34
|
-
"""Set the number of responses required per datapoint for the order. Will default to 10."""
|
|
35
|
-
self._referee = NaiveReferee(responses=responses_required)
|
|
36
|
-
return self
|
|
37
|
-
|
|
38
|
-
def validation_set(self, validation_set_id: str) -> 'SelectWordsOrderBuilder':
|
|
39
|
-
"""Set the validation set for the order."""
|
|
40
|
-
self._validation_set_id = validation_set_id
|
|
41
|
-
return self
|
|
42
|
-
|
|
43
|
-
def countries(self, country_codes: list[str]) -> 'SelectWordsOrderBuilder':
|
|
44
|
-
"""Set the countries where order will be shown as country codes."""
|
|
45
|
-
self._filters.append(CountryFilter(country_codes))
|
|
46
|
-
return self
|
|
47
|
-
|
|
48
|
-
def languages(self, language_codes: list[str]) -> 'SelectWordsOrderBuilder':
|
|
49
|
-
"""Set the languages where order will be shown as language codes."""
|
|
50
|
-
self._filters.append(LanguageFilter(language_codes))
|
|
51
|
-
return self
|
|
52
|
-
|
|
53
|
-
def wait_for_video_to_finish(self, offset: int = 0) -> 'SelectWordsOrderBuilder':
|
|
54
|
-
"""Allows labeler to only answer once the video has finished playing.
|
|
55
|
-
The offset gets added on top. Can be negative to allow answers before the video ends."""
|
|
56
|
-
self._settings.play_video_until_the_end(offset)
|
|
57
|
-
return self
|
|
58
|
-
|
|
59
|
-
def translation(self, disable: bool = False, show_both: bool = False) -> 'SelectWordsOrderBuilder':
|
|
60
|
-
"""Disable the translation of the order.
|
|
61
|
-
Only the instruction will be translated.
|
|
62
|
-
|
|
63
|
-
Args:
|
|
64
|
-
disable (bool): Whether to disable the translation. Defaults to False.
|
|
65
|
-
show_both (bool): Whether to show the original text alongside the translation. Defaults to False.
|
|
66
|
-
ATTENTION: this can lead to cluttering of the UI if the texts are long, leading to bad results."""
|
|
67
|
-
|
|
68
|
-
if not isinstance(disable, bool) or not isinstance(show_both, bool):
|
|
69
|
-
raise ValueError("disable and show_both must be booleans.")
|
|
70
|
-
|
|
71
|
-
if disable and show_both:
|
|
72
|
-
raise ValueError("You can't disable the translation and show both at the same time.")
|
|
73
|
-
|
|
74
|
-
if show_both:
|
|
75
|
-
self._settings.translation_behaviour(TranslationBehaviour.BOTH)
|
|
76
|
-
return self
|
|
77
|
-
|
|
78
|
-
if disable:
|
|
79
|
-
self._settings.translation_behaviour(TranslationBehaviour.ONLY_ORIGINAL)
|
|
80
|
-
|
|
81
|
-
else:
|
|
82
|
-
self._settings.translation_behaviour(TranslationBehaviour.ONLY_TRANSLATED)
|
|
83
|
-
|
|
84
|
-
return self
|
|
85
|
-
|
|
86
|
-
def run(self, submit: bool = True, disable_link: bool = False) -> 'RapidataOrder':
|
|
87
|
-
"""Run the order.
|
|
88
|
-
|
|
89
|
-
Args:
|
|
90
|
-
submit (bool): Whether to submit the order. Defaults to True. \
|
|
91
|
-
Set this to False if you first want to see the order on your dashboard before running it.
|
|
92
|
-
disable_link (bool): Whether to disable the printing of the link to the order. Defaults to False."""
|
|
93
|
-
|
|
94
|
-
return self.submit(submit=submit, disable_link=disable_link)
|
|
95
|
-
|
|
96
|
-
def submit(self, submit: bool = True, disable_link: bool = False) -> 'RapidataOrder':
|
|
97
|
-
"""Submit the order to be labeled.
|
|
98
|
-
|
|
99
|
-
Args:
|
|
100
|
-
submit (bool): Whether to submit the order. Defaults to True. \
|
|
101
|
-
Set this to False if you first want to see the order on your dashboard before running it.
|
|
102
|
-
disable_link (bool): Whether to disable the printing of the link to the order. Defaults to False."""
|
|
103
|
-
|
|
104
|
-
if (self._validation_set_id and MAX_TIME_IN_SECONDS_FOR_ONE_SESSION//self._time_effort - 1 < 1) or (MAX_TIME_IN_SECONDS_FOR_ONE_SESSION//self._time_effort < 1):
|
|
105
|
-
raise ValueError(f"The Labelers only have {MAX_TIME_IN_SECONDS_FOR_ONE_SESSION} seconds to do the task. \
|
|
106
|
-
Your taks is too complex. Try to break it down into simpler tasks.\
|
|
107
|
-
{'Alternatively remove the validation task' if self._validation_set_id else ''}")
|
|
108
|
-
|
|
109
|
-
selection: list[Selection] = ([ValidationSelection(amount=1, validation_set_id=self._validation_set_id),
|
|
110
|
-
LabelingSelection(amount=MAX_TIME_IN_SECONDS_FOR_ONE_SESSION//self._time_effort - 1)]
|
|
111
|
-
if self._validation_set_id
|
|
112
|
-
else [LabelingSelection(amount=MAX_TIME_IN_SECONDS_FOR_ONE_SESSION//self._time_effort)])
|
|
113
|
-
|
|
114
|
-
order = (self._order_builder
|
|
115
|
-
.workflow(
|
|
116
|
-
SelectWordsWorkflow(
|
|
117
|
-
instruction=self._instruction
|
|
118
|
-
)
|
|
119
|
-
)
|
|
120
|
-
.referee(self._referee)
|
|
121
|
-
.media(self._media_assets, metadata=self._texts)
|
|
122
|
-
.selections(selection)
|
|
123
|
-
.settings(self._settings)
|
|
124
|
-
.filters(self._filters)
|
|
125
|
-
.create(submit=submit, disable_link=disable_link))
|
|
126
|
-
|
|
127
|
-
return order
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
class SelectWordsMediaBuilder:
|
|
131
|
-
def __init__(self, name: str, instruction: str, openapi_service: OpenAPIService):
|
|
132
|
-
self._openapi_service = openapi_service
|
|
133
|
-
self._name = name
|
|
134
|
-
self._instruction = instruction
|
|
135
|
-
self._media_assets: list[BaseAsset] = []
|
|
136
|
-
self._texts: list[SelectWordsMetadata] = []
|
|
137
|
-
self._time_effort = 10
|
|
138
|
-
|
|
139
|
-
def media(self, media_paths: list[str], texts: list[str], time_effort: int = 10) -> SelectWordsOrderBuilder:
|
|
140
|
-
"""Set the media assets for the order by providing the local paths to the audio / video files.
|
|
141
|
-
|
|
142
|
-
Args:
|
|
143
|
-
media_paths (list[str]): A local file path.
|
|
144
|
-
texts (list[str]): The text will be split up by spaces and the labeler will be able to select the words.
|
|
145
|
-
time_effort (int): Estimated time in seconds to solve one task for the first time. Defaults to 10."""
|
|
146
|
-
|
|
147
|
-
if not isinstance(media_paths, list) or not all(isinstance(path, str) for path in media_paths):
|
|
148
|
-
raise ValueError("Media paths must be a list of strings, the strings being file paths.")
|
|
149
|
-
|
|
150
|
-
if not isinstance(texts, list) or not all(isinstance(text, str) for text in texts):
|
|
151
|
-
raise ValueError("texts must be a list of strings.")
|
|
152
|
-
|
|
153
|
-
if not len(media_paths) == len(texts):
|
|
154
|
-
raise ValueError("The number of media paths and texts must be the same.")
|
|
155
|
-
|
|
156
|
-
invalid_paths: list[str] = []
|
|
157
|
-
for path in media_paths:
|
|
158
|
-
try:
|
|
159
|
-
self._media_assets.append(MediaAsset(path))
|
|
160
|
-
except FileNotFoundError:
|
|
161
|
-
invalid_paths.append(path)
|
|
162
|
-
|
|
163
|
-
if invalid_paths:
|
|
164
|
-
raise FileNotFoundError(f"Could not find the following files: {invalid_paths}")
|
|
165
|
-
|
|
166
|
-
self._texts = [SelectWordsMetadata(text) for text in texts]
|
|
167
|
-
|
|
168
|
-
self._time_effort = time_effort
|
|
169
|
-
return self._build()
|
|
170
|
-
|
|
171
|
-
def _build(self) -> SelectWordsOrderBuilder:
|
|
172
|
-
if not self._media_assets:
|
|
173
|
-
raise ValueError("Please provide either a text or an media to be shown with the question")
|
|
174
|
-
return SelectWordsOrderBuilder(self._name,
|
|
175
|
-
self._instruction,
|
|
176
|
-
self._media_assets,
|
|
177
|
-
self._texts,
|
|
178
|
-
openapi_service=self._openapi_service,
|
|
179
|
-
time_effort=self._time_effort)
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
class SelectWordsInstructionBuilder:
|
|
183
|
-
def __init__(self, name: str, openapi_service: OpenAPIService):
|
|
184
|
-
self._openapi_service = openapi_service
|
|
185
|
-
self._name = name
|
|
186
|
-
self._instruction = None
|
|
187
|
-
|
|
188
|
-
def instruction(self, instruction: str) -> SelectWordsMediaBuilder:
|
|
189
|
-
"""Set the instruction for the order."""
|
|
190
|
-
self._instruction = instruction
|
|
191
|
-
return self._build()
|
|
192
|
-
|
|
193
|
-
def _build(self) -> SelectWordsMediaBuilder:
|
|
194
|
-
if self._instruction is None:
|
|
195
|
-
raise ValueError("Instruction is required")
|
|
196
|
-
return SelectWordsMediaBuilder(self._name, self._instruction, self._openapi_service)
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
from abc import ABC, abstractmethod
|
|
2
|
-
from typing import Any
|
|
3
|
-
|
|
4
|
-
from rapidata.api_client.models.simple_workflow_model import SimpleWorkflowModel
|
|
5
|
-
from rapidata.api_client.models.evaluation_workflow_model import EvaluationWorkflowModel
|
|
6
|
-
from rapidata.api_client.models.compare_workflow_model import CompareWorkflowModel
|
|
7
|
-
from rapidata.rapidata_client.settings import Settings
|
|
8
|
-
from rapidata.rapidata_client.referee.base_referee import Referee
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
class Workflow(ABC):
|
|
12
|
-
|
|
13
|
-
def __init__(self, type: str):
|
|
14
|
-
self._type = type
|
|
15
|
-
self._target_country_codes: list[str] = []
|
|
16
|
-
self._feature_flags: Settings = Settings()
|
|
17
|
-
|
|
18
|
-
def to_dict(self) -> dict[str, Any]:
|
|
19
|
-
return {
|
|
20
|
-
"_t": self._type,
|
|
21
|
-
"referee": self._referee.to_dict(),
|
|
22
|
-
"targetCountryCodes": self._target_country_codes,
|
|
23
|
-
"featureFlags": self._feature_flags.to_list(),
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
@abstractmethod
|
|
27
|
-
def to_model(
|
|
28
|
-
self,
|
|
29
|
-
) -> SimpleWorkflowModel | CompareWorkflowModel | EvaluationWorkflowModel:
|
|
30
|
-
pass
|
|
31
|
-
|
|
32
|
-
def referee(self, referee: Referee):
|
|
33
|
-
self._referee = referee
|
|
34
|
-
return self
|
|
35
|
-
|
|
36
|
-
def target_country_codes(self, target_country_codes: list[str]):
|
|
37
|
-
self._target_country_codes = target_country_codes
|
|
38
|
-
return self
|
|
39
|
-
|
|
40
|
-
def feature_flags(self, feature_flags: Settings):
|
|
41
|
-
self._feature_flags = feature_flags
|
|
42
|
-
return self
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
from rapidata.api_client.models.evaluation_workflow_model import EvaluationWorkflowModel
|
|
2
|
-
from rapidata.rapidata_client.workflow.base_workflow import Workflow
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
class EvaluationWorkflow(Workflow):
|
|
6
|
-
"""Workflow to run evaluation orders. This is used internally only and should not be necessary to be used by clients."""
|
|
7
|
-
|
|
8
|
-
def __init__(self, validation_set_id: str):
|
|
9
|
-
super().__init__("EvaluationWorkflow")
|
|
10
|
-
self.validation_set_id = validation_set_id
|
|
11
|
-
|
|
12
|
-
def to_model(self):
|
|
13
|
-
return EvaluationWorkflowModel(
|
|
14
|
-
_t="EvaluationWorkflow", validationSetId=self.validation_set_id
|
|
15
|
-
)
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|