1515from pathlib import Path
1616from typing import Iterable
1717from typing import List
18+ from typing import Optional
1819
1920import boto3
2021import cv2
@@ -2081,6 +2082,9 @@ def execute(self):
20812082 file_postfix = "___objects.json"
20822083 else :
20832084 file_postfix = "___pixel.json"
2085+ data ["annotation_mask_filename" ] = f"{ self ._image_name } ___save.png"
2086+ data ["annotation_json_filename" ] = f"{ self ._image_name } { file_postfix } "
2087+
20842088 response = requests .get (
20852089 url = credentials ["annotation_json_path" ]["url" ],
20862090 headers = credentials ["annotation_json_path" ]["headers" ],
@@ -2098,7 +2102,6 @@ def execute(self):
20982102 headers = annotation_blue_map_creds ["headers" ],
20992103 )
21002104 data ["annotation_mask" ] = io .BytesIO (response .content )
2101- data ["annotation_mask_filename" ] = f"{ self ._image_name } ___save.png"
21022105
21032106 self ._response .data = data
21042107
@@ -4482,3 +4485,56 @@ def execute(self):
44824485
44834486 self ._response .data = uploaded , failed_images , duplications
44844487 return self ._response
4488+
4489+
4490+ class DeleteAnnotations (BaseUseCase ):
4491+ POLL_AWAIT_TIME = 2
4492+
4493+ def __init__ (
4494+ self ,
4495+ project : ProjectEntity ,
4496+ folder : FolderEntity ,
4497+ backend_service : SuerannotateServiceProvider ,
4498+ image_names : Optional [List [str ]] = None ,
4499+ ):
4500+ super ().__init__ ()
4501+ self ._project = project
4502+ self ._folder = folder
4503+ self ._image_names = image_names
4504+ self ._backend_service = backend_service
4505+
4506+ def execute (self ) -> Response :
4507+
4508+ if self ._folder .name == "root" and not self ._image_names :
4509+ poll_id = self ._backend_service .delete_image_annotations (
4510+ project_id = self ._project .uuid , team_id = self ._project .team_id ,
4511+ )
4512+ else :
4513+ poll_id = self ._backend_service .delete_image_annotations (
4514+ project_id = self ._project .uuid ,
4515+ team_id = self ._project .team_id ,
4516+ folder_id = self ._folder .uuid ,
4517+ image_names = self ._image_names ,
4518+ )
4519+
4520+ if poll_id :
4521+ timeout_start = time .time ()
4522+ while time .time () < timeout_start + self .POLL_AWAIT_TIME :
4523+ progress = int (
4524+ self ._backend_service .get_annotations_delete_progress (
4525+ project_id = self ._project .uuid ,
4526+ team_id = self ._project .team_id ,
4527+ poll_id = poll_id ,
4528+ ).get ("process" , - 1 )
4529+ )
4530+ if 0 < progress < 100 :
4531+ logger .info (f"Delete annotations in progress { progress } /100" )
4532+ elif 0 > progress :
4533+ self ._response .errors = "Annotations delete fails."
4534+ break
4535+ else :
4536+ logger .info (f"Annotations deleted" )
4537+ break
4538+ else :
4539+ self ._response .errors = AppException ("Invalid image names." )
4540+ return self ._response
0 commit comments