

# 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.
from typing import TYPE_CHECKING

from ..models.auto import AutoModelForVisionaSeq
from ..utils import requires_backends
from .base import PipelineTool


if TYPE_CHECKING:
 from PIL import Image







class   __lowercase      (_UpperCAmelCase ):
 _UpperCamelCase			  =  """Salesforce/blip-image-captioning-base"""
 _UpperCamelCase			  =  (
     """This is a tool that generates a description of an image. It takes an input named `image` which should be the """
     """image to caption, and returns a text that contains the description in English."""
 )
 _UpperCamelCase			  =  """image_captioner"""
 _UpperCamelCase			  =  AutoModelForVisionaSeq

 _UpperCamelCase			  =  ["""image"""]
 _UpperCamelCase			  =  ["""text"""]
 def __init__(							self      ,							*A_      ,							**A_					)					->List[str]:



       '''simple docstring'''





       requires_backends(self      ,							['''vision''']					)
       super().__init__(*A_      ,							**A_					)
 def 	UpperCamelCase__  (							self      ,							A_					)					->Tuple:



       '''simple docstring'''





       return self.pre_processor(images=A_      ,							return_tensors='''pt'''					)
 def 	UpperCamelCase__  (							self      ,							A_					)					->Optional[int]:



       '''simple docstring'''





       return self.model.generate(**A_					)





 def 	UpperCamelCase__  (							self      ,							A_					)					->Dict:



       '''simple docstring'''





       return self.pre_processor.batch_decode(A_      ,							skip_special_tokens=A_					)[0].strip()





def 		_lowercase (     lowercase__   ,	lowercase__						):
      return (pointa[0] - pointa[0]) ** 2 + (pointa[1] - pointa[1]) ** 2







def 		_lowercase (     lowercase__   ,	lowercase__=0						):
      return sorted(lowercase__   ,	key=lambda lowercase__						: x[column]						)







def 		_lowercase (     lowercase__   ,	lowercase__   ,	lowercase__=float('''inf'''						)						):

      for i in range(points_counts - 1						):
            for j in range(i + 1   ,	lowercase__						):
                  __lowerCAmelCase					:						List[str]					=					euclidean_distance_sqr(points[i]   ,	points[j]						)
                  if current_dis < min_dis:
                        __lowerCAmelCase					:						Tuple					=					current_dis
      return min_dis







def 		_lowercase (     lowercase__   ,	lowercase__   ,	lowercase__=float('''inf'''						)						):

      for i in range(min(6   ,	points_counts - 1						)   ,	lowercase__						):
            for j in range(max(0   ,	i - 6						)   ,	lowercase__						):
                  __lowerCAmelCase					:						Union[str, Any]					=					euclidean_distance_sqr(points[i]   ,	points[j]						)
                  if current_dis < min_dis:
                        __lowerCAmelCase					:						int					=					current_dis
      return min_dis







def 		_lowercase (     lowercase__   ,	lowercase__   ,	lowercase__						):

      # base case
      if points_counts <= 3:
            return dis_between_closest_pair(lowercase__   ,	lowercase__						)

      # recursion
      __lowerCAmelCase					:						Optional[Any]					=					points_counts // 2
      __lowerCAmelCase					:						Optional[Any]					=					closest_pair_of_points_sqr(
          lowercase__   ,	points_sorted_on_y[:mid]   ,	lowercase__						)
      __lowerCAmelCase					:						str					=					closest_pair_of_points_sqr(
          lowercase__   ,	points_sorted_on_y[mid:]   ,	points_counts - mid						)
      __lowerCAmelCase					:						Optional[int]					=					min(lowercase__   ,	lowercase__						)
      __lowerCAmelCase					:						Tuple					=					[]
      for point in points_sorted_on_x:
            if abs(point[0] - points_sorted_on_x[mid][0]						) < closest_pair_dis:
                  cross_strip.append(lowercase__						)

      __lowerCAmelCase					:						List[Any]					=					dis_between_closest_in_strip(
          lowercase__   ,	len(lowercase__						)   ,	lowercase__						)
      return min(lowercase__   ,	lowercase__						)







def 		_lowercase (     lowercase__   ,	lowercase__						):
      __lowerCAmelCase					:						Union[str, Any]					=					column_based_sort(lowercase__   ,	column=0						)
      __lowerCAmelCase					:						Any					=					column_based_sort(lowercase__   ,	column=1						)
      return (
          closest_pair_of_points_sqr(
              lowercase__   ,	lowercase__   ,	lowercase__						)
      ) ** 0.5


if __name__ == "__main__":
 _UpperCamelCase 			=		[(2, 3), (12, 30), (40, 50), (5, 1), (12, 10), (3, 4)]
 print("Distance:", closest_pair_of_points(points, len(points)))


