5353from lib .core .serviceproviders import SuerannotateServiceProvider
5454from PIL import UnidentifiedImageError
5555
56- logger = logging .getLogger ()
56+ logger = logging .getLogger ("root" )
5757
5858
5959class BaseUseCase (ABC ):
@@ -3954,7 +3954,7 @@ def __init__(
39543954 self ._folder = folder
39553955
39563956 def validate_project_type (self ):
3957- if self ._project .project_type is not ProjectType .PIXEL :
3957+ if self ._project .project_type is not ProjectType .PIXEL . value :
39583958 raise AppValidationException (
39593959 "Operation not supported for given project type"
39603960 )
@@ -3970,53 +3970,54 @@ def validate_upload_state(self):
39703970 )
39713971
39723972 def execute (self ):
3973- images = self ._service .get_duplicated_images (
3974- project_id = self ._project .uuid ,
3975- team_id = self ._project .team_id ,
3976- folder_id = self ._folder .uuid ,
3977- images = self ._images_list ,
3978- )
3979-
3980- image_ids = [image ["id" ] for image in images ]
3981- image_names = [image ["name" ] for image in images ]
3982-
3983- res = self ._service .run_segmentation (
3984- self ._project .team_id ,
3985- self ._project .uuid ,
3986- model_name = self ._ml_model_name ,
3987- image_ids = image_ids ,
3988- )
3989- if not res .ok :
3990- return self ._response
3991-
3992- succeded_imgs = []
3993- failed_imgs = []
3994- while len (succeded_imgs ) + len (failed_imgs ) != len (image_ids ):
3995- images_metadata = self ._service .get_bulk_images (
3973+ if self .is_valid ():
3974+ images = self ._service .get_duplicated_images (
39963975 project_id = self ._project .uuid ,
39973976 team_id = self ._project .team_id ,
39983977 folder_id = self ._folder .uuid ,
3999- images = image_names ,
3978+ images = self . _images_list ,
40003979 )
40013980
4002- succeded_imgs = [
4003- img ["name" ]
4004- for img in images_metadata
4005- if img ["segmentation_status" ] == 3
4006- ]
4007- failed_imgs = [
4008- img ["name" ]
4009- for img in images_metadata
4010- if img ["segmentation_status" ] == 4
4011- ]
3981+ image_ids = [image ["id" ] for image in images ]
3982+ image_names = [image ["name" ] for image in images ]
40123983
4013- complete_images = succeded_imgs + failed_imgs
4014- logger .info (
4015- f"segmentation complete on { len (complete_images )} / { len (image_ids )} images"
3984+ res = self ._service .run_segmentation (
3985+ self ._project .team_id ,
3986+ self ._project .uuid ,
3987+ model_name = self ._ml_model_name ,
3988+ image_ids = image_ids ,
40163989 )
4017- time .sleep (5 )
3990+ if not res .ok :
3991+ return self ._response
3992+
3993+ succeded_imgs = []
3994+ failed_imgs = []
3995+ while len (succeded_imgs ) + len (failed_imgs ) != len (image_ids ):
3996+ images_metadata = self ._service .get_bulk_images (
3997+ project_id = self ._project .uuid ,
3998+ team_id = self ._project .team_id ,
3999+ folder_id = self ._folder .uuid ,
4000+ images = image_names ,
4001+ )
4002+
4003+ succeded_imgs = [
4004+ img ["name" ]
4005+ for img in images_metadata
4006+ if img ["segmentation_status" ] == 3
4007+ ]
4008+ failed_imgs = [
4009+ img ["name" ]
4010+ for img in images_metadata
4011+ if img ["segmentation_status" ] == 4
4012+ ]
40184013
4019- self ._response .data = (succeded_imgs , failed_imgs )
4014+ complete_images = succeded_imgs + failed_imgs
4015+ logger .info (
4016+ f"segmentation complete on { len (complete_images )} / { len (image_ids )} images"
4017+ )
4018+ time .sleep (5 )
4019+
4020+ self ._response .data = (succeded_imgs , failed_imgs )
40204021 return self ._response
40214022
40224023
@@ -4355,13 +4356,15 @@ def images_to_upload(self):
43554356 paths = self .paths
43564357 filtered_paths = []
43574358 duplicated_paths = []
4358- images = self ._backend_client .get_bulk_images (
4359+
4360+ get_bulk_use_case = GetDuplicateImages (
4361+ service = self ._backend_client ,
43594362 project_id = self ._project .uuid ,
43604363 team_id = self ._project .team_id ,
43614364 folder_id = self ._folder .uuid ,
43624365 images = [Path (image ).name for image in paths ],
43634366 )
4364- image_names = [ image [ "name" ] for image in images ]
4367+ image_names = get_bulk_use_case . execute ()
43654368
43664369 for path in paths :
43674370 not_in_exclude_list = [
@@ -4445,6 +4448,12 @@ def execute(self) -> Response:
44454448 image_names = self ._image_names ,
44464449 )
44474450
4451+ project_folder_name = (
4452+ self ._project .name
4453+ + (f"/{ self ._folder .name } " if self ._folder .name != "root" else "" )
4454+ + "."
4455+ )
4456+
44484457 if response :
44494458 timeout_start = time .time ()
44504459 while time .time () < timeout_start + self .POLL_AWAIT_TIME :
@@ -4461,7 +4470,11 @@ def execute(self) -> Response:
44614470 self ._response .errors = "Annotations delete fails."
44624471 break
44634472 else :
4464- logger .info ("Annotations deleted" )
4473+ logger .info (
4474+ "The annotations have been successfully deleted from "
4475+ + project_folder_name
4476+ )
4477+
44654478 break
44664479 else :
44674480 self ._response .errors = AppException ("Invalid image names or empty folder." )
0 commit comments