Skip to content

Commit fef3c96

Browse files
Vaghinak BasentsyanVaghinak Basentsyan
authored andcommitted
SDK | Added createdAt, updatedAt for classes in classes.json
1 parent 330c852 commit fef3c96

File tree

10 files changed

+252
-56
lines changed

10 files changed

+252
-56
lines changed

src/superannotate/lib/app/interface/sdk_interface.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,9 @@
4444
from lib.core.enums import ImageQuality
4545
from lib.core.exceptions import AppException
4646
from lib.core.exceptions import AppValidationException
47-
from lib.core.types import ClassesJson
4847
from lib.core.types import AttributeGroup
48+
from lib.core.types import ClassesJson
49+
from lib.core.types import MLModel
4950
from lib.core.types import Project
5051
from lib.infrastructure.controller import Controller
5152
from plotly.subplots import make_subplots
@@ -1884,7 +1885,9 @@ def create_annotation_class(
18841885
"""
18851886
if isinstance(project, Project):
18861887
project = project.dict()
1887-
attribute_groups = list(map(lambda x: x.dict(), attribute_groups)) if attribute_groups else None
1888+
attribute_groups = (
1889+
list(map(lambda x: x.dict(), attribute_groups)) if attribute_groups else None
1890+
)
18881891
response = controller.create_annotation_class(
18891892
project_name=project, name=name, color=color, attribute_groups=attribute_groups
18901893
)
@@ -1941,6 +1944,8 @@ def download_annotation_classes_json(project: str, folder: Union[str, Path]):
19411944
response = controller.download_annotation_classes(
19421945
project_name=project, download_path=folder
19431946
)
1947+
if response.errors:
1948+
raise AppException(response.errors)
19441949
return response.data
19451950

19461951

@@ -2268,7 +2273,6 @@ def download_image(
22682273
)
22692274
if response.errors:
22702275
raise AppException(response.errors)
2271-
logger.info(f"Downloaded image {image_name} to {local_dir_path} ")
22722276
return response.data
22732277

22742278

@@ -2733,7 +2737,7 @@ def stop_model_training(model: dict):
27332737

27342738
@Trackable
27352739
@validate_arguments
2736-
def download_model(model: dict, output_dir: Union[str, Path]):
2740+
def download_model(model: MLModel, output_dir: Union[str, Path]):
27372741
"""Downloads the neural network and related files
27382742
which are the <model_name>.pth/pkl. <model_name>.json, <model_name>.yaml, classes_mapper.json
27392743
@@ -2744,8 +2748,9 @@ def download_model(model: dict, output_dir: Union[str, Path]):
27442748
:return: the metadata of the model
27452749
:rtype: dict
27462750
"""
2747-
2748-
res = controller.download_ml_model(model_data=model, download_path=output_dir)
2751+
res = controller.download_ml_model(
2752+
model_data=model.dict(), download_path=output_dir
2753+
)
27492754
if res.errors:
27502755
logger.error("\n".join([str(error) for error in res.errors]))
27512756
else:

src/superannotate/lib/core/entities.py

Lines changed: 38 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,22 @@ def to_dict(self):
2424
raise NotImplementedError
2525

2626

27+
class BaseTimedEntity(BaseEntity):
28+
def __init__(
29+
self, uuid: Any = None, createdAt: str = None, updatedAt: str = None,
30+
):
31+
super().__init__(uuid)
32+
self.createdAt = createdAt
33+
self.updatedAt = updatedAt
34+
35+
def to_dict(self):
36+
return {
37+
"id": self.uuid,
38+
"createdAt": self.createdAt,
39+
"updatedAt": self.updatedAt,
40+
}
41+
42+
2743
class ConfigEntity(BaseEntity):
2844
def __init__(self, uuid: str, value: str):
2945
super().__init__(uuid)
@@ -41,10 +57,12 @@ def to_dict(self):
4157
return {"key": self.uuid, "value": self.value}
4258

4359

44-
class ProjectEntity(BaseEntity):
60+
class ProjectEntity(BaseTimedEntity):
4561
def __init__(
4662
self,
4763
uuid: int = None,
64+
createdAt: str = None,
65+
updatedAt: str = None,
4866
team_id: int = None,
4967
name: str = None,
5068
project_type: int = None,
@@ -65,7 +83,7 @@ def __init__(
6583
completed_images_count: int = None,
6684
root_folder_completed_images_count: int = None,
6785
):
68-
super().__init__(uuid)
86+
super().__init__(uuid, createdAt, updatedAt)
6987
self.team_id = team_id
7088
self.name = name
7189
self.project_type = project_type
@@ -100,7 +118,7 @@ def __copy__(self):
100118

101119
def to_dict(self):
102120
return {
103-
"id": self.uuid,
121+
**super().to_dict(),
104122
"team_id": self.team_id,
105123
"name": self.name,
106124
"type": self.project_type,
@@ -175,17 +193,19 @@ def to_dict(self):
175193
}
176194

177195

178-
class FolderEntity(BaseEntity):
196+
class FolderEntity(BaseTimedEntity):
179197
def __init__(
180198
self,
181199
uuid: int = None,
200+
createdAt: str = None,
201+
updatedAt: str = None,
182202
project_id: int = None,
183203
parent_id: int = None,
184204
team_id: int = None,
185205
name: str = None,
186206
folder_users: List[dict] = None,
187207
):
188-
super().__init__(uuid)
208+
super().__init__(uuid, createdAt, updatedAt)
189209
self.team_id = team_id
190210
self.project_id = project_id
191211
self.name = name
@@ -194,6 +214,7 @@ def __init__(
194214

195215
def to_dict(self):
196216
return {
217+
**super().to_dict(),
197218
"id": self.uuid,
198219
"team_id": self.team_id,
199220
"name": self.name,
@@ -301,22 +322,26 @@ def to_dict(self):
301322
return {"uuid": self.uuid, "bytes": self.data, "metadata": self.metadata}
302323

303324

304-
class AnnotationClassEntity(BaseEntity):
325+
class AnnotationClassEntity(BaseTimedEntity):
305326
def __init__(
306327
self,
307328
uuid: int = None,
329+
createdAt: str = None,
330+
updatedAt: str = None,
308331
color: str = None,
309332
count: int = None,
310333
name: str = None,
311334
project_id: int = None,
312335
attribute_groups: Iterable = None,
313336
):
314-
super().__init__(uuid)
337+
super().__init__(uuid, createdAt, updatedAt)
315338
self.color = color
316339
self.count = count
317340
self.name = name
318341
self.project_id = project_id
319342
self.attribute_groups = attribute_groups
343+
self.createdAt = createdAt
344+
self.updatedAt = updatedAt
320345

321346
def __copy__(self):
322347
return AnnotationClassEntity(
@@ -328,7 +353,7 @@ def __copy__(self):
328353

329354
def to_dict(self):
330355
return {
331-
"id": self.uuid,
356+
**super().to_dict(),
332357
"color": self.color,
333358
"count": self.count,
334359
"name": self.name,
@@ -402,12 +427,14 @@ def to_dict(self):
402427
}
403428

404429

405-
class MLModelEntity(BaseEntity):
430+
class MLModelEntity(BaseTimedEntity):
406431
def __init__(
407432
self,
408433
uuid: int = None,
409434
team_id: int = None,
410435
name: str = None,
436+
createdAt: str = None,
437+
updatedAt: str = None,
411438
path: str = None,
412439
config_path: str = None,
413440
model_type: int = None,
@@ -423,7 +450,7 @@ def __init__(
423450
is_global: bool = None,
424451
hyper_parameters: dict = {},
425452
):
426-
super().__init__(uuid=uuid)
453+
super().__init__(uuid, createdAt, updatedAt)
427454
self.name = name
428455
self.path = path
429456
self.team_id = team_id
@@ -443,7 +470,7 @@ def __init__(
443470

444471
def to_dict(self):
445472
return {
446-
"id": self.uuid,
473+
**super().to_dict(),
447474
"name": self.name,
448475
"team_id": self.team_id,
449476
"description": self.description,

src/superannotate/lib/core/service_types.py

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1+
from typing import Any
12
from typing import Dict
2-
from typing import Optional
3+
from typing import List
34
from typing import Union
45

56
from lib.core.exceptions import AppException
@@ -52,11 +53,35 @@ def __init__(self, **data):
5253
super().__init__(**data)
5354

5455

56+
class DownloadMLModelAuthData(BaseModel):
57+
access_key: str
58+
secret_key: str
59+
session_token: str
60+
region: str
61+
bucket: str
62+
paths: List[str]
63+
64+
class Config:
65+
extra = Extra.allow
66+
fields = {
67+
"access_key": "accessKeyId",
68+
"secret_key": "secretAccessKey",
69+
"session_token": "sessionToken",
70+
"region": "region",
71+
}
72+
73+
def __init__(self, **data):
74+
credentials = data["tokens"]
75+
data.update(credentials)
76+
del data["tokens"]
77+
super().__init__(**data)
78+
79+
5580
class ServiceResponse(BaseModel):
5681
status: int
5782
reason: str
5883
content: Union[bytes, str]
59-
data: Optional[Union[UserLimits, UploadAnnotationAuthData]]
84+
data: Any
6085

6186
def __init__(self, response, content_type):
6287
data = {
@@ -71,3 +96,7 @@ def __init__(self, response, content_type):
7196
@property
7297
def ok(self):
7398
return 199 < self.status < 300
99+
100+
@property
101+
def error(self):
102+
return getattr(self.data, "error", "Unknown error.")

src/superannotate/lib/core/serviceproviders.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,9 @@ def delete_model(self, team_id: int, model_id: int):
286286
def stop_model_training(self, team_id: int, model_id: int):
287287
raise NotImplementedError
288288

289-
def get_ml_model_download_tokens(self, team_id: int, model_id: int):
289+
def get_ml_model_download_tokens(
290+
self, team_id: int, model_id: int
291+
) -> ServiceResponse:
290292
raise NotImplementedError
291293

292294
def run_segmentation(

src/superannotate/lib/core/types.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44

55
from pydantic import BaseModel
66
from pydantic import constr
7-
from pydantic import StrictStr
87
from pydantic import Extra
8+
from pydantic import StrictStr
99

1010

1111
NotEmptyStr = constr(strict=True, min_length=1)
@@ -127,3 +127,14 @@ class Project(BaseModel):
127127

128128
class Config:
129129
extra = Extra.allow
130+
131+
132+
class MLModel(BaseModel):
133+
name: NotEmptyStr
134+
id: int
135+
path: NotEmptyStr
136+
config_path: NotEmptyStr
137+
team_id: Optional[int]
138+
139+
class Config:
140+
extra = Extra.allow

0 commit comments

Comments
 (0)