Skip to content

Commit d4da250

Browse files
authored
Merge pull request #168 from superannotateai/re-design-sdk
Re design sdk
2 parents 7782be8 + 3848c00 commit d4da250

File tree

16 files changed

+138
-97
lines changed

16 files changed

+138
-97
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# Byte-compiled / optimized / DLL files
22
__pycache__/
3+
*.pyc
34
*.py[cod]
45
*$py.class
56
*mypy*

src/superannotate/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,6 @@
243243
"upload_videos_from_folder_to_project",
244244
# Annotation Section
245245
"create_annotation_class",
246-
"delete_annotation_class",
247246
"prepare_export",
248247
"download_export",
249248
"set_images_annotation_statuses",

src/superannotate/lib/app/helpers.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ def check_types(obj, **kwargs):
131131
if attr_name == "return":
132132
continue
133133
try:
134-
if attr_type.__origin__ is list:
134+
if getattr(attr_type, "__origin__") and attr_type.__origin__ is list:
135135
if attr_type.__args__:
136136
for elem in kwargs[attr_name]:
137137
if type(elem) in attr_type.__args__:
@@ -140,7 +140,7 @@ def check_types(obj, **kwargs):
140140
errors.append(f"Invalid input {attr_name}")
141141
elif not isinstance(kwargs[attr_name], list):
142142
errors.append(f"Argument {attr_name} is not of type {attr_type}")
143-
elif attr_type.__origin__ is Union:
143+
elif getattr(attr_type, "__origin__") and attr_type.__origin__ is Union:
144144
if kwargs.get(attr_name) and not isinstance(
145145
kwargs[attr_name], attr_type.__args__
146146
):

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ def upload_image(image_path: str):
130130

131131
paths = []
132132

133-
if isinstance(extensions,str):
133+
if isinstance(extensions, str):
134134
extensions = extensions.strip().split(",")
135135

136136
for extension in extensions:
@@ -264,7 +264,7 @@ def _upload_annotations(
264264

265265
annotations_path = folder
266266
with tempfile.TemporaryDirectory() as temp_dir:
267-
if format != 'SuperAnnotate':
267+
if format != "SuperAnnotate":
268268
import_annotation(
269269
input_dir=folder,
270270
output_dir=temp_dir,

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

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -462,12 +462,12 @@ def search_folders(
462462
:rtype: list of strs or dicts
463463
"""
464464

465-
if not folder_name:
466-
data = controller.get_project_folders(project).data
467-
else:
468-
data = controller.search_folder(
469-
project_name=project, name=folder_name, include_users=return_metadata
470-
).data
465+
response = controller.search_folders(
466+
project_name=project, folder_name=folder_name, include_users=return_metadata
467+
)
468+
if response.errors:
469+
raise AppException(response.errors)
470+
data = response.data
471471
if return_metadata:
472472
return [BaseSerializers(folder).serialize() for folder in data]
473473
return [folder.name for folder in data]
@@ -1166,9 +1166,11 @@ def unassign_images(project: Union[str, dict], image_names: List[str]):
11661166
"""
11671167
project_name, folder_name = extract_project_folder(project)
11681168

1169-
controller.un_assign_images(
1169+
response = controller.un_assign_images(
11701170
project_name=project_name, folder_name=folder_name, image_names=image_names
11711171
)
1172+
if response.errors:
1173+
raise AppException(response.errors)
11721174

11731175

11741176
@Trackable
@@ -1183,7 +1185,11 @@ def unassign_folder(project_name: str, folder_name: str):
11831185
:param folder_name: folder name to remove assignees
11841186
:type folder_name: str
11851187
"""
1186-
controller.un_assign_folder(project_name=project_name, folder_name=folder_name)
1188+
response = controller.un_assign_folder(
1189+
project_name=project_name, folder_name=folder_name
1190+
)
1191+
if response.errors:
1192+
raise AppException(response.errors)
11871193

11881194

11891195
@Trackable
@@ -2697,7 +2703,18 @@ def stop_model_training(model):
26972703
:return: the metadata of the now, stopped model
26982704
:rtype: dict
26992705
"""
2700-
response = controller.stop_model_training(model["id"])
2706+
2707+
model_id = None
2708+
if isinstance(model, dict):
2709+
model_id = model['id']
2710+
else:
2711+
res = controller.search_models(name=model).data
2712+
if len(res):
2713+
model_id = res[0]['id']
2714+
else:
2715+
raise AppException("Model not found.")
2716+
2717+
response = controller.stop_model_training(model_id=model_id)
27012718

27022719
if not response.errors:
27032720
logger.info("Stopped model training")
@@ -3525,4 +3542,4 @@ def aggregate_annotations_as_df(
35253542
include_tags,
35263543
verbose,
35273544
folder_names,
3528-
)
3545+
)

src/superannotate/lib/app/serializers.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,11 @@ def serialize(self):
2727
data = super().serialize()
2828
users = []
2929
for user in data["users"]:
30-
user["user_role"] = constance.UserRole.get_name(data["user_role"])
30+
user["user_role"] = constance.UserRole.get_name(user["user_role"])
3131
users.append(user)
3232
data["users"] = users
3333
for user in data["pending_invitations"]:
34-
user["user_role"] = constance.UserRole.get_name(data["user_role"])
34+
user["user_role"] = constance.UserRole.get_name(user["user_role"])
3535
return data
3636

3737

src/superannotate/lib/core/conditions.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,20 @@ def __init__(self, key: str, value: Any, condition_type: str):
2020
self._type = condition_type
2121
self._condition_set = [] # type: List[NamedTuple]
2222

23+
@staticmethod
24+
def get_empty_condition():
25+
class EmptyCondition:
26+
def __or__(self, other):
27+
return other
28+
29+
def __and__(self, other):
30+
return other
31+
32+
def build_query(self):
33+
return ""
34+
35+
return EmptyCondition()
36+
2337
def __str__(self):
2438
return f"{self._key}{self._type}{self._value}"
2539

src/superannotate/lib/core/entities.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,11 @@ def __init__(
4747
name: str = None,
4848
project_type: int = None,
4949
description: str = None,
50+
attachment_name: str = None,
51+
attachment_path: str = None,
52+
creator_id: str = None,
53+
entropy_status: int = None,
54+
sharing_status: int = None,
5055
status: int = None,
5156
folder_id: int = None,
5257
upload_state: int = None,
@@ -62,6 +67,11 @@ def __init__(
6267
self.name = name
6368
self.project_type = project_type
6469
self.description = description
70+
self.attachment_name = attachment_name
71+
self.attachment_path = attachment_path
72+
self.creator_id = creator_id
73+
self.entropy_status = entropy_status
74+
self.sharing_status = sharing_status
6575
self.status = status
6676
self.folder_id = folder_id
6777
self.upload_state = upload_state
@@ -92,6 +102,11 @@ def to_dict(self):
92102
"type": self.project_type,
93103
"description": self.description,
94104
"status": self.status,
105+
"attachment_path": self.attachment_path,
106+
"attachment_name": self.attachment_name,
107+
"entropy_status": self.entropy_status,
108+
"sharing_status": self.sharing_status,
109+
"creator_id": self.creator_id,
95110
"folder_id": self.folder_id,
96111
"upload_state": self.upload_state,
97112
"users": self.users,

src/superannotate/lib/core/enums.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ class ProjectType(BaseTitledEnum):
3131

3232

3333
class UserRole(BaseTitledEnum):
34+
SUPER_AMIN = "Superadmin", 1
3435
ADMIN = "Admin", 2
3536
ANNOTATOR = "Annotator", 3
3637
QA = "QA", 4

src/superannotate/lib/core/serviceproviders.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,4 +287,4 @@ def run_segmentation(
287287
def run_prediction(
288288
self, team_id: int, project_id: int, ml_model_id: int, image_ids: list
289289
):
290-
raise NotImplementedError
290+
raise NotImplementedError

0 commit comments

Comments
 (0)