


'''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

__snake_case							      =     logging.get_logger(__name__)
@add_end_docstrings(A__					)
class    lowercase	(							A__					):

		"""simple docstring"""

		def __init__(		self    ,   **UpperCamelCase_							):

							'''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_							):

							'''simple docstring'''


							return super().__call__(UpperCamelCase_    ,   **UpperCamelCase_							)




		def     lowerCAmelCase__				(		self    ,   **UpperCamelCase_							):

							'''simple docstring'''


							UpperCamelCase__   :Union[str, Any]												= {}
							if "candidate_labels" in kwargs:
												UpperCamelCase__   :int												= kwargs['''candidate_labels''']
							if "hypothesis_template" in kwargs:
												UpperCamelCase__   :Dict												= kwargs['''hypothesis_template''']

							return preprocess_params, {}, {}




		def     lowerCAmelCase__				(		self    ,   UpperCamelCase_    ,   UpperCamelCase_=None    ,   UpperCamelCase_="This is a photo of {}."							):

							'''simple docstring'''


							UpperCamelCase__   :List[Any]												= load_image(UpperCamelCase_							)
							UpperCamelCase__   :List[Any]												= self.image_processor(images=[image]    ,   return_tensors=self.framework							)
							UpperCamelCase__   :List[Any]												= candidate_labels
							UpperCamelCase__   :Optional[int]												= [hypothesis_template.format(UpperCamelCase_							) for x in candidate_labels]
							UpperCamelCase__   :List[Any]												= self.tokenizer(UpperCamelCase_    ,   return_tensors=self.framework    ,   padding=UpperCamelCase_							)
							UpperCamelCase__   :Any												= [text_inputs]
							return inputs




		def     lowerCAmelCase__				(		self    ,   UpperCamelCase_							):

							'''simple docstring'''


							UpperCamelCase__   :Optional[int]												= model_inputs.pop('''candidate_labels'''							)
							UpperCamelCase__   :Any												= model_inputs.pop('''text_inputs'''							)
							if isinstance(text_inputs[0]    ,   UpperCamelCase_							):
												UpperCamelCase__   :Dict												= text_inputs[0]
							else:
												# Batching case.
												UpperCamelCase__   :Any												= text_inputs[0][0]

							UpperCamelCase__   :str												= self.model(**UpperCamelCase_    ,   **UpperCamelCase_							)

							UpperCamelCase__   :Optional[Any]												= {
							    '''candidate_labels''': candidate_labels,
							    '''logits''': outputs.logits_per_image,
							}
							return model_outputs




		def     lowerCAmelCase__				(		self    ,   UpperCamelCase_							):

							'''simple docstring'''


							UpperCamelCase__   :Optional[int]												= model_outputs.pop('''candidate_labels'''							)
							UpperCamelCase__   :List[Any]												= model_outputs['''logits'''][0]
							if self.framework == "pt":
												UpperCamelCase__   :Tuple												= logits.softmax(dim=-1							).squeeze(-1							)
												UpperCamelCase__   :str												= probs.tolist()
												if not isinstance(UpperCamelCase_    ,   UpperCamelCase_							):
																	UpperCamelCase__   :Optional[int]												= [scores]
							elif self.framework == "tf":
												UpperCamelCase__   :Any												= stable_softmax(UpperCamelCase_    ,   axis=-1							)
												UpperCamelCase__   :Tuple												= probs.numpy().tolist()
							else:
												raise ValueError(F'''Unsupported framework: {self.framework}'''							)

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



'''simple docstring'''
__snake_case							      =     65521


def 			a      (			__a   )  ->	int:



					'''simple docstring'''






					UpperCamelCase__   :Tuple												= 1
					UpperCamelCase__   :Any												= 0
					for plain_chr in plain_text:
										UpperCamelCase__   :List[str]												= (a + ord(__a   )) % MOD_ADLER
										UpperCamelCase__   :Tuple												= (b + a) % MOD_ADLER
					return (b << 16) | a