

'''simple docstring'''







from collections import UserDict
from typing import List, Union

from ..utils import (
    add_end_docstrings,
    is_tf_available,
    is_torch_available,
    is_vision_available,
    logging,
    requires_backends,
)
from .base import PIPELINE_INIT_ARGS, Pipeline


if is_vision_available():
      from PIL import Image

      from ..image_utils import load_image

if is_torch_available():
      from ..models.auto.modeling_auto import MODEL_FOR_ZERO_SHOT_IMAGE_CLASSIFICATION_MAPPING

if is_tf_available():
      from ..models.auto.modeling_tf_auto import TF_MODEL_FOR_ZERO_SHOT_IMAGE_CLASSIFICATION_MAPPING
      from ..tf_utils import stable_softmax

__lowerCamelCase		       =    logging.get_logger(__name__)


@add_end_docstrings(_snake_case			)
class 					A__      (      _snake_case			):



    def __init__(					self		,				**UpperCamelCase__       )						->      List[str]:





           '''simple docstring'''
           super().__init__(**UpperCamelCase__       )

           requires_backends(self		,				"""vision"""       )
           self.check_model_type(
               TF_MODEL_FOR_ZERO_SHOT_IMAGE_CLASSIFICATION_MAPPING
               if self.framework == """tf"""
               else MODEL_FOR_ZERO_SHOT_IMAGE_CLASSIFICATION_MAPPING       )



    def __call__(					self		,				UpperCamelCase__		,				**UpperCamelCase__       )						->      Optional[int]:





           '''simple docstring'''
           return super().__call__(UpperCamelCase__		,				**UpperCamelCase__       )



    def 					snake_case_			(					self		,				**UpperCamelCase__       )						->      str:





           '''simple docstring'''
           A_						=      {}
           if "candidate_labels" in kwargs:
                  A_						=      kwargs["""candidate_labels"""]
           if "hypothesis_template" in kwargs:
                  A_						=      kwargs["""hypothesis_template"""]

           return preprocess_params, {}, {}



    def 					snake_case_			(					self		,				UpperCamelCase__		,				UpperCamelCase__=None		,				UpperCamelCase__="This is a photo of {}."       )						->      Union[str, Any]:





           '''simple docstring'''
           A_						=      load_image(UpperCamelCase__       )
           A_						=      self.image_processor(images=[image]		,				return_tensors=self.framework       )
           A_						=      candidate_labels
           A_						=      [hypothesis_template.format(UpperCamelCase__       ) for x in candidate_labels]
           A_						=      self.tokenizer(UpperCamelCase__		,				return_tensors=self.framework		,				padding=UpperCamelCase__       )
           A_						=      [text_inputs]
           return inputs



    def 					snake_case_			(					self		,				UpperCamelCase__       )						->      Optional[int]:





           '''simple docstring'''
           A_						=      model_inputs.pop("""candidate_labels"""       )
           A_						=      model_inputs.pop("""text_inputs"""       )
           if isinstance(text_inputs[0]		,				UpperCamelCase__       ):
                  A_						=      text_inputs[0]
           else:
                  # Batching case.
                  A_						=      text_inputs[0][0]

           A_						=      self.model(**UpperCamelCase__		,				**UpperCamelCase__       )

           A_						=      {
               """candidate_labels""": candidate_labels,
               """logits""": outputs.logits_per_image,
           }
           return model_outputs







    def 					snake_case_			(					self		,				UpperCamelCase__       )						->      List[Any]:





           '''simple docstring'''
           A_						=      model_outputs.pop("""candidate_labels"""       )
           A_						=      model_outputs["""logits"""][0]
           if self.framework == "pt":
                  A_						=      logits.softmax(dim=-1       ).squeeze(-1       )
                  A_						=      probs.tolist()
                  if not isinstance(UpperCamelCase__		,				UpperCamelCase__       ):
                         A_						=      [scores]
           elif self.framework == "tf":
                  A_						=      stable_softmax(UpperCamelCase__		,				axis=-1       )
                  A_						=      probs.numpy().tolist()
           else:
                  raise ValueError(f'''Unsupported framework: {self.framework}'''       )

           A_						=      [
               {"""score""": score, """label""": candidate_label}
               for score, candidate_label in sorted(zip(UpperCamelCase__		,				UpperCamelCase__       )		,				key=lambda UpperCamelCase__       : -x[0]       )
           ]
           return result



'''simple docstring'''







def       UpperCAmelCase__    (      UpperCAmelCase__				)			->			bool:
       return str(UpperCAmelCase__				) == str(UpperCAmelCase__				)[::-1]
def       UpperCAmelCase__    (      UpperCAmelCase__				)			->			int:
       return int(UpperCAmelCase__				) + int(str(UpperCAmelCase__				)[::-1]				)
def       UpperCAmelCase__    (      UpperCAmelCase__ = 1_00_00				)			->			int:
       A_						=      []
       for num in range(1,       UpperCAmelCase__				):
              A_						=      0
              A_						=      num
              while iterations < 50:
                     A_						=      sum_reverse(UpperCAmelCase__				)
                     iterations += 1
                     if is_palindrome(UpperCAmelCase__				):
                            break
              else:
                     lychrel_nums.append(UpperCAmelCase__				)
       return len(UpperCAmelCase__				)


if __name__ == "__main__":
      print(f"""{solution() = }""")
