Skip to content

Commit da5b8c7

Browse files
authored
Merge pull request #156 from fastlabel/feature/create-image-task-by-gcp
[Task Create]Impl Integrated Image Task Create API SDK
2 parents e87676e + d1a84b7 commit da5b8c7

File tree

2 files changed

+98
-1
lines changed

2 files changed

+98
-1
lines changed

README.md

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,51 @@ task_id = client.create_image_task(
121121

122122
- You can upload up to a size of 20 MB.
123123

124+
125+
#### Create Integrated Image Task
126+
127+
Create a new task by integrated image.
128+
(Project storage setting should be configured in advance.)
129+
130+
```python
131+
task_id = client.create_integrated_image_task(
132+
project="YOUR_PROJECT_SLUG",
133+
file_path="<integrated-storage-dir>/sample.jpg",
134+
storage_type="gcp",
135+
)
136+
```
137+
138+
Create a new task with pre-defined annotations. (Class should be configured on your project in advance)
139+
140+
```python
141+
task_id = client.create_image_task(
142+
project="YOUR_PROJECT_SLUG",
143+
file_path="<integrated-storage-dir>/sample.jpg",
144+
storage_type="gcp",
145+
annotations=[{
146+
"type": "bbox",
147+
"value": "annotation-value",
148+
"attributes": [
149+
{
150+
"key": "attribute-key",
151+
"value": "attribute-value"
152+
}
153+
],
154+
"points": [
155+
100, # top-left x
156+
100, # top-left y
157+
200, # bottom-right x
158+
200 # bottom-right y
159+
]
160+
}]
161+
)
162+
```
163+
164+
##### Limitation
165+
166+
- You can upload up to a size of 20 MB.
167+
168+
124169
#### Find Task
125170

126171
Find a single task.

fastlabel/__init__.py

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import os
55
import re
66
from concurrent.futures import ThreadPoolExecutor
7-
from typing import List
7+
from typing import List, Literal
88

99
import cv2
1010
import numpy as np
@@ -902,6 +902,58 @@ def create_image_task(
902902

903903
return self.api.post_request(endpoint, payload=payload)
904904

905+
def create_integrated_image_task(
906+
self,
907+
project: str,
908+
storage_type: Literal["gcp"],
909+
file_path: str,
910+
status: str = None,
911+
external_status: str = None,
912+
annotations: list = None,
913+
tags: list = None,
914+
**kwargs,
915+
) -> str:
916+
"""
917+
Create a single integrated image task.
918+
919+
project is slug of your project (Required).
920+
storage type is the type of storage where your file resides (Required). e.g.) gcp
921+
file_path is a path to data in your setting storage bucket. Supported extensions are png, jpg, jpeg (Required).
922+
status can be 'registered', 'completed', 'skipped', 'reviewed', 'sent_back',
923+
'approved', 'declined' (Optional).
924+
external_status can be 'registered', 'completed', 'skipped', 'reviewed',
925+
'sent_back', 'approved', 'declined', 'customer_declined' (Optional).
926+
annotations is a list of annotation to be set in advance (Optional).
927+
tags is a list of tag to be set in advance (Optional).
928+
assignee is slug of assigned user (Optional).
929+
reviewer is slug of review user (Optional).
930+
approver is slug of approve user (Optional).
931+
external_assignee is slug of external assigned user (Optional).
932+
external_reviewer is slug of external review user (Optional).
933+
external_approver is slug of external approve user (Optional).
934+
"""
935+
endpoint = "tasks/integrated-image"
936+
if not utils.is_image_supported_ext(file_path):
937+
raise FastLabelInvalidException(
938+
"Supported extensions are png, jpg, jpeg.", 422
939+
)
940+
941+
payload = {"project": project, "filePath": file_path, "storageType": storage_type}
942+
if status:
943+
payload["status"] = status
944+
if external_status:
945+
payload["externalStatus"] = external_status
946+
if annotations:
947+
for annotation in annotations:
948+
annotation["content"] = file_path
949+
payload["annotations"] = annotations
950+
if tags:
951+
payload["tags"] = tags
952+
953+
self.__fill_assign_users(payload, **kwargs)
954+
955+
return self.api.post_request(endpoint, payload=payload)
956+
905957
def create_image_classification_task(
906958
self,
907959
project: str,

0 commit comments

Comments
 (0)