Skip to content

Commit 289c046

Browse files
committed
Merge remote-tracking branch 'origin/attach_items' into attach_items
# Conflicts: # src/superannotate/lib/app/interface/sdk_interface.py # src/superannotate/lib/core/entities/base.py
2 parents 9e9582a + 628b4a3 commit 289c046

File tree

1 file changed

+41
-50
lines changed

1 file changed

+41
-50
lines changed

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

Lines changed: 41 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@
1212
from typing import Union
1313

1414
import boto3
15+
from pydantic import StrictBool
16+
from pydantic import conlist
17+
from pydantic import parse_obj_as
18+
from pydantic.error_wrappers import ValidationError
19+
from tqdm import tqdm
20+
1521
import lib.core as constances
1622
from lib.app.annotation_helpers import add_annotation_bbox_to_json
1723
from lib.app.annotation_helpers import add_annotation_comment_to_json
@@ -50,12 +56,7 @@
5056
from lib.core.types import PriorityScore
5157
from lib.core.types import Project
5258
from lib.infrastructure.controller import Controller
53-
from pydantic import conlist
54-
from pydantic import parse_obj_as
55-
from pydantic import StrictBool
56-
from pydantic.error_wrappers import ValidationError
5759
from superannotate.logger import get_default_logger
58-
from tqdm import tqdm
5960

6061
logger = get_default_logger()
6162

@@ -1816,12 +1817,6 @@ def attach_image_urls_to_project(
18161817
:return: list of linked image names, list of failed image names, list of duplicate image names
18171818
:rtype: tuple
18181819
"""
1819-
warning_msg = (
1820-
"We're deprecating the attach_image_urls_to_project function. Please use attach_items instead. Learn more."
1821-
"https://superannotate.readthedocs.io/en/stable/superannotate.sdk.html#superannotate.attach_items"
1822-
)
1823-
logger.warning(warning_msg)
1824-
warnings.warn(warning_msg, DeprecationWarning)
18251820
project_name, folder_name = extract_project_folder(project)
18261821
project = Controller.get_default().get_project_metadata(project_name).data
18271822
project_folder_name = project_name + (f"/{folder_name}" if folder_name else "")
@@ -1889,12 +1884,6 @@ def attach_video_urls_to_project(
18891884
:return: attached videos, failed videos, skipped videos
18901885
:rtype: (list, list, list)
18911886
"""
1892-
warning_msg = (
1893-
"We're deprecating the attach_video_urls_to_project function. Please use attach_items instead. Learn more."
1894-
"https://superannotate.readthedocs.io/en/stable/superannotate.sdk.html#superannotate.attach_items"
1895-
)
1896-
logger.warning(warning_msg)
1897-
warnings.warn(warning_msg, DeprecationWarning)
18981887
project_name, folder_name = extract_project_folder(project)
18991888
project = Controller.get_default().get_project_metadata(project_name).data
19001889
project_folder_name = project_name + (f"/{folder_name}" if folder_name else "")
@@ -2755,12 +2744,6 @@ def attach_document_urls_to_project(
27552744
:return: list of attached documents, list of not attached documents, list of skipped documents
27562745
:rtype: tuple
27572746
"""
2758-
warning_msg = (
2759-
"We're deprecating the attach_document_urls_to_project function. Please use attach_items instead. Learn more."
2760-
"https://superannotate.readthedocs.io/en/stable/superannotate.sdk.html#superannotate.attach_items"
2761-
)
2762-
logger.warning(warning_msg)
2763-
warnings.warn(warning_msg, DeprecationWarning)
27642747
project_name, folder_name = extract_project_folder(project)
27652748
project = Controller.get_default().get_project_metadata(project_name).data
27662749
project_folder_name = project_name + (f"/{folder_name}" if folder_name else "")
@@ -3119,8 +3102,8 @@ def search_items(
31193102
@validate_arguments
31203103
def attach_items(
31213104
project: Union[NotEmptyStr, dict],
3122-
attachments: AttachmentArg,
3123-
annotation_status: Optional[AnnotationStatuses] = "NotStarted"
3105+
attachments,
3106+
annotation_status="NotStarted"
31243107
):
31253108
"""Link items from external storage to SuperAnnotate using URLs.
31263109
@@ -3144,33 +3127,41 @@ def attach_items(
31443127
that are already in SuperAnnotate.
31453128
:rtype: tuple
31463129
"""
3147-
attachments = attachments.__root__
31483130
project_name, folder_name = extract_project_folder(project)
3149-
if attachments and isinstance(attachments[0], AttachmentDict):
3150-
unique_attachments = set(attachments)
3151-
duplicate_attachments = [item for item, count in collections.Counter(attachments).items() if count > 1]
3152-
else:
3153-
unique_attachments, duplicate_attachments = get_name_url_duplicated_from_csv(attachments)
3154-
3155-
if duplicate_attachments:
3156-
logger.info("Dropping duplicates.")
3157-
unique_attachments = parse_obj_as(List[AttachmentEntity], unique_attachments)
3158-
if unique_attachments:
3159-
logger.info(f"Attaching {len(unique_attachments)} file(s) to project {project}.")
3160-
response = Controller.get_default().attach_items(
3161-
project_name=project_name,
3162-
folder_name=folder_name,
3163-
attachments=unique_attachments,
3164-
annotation_status=annotation_status,
3131+
3132+
images_to_upload, duplicate_images = get_paths_and_duplicated_from_csv(attachments)
3133+
3134+
attachments_data
3135+
3136+
use_case = Controller.get_default().attach_items(
3137+
project_name=project_name,
3138+
folder_name=folder_name,
3139+
files=ImageSerializer.deserialize(images_to_upload), # noqa: E203
3140+
annotation_status=annotation_status,
3141+
)
3142+
if len(duplicate_images):
3143+
logger.warning(
3144+
constances.ALREADY_EXISTING_FILES_WARNING.format(len(duplicate_images))
31653145
)
3166-
if response.errors:
3167-
raise AppException(response.errors)
31683146

3169-
uploaded, duplicated = response.data
3147+
if use_case.is_valid():
3148+
logger.info(
3149+
constances.ATTACHING_FILES_MESSAGE.format(
3150+
len(images_to_upload), project
3151+
)
3152+
)
3153+
with tqdm(
3154+
total=use_case.attachments_count, desc="Attaching urls"
3155+
) as progress_bar:
3156+
for attached in use_case.execute():
3157+
progress_bar.update(attached)
3158+
uploaded, duplications = use_case.data
31703159
uploaded = [i["name"] for i in uploaded]
3171-
fails = [
3172-
attachment.name
3173-
for attachment in unique_attachments
3174-
if attachment.name not in uploaded and attachment.name not in duplicated
3160+
duplications.extend(duplicate_images)
3161+
failed_images = [
3162+
image["name"]
3163+
for image in images_to_upload
3164+
if image["name"] not in uploaded + duplications
31753165
]
3176-
return uploaded, fails, duplicated
3166+
return uploaded, failed_images, duplications
3167+
raise AppException(use_case.response.errors)

0 commit comments

Comments
 (0)