Skip to content

Commit ddf25ce

Browse files
authored
Merge pull request #15 from superannotateai/public_links_dev
Public links implementation
2 parents bf5045c + 49a083a commit ddf25ce

File tree

11 files changed

+412
-18
lines changed

11 files changed

+412
-18
lines changed

docs/source/superannotate.sdk.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ ________
3737
.. autofunction:: superannotate.delete_folders
3838
.. autofunction:: superannotate.rename_folder
3939
.. autofunction:: superannotate.upload_images_to_project
40+
.. autofunction:: superannotate.attach_image_urls_to_project
4041
.. autofunction:: superannotate.upload_images_from_public_urls_to_project
4142
.. autofunction:: superannotate.upload_images_from_google_cloud_to_project
4243
.. autofunction:: superannotate.upload_images_from_azure_blob_to_project

superannotate/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,8 @@ def consensus(*args, **kwargs):
7272
upload_images_from_google_cloud_to_project,
7373
upload_images_from_public_urls_to_project,
7474
upload_images_from_s3_bucket_to_project, upload_images_to_project,
75-
upload_preannotations_from_folder_to_project, upload_video_to_project,
76-
upload_videos_from_folder_to_project
75+
attach_image_urls_to_project, upload_preannotations_from_folder_to_project,
76+
upload_video_to_project, upload_videos_from_folder_to_project
7777
)
7878
from .db.search_projects import search_projects
7979
from .db.teams import (

superannotate/__main__.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ def main():
6262
create_folder(command, further_args)
6363
elif command == "upload-images":
6464
image_upload(command, further_args)
65+
elif command == "attach-image-urls":
66+
attach_image_urls(command, further_args)
6567
elif command == "upload-videos":
6668
video_upload(command, further_args)
6769
elif command in ["upload-preannotations", "upload-annotations"]:
@@ -288,6 +290,31 @@ def image_upload(command_name, args):
288290
)
289291

290292

293+
def attach_image_urls(command_name, args):
294+
parser = argparse.ArgumentParser(prog=_CLI_COMMAND + " " + command_name)
295+
parser.add_argument(
296+
'--project', required=True, help='Project name to upload'
297+
)
298+
parser.add_argument(
299+
'--attachments',
300+
required=True,
301+
help='path to csv file on attachments metadata'
302+
)
303+
parser.add_argument(
304+
'--annotation_status',
305+
required=False,
306+
default="NotStarted",
307+
help=
308+
'Set images\' annotation statuses after upload. Default is NotStarted'
309+
)
310+
args = parser.parse_args(args)
311+
sa.attach_image_urls_to_project(
312+
project=args.project,
313+
attachments=args.attachments,
314+
annotation_status=args.annotation_status
315+
)
316+
317+
291318
def export_project(command_name, args):
292319
parser = argparse.ArgumentParser(prog=_CLI_COMMAND + " " + command_name)
293320
parser.add_argument(

superannotate/common.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@
2929
"Completed": 5,
3030
"Skipped": 6
3131
}
32+
33+
_UPLOAD_STATES_STR_TO_CODES = {"Initial": 1, "Basic": 2, "External": 3}
34+
_UPLOAD_STATES_CODES_TO_STR = {1: "Initial", 2: "Basic", 3: "External"}
35+
3236
_USER_ROLES = {"Admin": 2, "Annotator": 3, "QA": 4, "Customer": 5, "Viewer": 6}
3337
_AVAILABLE_SEGMENTATION_MODELS = ['autonomous', 'generic']
3438
_MODEL_TRAINING_STATUSES = {
@@ -118,6 +122,14 @@ def annotation_status_str_to_int(annotation_status):
118122
return _ANNOTATION_STATUSES[annotation_status]
119123

120124

125+
def upload_state_str_to_int(upload_state):
126+
return _UPLOAD_STATES_STR_TO_CODES[upload_state]
127+
128+
129+
def upload_state_int_to_str(upload_state):
130+
return _UPLOAD_STATES_CODES_TO_STR[upload_state]
131+
132+
121133
def annotation_status_int_to_str(annotation_status):
122134
"""Converts metadata annotation_status int value to a string
123135

superannotate/db/exports.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
from tqdm import tqdm
1313

1414
from ..api import API
15-
from ..common import annotation_status_str_to_int
15+
from ..common import annotation_status_str_to_int, upload_state_int_to_str
1616
from ..exceptions import (
1717
SABaseException, SAExistingExportNameException,
1818
SANonExistingExportNameException
@@ -123,6 +123,11 @@ def prepare_export(
123123
"""
124124
if not isinstance(project, dict):
125125
project = get_project_metadata_bare(project)
126+
upload_state = upload_state_int_to_str(project.get("upload_state"))
127+
if upload_state == "External" and include_fuse == True:
128+
logger.info(
129+
"Include fuse functionality is not supported for projects containing images attached with URLs"
130+
)
126131
team_id, project_id = project["team_id"], project["id"]
127132
if annotation_statuses is None:
128133
annotation_statuses = [2, 3, 4, 5]

superannotate/db/images.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -636,6 +636,12 @@ def download_image(
636636
)
637637

638638
project, project_folder = get_project_and_folder_metadata(project)
639+
upload_state = common.upload_state_int_to_str(project.get("upload_state"))
640+
if upload_state == "External":
641+
raise SABaseException(
642+
0,
643+
"The function does not support projects containing images attached with URLs"
644+
)
639645
img = get_image_bytes(
640646
(project, project_folder), image_name, variant=variant
641647
)
@@ -703,6 +709,13 @@ def get_image_bytes(project, image_name, variant='original'):
703709
:return: io.BytesIO() of the image
704710
:rtype: io.BytesIO()
705711
"""
712+
project, project_folder = get_project_and_folder_metadata(project)
713+
upload_state = common.upload_state_int_to_str(project.get("upload_state"))
714+
if upload_state == "External":
715+
raise SABaseException(
716+
0,
717+
"The function does not support projects containing images attached with URLs"
718+
)
706719
if variant not in ["original", "lores"]:
707720
raise SABaseException(
708721
0, "Image download variant should be either original or lores"

superannotate/db/project_images.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,12 @@ def upload_image_to_project(
5151
:type image_quality_in_editor: str
5252
"""
5353
project, project_folder = get_project_and_folder_metadata(project)
54+
upload_state = common.upload_state_int_to_str(project.get("upload_state"))
55+
if upload_state == "External":
56+
raise SABaseException(
57+
0,
58+
"The function does not support projects containing images attached with URLs"
59+
)
5460
annotation_status = common.annotation_status_str_to_int(annotation_status)
5561
if image_quality_in_editor is None:
5662
image_quality_in_editor = get_project_default_image_quality_in_editor(
@@ -121,8 +127,12 @@ def upload_image_to_project(
121127
else:
122128
project_folder_id = None
123129
__create_image(
124-
[img_name], [key], project, annotation_status, prefix,
125-
[images_info_and_array[2]], project_folder_id
130+
[img_name], [key],
131+
project,
132+
annotation_status,
133+
prefix, [images_info_and_array[2]],
134+
project_folder_id,
135+
upload_state="Basic"
126136
)
127137

128138
while True:

0 commit comments

Comments
 (0)