Skip to content

Commit 00b224c

Browse files
Vaghinak BasentsyanVaghinak Basentsyan
authored andcommitted
Added new response type
1 parent 9f9f925 commit 00b224c

File tree

10 files changed

+221
-170
lines changed

10 files changed

+221
-170
lines changed

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

Lines changed: 10 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
import lib.core as constances
1111
import pandas as pd
1212
from lib import __file__ as lib_path
13-
from lib.app.helpers import get_annotation_paths
1413
from lib.app.helpers import split_project_path
1514
from lib.app.input_converters.conversion import import_annotation
1615
from lib.app.interface.base_interface import BaseInterfaceFacade
@@ -19,14 +18,14 @@
1918
from lib.app.interface.sdk_interface import attach_video_urls_to_project
2019
from lib.app.interface.sdk_interface import create_folder
2120
from lib.app.interface.sdk_interface import create_project
21+
from lib.app.interface.sdk_interface import upload_annotations_from_folder_to_project
2222
from lib.app.interface.sdk_interface import upload_images_from_folder_to_project
23+
from lib.app.interface.sdk_interface import upload_preannotations_from_folder_to_project
2324
from lib.app.interface.sdk_interface import upload_videos_from_folder_to_project
2425
from lib.app.serializers import ImageSerializer
2526
from lib.core.entities import ConfigEntity
2627
from lib.infrastructure.controller import Controller
2728
from lib.infrastructure.repositories import ConfigRepository
28-
from tqdm import tqdm
29-
3029

3130
logger = logging.getLogger()
3231
controller = Controller(logger)
@@ -107,13 +106,11 @@ def upload_images(
107106
"""
108107
if not isinstance(extensions, list):
109108
extensions = extensions.split(",")
110-
111109
upload_images_from_folder_to_project(
112110
project,
113111
folder_path=folder,
114112
extensions=extensions,
115113
annotation_status=set_annotation_status,
116-
from_s3_bucket=None,
117114
exclude_file_patterns=exclude_file_patterns,
118115
recursive_subfolders=recursive_subfolders,
119116
image_quality_in_editor=image_quality_in_editor,
@@ -202,7 +199,6 @@ def _upload_annotations(
202199
data_set_name = ""
203200
if not task:
204201
task = "object_detection"
205-
206202
annotations_path = folder
207203
with tempfile.TemporaryDirectory() as temp_dir:
208204
if format != "SuperAnnotate":
@@ -222,22 +218,14 @@ def _upload_annotations(
222218
project_name=project_name,
223219
annotation_classes=json.load(open(classes_path)),
224220
)
225-
annotation_paths = get_annotation_paths(annotations_path)
226-
chunk_size = 10
227-
with tqdm(total=len(annotation_paths)) as progress_bar:
228-
for i in range(0, len(annotation_paths), chunk_size):
229-
response = self.controller.upload_annotations_from_folder(
230-
project_name=project["project"].name,
231-
folder_name=folder_name,
232-
folder_path=annotations_path,
233-
annotation_paths=annotation_paths[
234-
i : i + chunk_size # noqa: E203
235-
],
236-
is_pre_annotations=pre,
237-
)
238-
if response.errors:
239-
logger.warning(response.errors)
240-
progress_bar.update(chunk_size)
221+
if pre:
222+
upload_preannotations_from_folder_to_project(
223+
project_name, annotations_path
224+
)
225+
else:
226+
upload_annotations_from_folder_to_project(
227+
project_name, annotations_path
228+
)
241229
sys.exit(0)
242230

243231
def attach_image_urls(

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

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
from typing import Iterable
1414
from typing import List
1515
from typing import Optional
16+
from typing import Tuple
1617
from typing import Union
1718

1819
import boto3
@@ -1338,7 +1339,9 @@ def get_image_annotations(project: Union[str, dict], image_name: str):
13381339
def upload_images_from_folder_to_project(
13391340
project: Union[str, dict],
13401341
folder_path: Union[str, Path],
1341-
extensions: Optional[Iterable[str]] = constances.DEFAULT_IMAGE_EXTENSIONS,
1342+
extensions: Optional[
1343+
Union[List[str], Tuple[str]]
1344+
] = constances.DEFAULT_IMAGE_EXTENSIONS,
13421345
annotation_status="NotStarted",
13431346
from_s3_bucket=None,
13441347
exclude_file_patterns: Optional[
@@ -1382,8 +1385,8 @@ def upload_images_from_folder_to_project(
13821385
logger.info(
13831386
"When using recursive subfolder parsing same name images in different subfolders will overwrite each other."
13841387
)
1385-
13861388
if not isinstance(extensions, (list, tuple)):
1389+
print(extensions)
13871390
raise AppException(
13881391
"extensions should be a list or a tuple in upload_images_from_folder_to_project"
13891392
)
@@ -1660,7 +1663,9 @@ def prepare_export(
16601663
def upload_videos_from_folder_to_project(
16611664
project: Union[str, dict],
16621665
folder_path: Union[str, Path],
1663-
extensions: Optional[Iterable[str]] = constances.DEFAULT_VIDEO_EXTENSIONS,
1666+
extensions: Optional[
1667+
Union[Tuple[str], List[str]]
1668+
] = constances.DEFAULT_VIDEO_EXTENSIONS,
16641669
exclude_file_patterns: Optional[Iterable[str]] = (),
16651670
recursive_subfolders: Optional[StrictBool] = False,
16661671
target_fps: Optional[int] = None,

src/superannotate/lib/core/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@
5555
TOKEN_UUID = "token"
5656

5757

58+
DEPRECATED_VIDEO_PROJECTS_MESSAGE = "The function does not support projects containing videos attached with URLs"
59+
5860
__version__ = "?"
5961

6062
__alL__ = (
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
from typing import Dict
2+
from typing import List
3+
from typing import Optional
4+
from typing import Union
5+
6+
from lib.core.exceptions import AppException
7+
from pydantic import BaseModel
8+
from pydantic import Extra
9+
10+
11+
class UserLimits(BaseModel):
12+
super_user_limit: int
13+
project_limit: int
14+
folder_limit: int
15+
16+
def has_enough_slots(self, count: int):
17+
if count > self.super_user_limit:
18+
raise AppException(
19+
"The number of items you want to upload exceeds the limit of your subscription plan."
20+
)
21+
if count > self.project_limit:
22+
raise AppException(
23+
"You have exceeded the limit of 500 000 items per project."
24+
)
25+
if count > self.folder_limit:
26+
raise AppException(
27+
"“You have exceeded the limit of 50 000 items per folder."
28+
)
29+
return True
30+
31+
32+
class UploadAnnotationAuthData(BaseModel):
33+
access_key: str
34+
secret_key: str
35+
session_token: str
36+
region: str
37+
bucket: str
38+
images: Dict[int, dict]
39+
40+
class Config:
41+
extra = Extra.allow
42+
fields = {
43+
"access_key": "accessKeyId",
44+
"secret_key": "secretAccessKey",
45+
"session_token": "sessionToken",
46+
"region": "region",
47+
}
48+
49+
def __init__(self, **data):
50+
credentials = data["creds"]
51+
data.update(credentials)
52+
del data["creds"]
53+
super().__init__(**data)
54+
55+
56+
class ServiceResponse(BaseModel):
57+
status: int
58+
reason: str
59+
content: Union[bytes, str]
60+
data: Optional[Union[UserLimits, UploadAnnotationAuthData]]
61+
62+
def __init__(self, response, content_type):
63+
data = {
64+
"status": response.status_code,
65+
"reason": response.reason,
66+
"content": response.content,
67+
}
68+
if response.ok:
69+
data["data"] = content_type(**response.json())
70+
super().__init__(**data)
71+
72+
@property
73+
def ok(self):
74+
return 199 < self.status < 300

src/superannotate/lib/core/serviceproviders.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
from typing import List
66
from typing import Tuple
77

8+
from lib.core.service_types import ServiceResponse
9+
810

911
class SingleInstanceMetaClass(type):
1012
_instances = {}
@@ -255,7 +257,7 @@ def get_pre_annotation_upload_data(
255257

256258
def get_annotation_upload_data(
257259
self, project_id: int, team_id: int, image_ids: List[int], folder_id: int
258-
):
260+
) -> ServiceResponse:
259261
raise NotImplementedError
260262

261263
def get_templates(self, team_id: int):
@@ -310,3 +312,8 @@ def get_annotations_delete_progress(
310312
self, team_id: int, project_id: int, poll_id: int
311313
):
312314
raise NotImplementedError
315+
316+
def get_limits(
317+
self, team_id: int, project_id: int, folder_id: int = None
318+
) -> ServiceResponse:
319+
raise NotImplementedError

0 commit comments

Comments
 (0)