Skip to content

Commit 9f9a55a

Browse files
authored
Merge pull request #222 from superannotateai/sdk_copy_iamge
copy_image changed
2 parents 3a4181a + 998b28c commit 9f9a55a

File tree

4 files changed

+461
-507
lines changed

4 files changed

+461
-507
lines changed

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

Lines changed: 23 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import concurrent.futures
12
import io
23
import json
34
import logging
@@ -564,34 +565,16 @@ def copy_image(
564565
LIMITED_FUNCTIONS[source_project_metadata["project"].project_type]
565566
)
566567

567-
img_bytes = get_image_bytes(project=source_project, image_name=image_name)
568-
569-
s3_response = controller.upload_image_to_s3(
570-
project_name=destination_project, image_path=image_name, image_bytes=img_bytes
571-
)
572-
if s3_response.errors:
573-
raise AppException(s3_response.errors)
574-
image_entity = s3_response.data
575-
del img_bytes
576-
577-
annotation_status = None
578-
if copy_annotation_status:
579-
res = controller.get_image(
580-
project_name=source_project_name,
581-
image_name=image_name,
582-
folder_path=source_folder_name,
583-
)
584-
annotation_status = constances.AnnotationStatus.get_name(
585-
res.annotation_status_code
586-
)
587-
588-
controller.attach_urls(
589-
project_name=destination_project,
590-
files=[image_entity],
591-
folder_name=destination_folder,
592-
annotation_status=annotation_status,
593-
upload_state_code=constances.UploadState.BASIC.value,
568+
response = controller.copy_image(
569+
from_project_name=source_project_name,
570+
from_folder_name=source_folder_name,
571+
to_project_name=destination_project,
572+
to_folder_name=destination_folder,
573+
image_name=image_name,
574+
copy_annotation_status=copy_annotation_status
594575
)
576+
if response.errors:
577+
raise AppException(response.errors)
595578

596579
if include_annotations:
597580
controller.copy_image_annotation_classes(
@@ -729,8 +712,8 @@ def move_images(
729712
source_project: Union[NotEmptyStr, dict],
730713
image_names: Optional[List[NotEmptyStr]],
731714
destination_project: Union[NotEmptyStr, dict],
732-
*_,
733-
**__,
715+
*args,
716+
**kwargs,
734717
):
735718
"""Move images in bulk between folders in a project
736719
@@ -1011,7 +994,7 @@ def delete_image(project: Union[NotEmptyStr, dict], image_name: str):
1011994

1012995
@Trackable
1013996
@validate_arguments
1014-
def get_image_metadata(project: Union[NotEmptyStr, dict], image_name: str, *_, **__):
997+
def get_image_metadata(project: Union[NotEmptyStr, dict], image_name: str, *args, **kwargs):
1015998
"""Returns image metadata
1016999
10171000
:param project: project name or folder path (e.g., "project1/folder1")
@@ -2009,16 +1992,15 @@ def move_image(
20091992
:type copy_pin: bool
20101993
"""
20111994
source_project_name, source_folder_name = extract_project_folder(source_project)
2012-
destination_project_name, destination_folder = extract_project_folder(
2013-
destination_project
2014-
)
2015-
response = controller.move_image(
1995+
destination_project_name, destination_folder = extract_project_folder(destination_project)
1996+
response = controller.copy_image(
20161997
from_project_name=source_project_name,
20171998
from_folder_name=source_folder_name,
20181999
to_project_name=destination_project_name,
20192000
to_folder_name=destination_folder,
20202001
image_name=image_name,
20212002
copy_annotation_status=copy_annotation_status,
2003+
move=True
20222004
)
20232005
if response.errors:
20242006
raise AppException(response.errors)
@@ -2271,13 +2253,11 @@ def attach_image_urls_to_project(
22712253
annotation_status=annotation_status,
22722254
)
22732255
if use_case.is_valid():
2274-
with tqdm(
2275-
total=use_case.attachments_count, desc="Attaching urls"
2276-
) as progress_bar:
2256+
with tqdm(total=use_case.attachments_count, desc="Attaching urls") as progress_bar:
22772257
for _ in use_case.execute():
22782258
progress_bar.update(1)
22792259
uploaded, duplications = use_case.data
2280-
uploaded = [i["name"] for i in uploaded]
2260+
uploaded = [i['name'] for i in uploaded]
22812261
duplications.extend(duplicate_images)
22822262
failed_images = [
22832263
image["name"]
@@ -2324,13 +2304,11 @@ def attach_video_urls_to_project(
23242304
annotation_status=annotation_status,
23252305
)
23262306
if use_case.is_valid():
2327-
with tqdm(
2328-
total=use_case.attachments_count, desc="Attaching urls"
2329-
) as progress_bar:
2307+
with tqdm(total=use_case.attachments_count, desc="Attaching urls") as progress_bar:
23302308
for _ in use_case.execute():
23312309
progress_bar.update(1)
23322310
uploaded, duplications = use_case.data
2333-
uploaded = [i["name"] for i in uploaded]
2311+
uploaded = [i['name'] for i in uploaded]
23342312
duplications.extend(duplicate_images)
23352313
failed_images = [
23362314
image["name"]
@@ -3324,7 +3302,7 @@ def upload_image_to_project(
33243302
image=img,
33253303
annotation_status=annotation_status,
33263304
from_s3_bucket=from_s3_bucket,
3327-
image_quality_in_editor=image_quality_in_editor,
3305+
image_quality_in_editor=image_quality_in_editor
33283306
)
33293307
if response.errors:
33303308
raise AppException(response.errors)
@@ -3535,13 +3513,11 @@ def attach_document_urls_to_project(
35353513
annotation_status=annotation_status,
35363514
)
35373515
if use_case.is_valid():
3538-
with tqdm(
3539-
total=use_case.attachments_count, desc="Attaching urls"
3540-
) as progress_bar:
3516+
with tqdm(total=use_case.attachments_count, desc="Attaching urls") as progress_bar:
35413517
for _ in use_case.execute():
35423518
progress_bar.update(1)
35433519
uploaded, duplications = use_case.data
3544-
uploaded = [i["name"] for i in uploaded]
3520+
uploaded = [i['name'] for i in uploaded]
35453521
duplications.extend(duplicate_images)
35463522
failed_images = [
35473523
image["name"]

0 commit comments

Comments
 (0)