1515from pathlib import Path
1616from typing import Iterable
1717from typing import List
18+ from typing import Optional
1819
1920import boto3
2021import cv2
@@ -2084,6 +2085,9 @@ def execute(self):
20842085 file_postfix = "___objects.json"
20852086 else :
20862087 file_postfix = "___pixel.json"
2088+ data ["annotation_mask_filename" ] = f"{ self ._image_name } ___save.png"
2089+ data ["annotation_json_filename" ] = f"{ self ._image_name } { file_postfix } "
2090+
20872091 response = requests .get (
20882092 url = credentials ["annotation_json_path" ]["url" ],
20892093 headers = credentials ["annotation_json_path" ]["headers" ],
@@ -2101,7 +2105,6 @@ def execute(self):
21012105 headers = annotation_blue_map_creds ["headers" ],
21022106 )
21032107 data ["annotation_mask" ] = io .BytesIO (response .content )
2104- data ["annotation_mask_filename" ] = f"{ self ._image_name } ___save.png"
21052108
21062109 self ._response .data = data
21072110
@@ -4485,3 +4488,56 @@ def execute(self):
44854488
44864489 self ._response .data = uploaded , failed_images , duplications
44874490 return self ._response
4491+
4492+
4493+ class DeleteAnnotations (BaseUseCase ):
4494+ POLL_AWAIT_TIME = 2
4495+
4496+ def __init__ (
4497+ self ,
4498+ project : ProjectEntity ,
4499+ folder : FolderEntity ,
4500+ backend_service : SuerannotateServiceProvider ,
4501+ image_names : Optional [List [str ]] = None ,
4502+ ):
4503+ super ().__init__ ()
4504+ self ._project = project
4505+ self ._folder = folder
4506+ self ._image_names = image_names
4507+ self ._backend_service = backend_service
4508+
4509+ def execute (self ) -> Response :
4510+
4511+ if self ._folder .name == "root" and not self ._image_names :
4512+ poll_id = self ._backend_service .delete_image_annotations (
4513+ project_id = self ._project .uuid , team_id = self ._project .team_id ,
4514+ )
4515+ else :
4516+ poll_id = self ._backend_service .delete_image_annotations (
4517+ project_id = self ._project .uuid ,
4518+ team_id = self ._project .team_id ,
4519+ folder_id = self ._folder .uuid ,
4520+ image_names = self ._image_names ,
4521+ )
4522+
4523+ if poll_id :
4524+ timeout_start = time .time ()
4525+ while time .time () < timeout_start + self .POLL_AWAIT_TIME :
4526+ progress = int (
4527+ self ._backend_service .get_annotations_delete_progress (
4528+ project_id = self ._project .uuid ,
4529+ team_id = self ._project .team_id ,
4530+ poll_id = poll_id ,
4531+ ).get ("process" , - 1 )
4532+ )
4533+ if 0 < progress < 100 :
4534+ logger .info (f"Delete annotations in progress { progress } /100" )
4535+ elif 0 > progress :
4536+ self ._response .errors = "Annotations delete fails."
4537+ break
4538+ else :
4539+ logger .info (f"Annotations deleted" )
4540+ break
4541+ else :
4542+ self ._response .errors = AppException ("Invalid image names." )
4543+ return self ._response
0 commit comments