|
12 | 12 | from labelbox.orm.query import results_query_part |
13 | 13 | from labelbox.orm.model import Field, Relationship, Entity |
14 | 14 | from labelbox.orm.db_object import DbObject, experimental |
| 15 | +from labelbox.data.annotation_types import LabelList |
15 | 16 |
|
16 | 17 | if TYPE_CHECKING: |
17 | 18 | from labelbox import MEAPredictionImport |
18 | 19 |
|
19 | 20 | logger = logging.getLogger(__name__) |
20 | 21 |
|
| 22 | +DATAROWS_IMPORT_LIMIT = 25000 |
| 23 | + |
21 | 24 |
|
22 | 25 | class DataSplit(Enum): |
23 | 26 | TRAINING = "TRAINING" |
@@ -122,6 +125,34 @@ def _wait_until_done(self, status_fn, timeout_seconds=120, sleep_time=5): |
122 | 125 | ) |
123 | 126 | time.sleep(sleep_time) |
124 | 127 |
|
| 128 | + def upsert_predictions_and_send_to_project( |
| 129 | + self, |
| 130 | + name: str, |
| 131 | + predictions: LabelList, |
| 132 | + project_id: str, |
| 133 | + priority: Optional[int] = 5, |
| 134 | + ) -> 'MEAPredictionImport': # type: ignore |
| 135 | + """ Upload predictions and creates a batch import to project. |
| 136 | + Args: |
| 137 | + name (str): name of the AnnotationImport job as well as the name of the batch import |
| 138 | + predictions (Iterable): |
| 139 | + iterable of annotation rows |
| 140 | + project_id (str): id of the project to import into |
| 141 | + priority (int): priority of the job |
| 142 | + Returns: |
| 143 | + (AnnotationImport, Project) |
| 144 | + """ |
| 145 | + data_rows_set = set( |
| 146 | + map(lambda x: x.data_row.id, predictions)[:DATAROWS_IMPORT_LIMIT]) |
| 147 | + data_rows = list(data_rows_set) |
| 148 | + project = self.client.get_project(project_id) |
| 149 | + batch = project.create_batch(name, data_rows, priority) |
| 150 | + |
| 151 | + predictions_for_data_rows = filter( |
| 152 | + lambda x: x.data_row.id in data_rows_set, predictions) |
| 153 | + |
| 154 | + return (self.add_predictions(name, predictions_for_data_rows), batch) |
| 155 | + |
125 | 156 | def add_predictions( |
126 | 157 | self, |
127 | 158 | name: str, |
|
0 commit comments