




"""simple docstring"""


# Copyright 2023 The HuggingFace Inc. team. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import numpy as np
import torch

from ..models.clipseg import CLIPSegForImageSegmentation
from ..utils import is_vision_available, requires_backends
from .base import PipelineTool


if is_vision_available():
     from PIL import Image






class 					lowercase(     __a ):







 '''simple docstring'''





 lowercase__ 					=					(
     "This is a tool that creates a segmentation mask of an image according to a label. It cannot create an image."
     "It takes two arguments named `image` which should be the original image, and `label` which should be a text "
     "describing the elements what should be identified in the segmentation mask. The tool returns the mask."
 )
 lowercase__ 					=					"CIDAS/clipseg-rd64-refined"
 lowercase__ 					=					"image_segmenter"
 lowercase__ 					=					CLIPSegForImageSegmentation

 lowercase__ 					=					["image", "text"]
 lowercase__ 					=					["image"]


 def __init__(				self:		Dict,      *a_:		str,      **a_:		Tuple		):




   '''simple docstring'''



   requires_backends(self,      ["""vision"""]		)
   super().__init__(*a_,      **a_		)


 def  UpperCamelCase_   (				self:		Union[str, Any],      a_:		"Image",      a_:		str		):




   '''simple docstring'''



   return self.pre_processor(text=[label],      images=[image],      padding=a_,      return_tensors="""pt"""		)


 def  UpperCamelCase_   (				self:		int,      a_:		Tuple		):




   '''simple docstring'''



   with torch.no_grad():
     _snake_case							:		Dict								=  self.model(**a_		).logits
   return logits


 def  UpperCamelCase_   (				self:		Any,      a_:		Any		):




   '''simple docstring'''



   _snake_case							:		Optional[Any]								=  outputs.cpu().detach().numpy()
   _snake_case							:		Tuple								=  0
   _snake_case							:		Optional[Any]								=  1
   return Image.fromarray((array * 255).astype(np.uinta		)		)








"""simple docstring"""


from __future__ import annotations


def 					UpperCAmelCase__       (snake_case__							:					list[int]		,   snake_case__							:					int    ):
  """simple docstring"""

  if len(snake_case__    ) < k or k < 0:
    raise ValueError("""Invalid Input"""    )
  _snake_case							:		Optional[int]								=  sum(array[:k]    )
  for i in range(len(snake_case__    ) - k    ):
    _snake_case							:		Optional[Any]								=  current_sum - array[i] + array[i + k]
    _snake_case							:		List[str]								=  max(snake_case__		,   snake_case__    )
  return max_sum


if __name__ == "__main__":
     from doctest import testmod
     from random import randint

     testmod()
     A_						=				[randint(-10_00, 10_00) for i in range(1_00)]
     A_						=				randint(0, 1_10)
     print(F'''The maximum sum of {k} consecutive elements is {max_sum_in_array(array,k)}''')


