



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

UpperCamelCase__:   str								=			logging.get_logger(__name__)

@add_end_docstrings(lowerCAmelCase_			)
class 				SCREAMING_SNAKE_CASE(							lowerCAmelCase_			):







	"""simple docstring"""






	def __init__(						self			:     List[str]		,			**__snake_case			:     Optional[int]		)			->		List[Any]:
								super().__init__(**__snake_case		)

								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			:     List[str]		,			__snake_case			:     Union[str, List[str], "Image", List["Image"]]		,			**__snake_case			:     Optional[int]		)			->		Optional[int]:
								return super().__call__(__snake_case		,			**__snake_case		)







	def      A	(						self			:     Any		,			**__snake_case			:     List[str]		)			->		List[Any]:
								UpperCAmelCase :       Union[str, Any] 							=		{}
								if "candidate_labels" in kwargs:
															UpperCAmelCase :       Dict 							=		kwargs['''candidate_labels''']
								if "hypothesis_template" in kwargs:
															UpperCAmelCase :       List[Any] 							=		kwargs['''hypothesis_template''']

								return preprocess_params, {}, {}







	def      A	(						self			:     Any		,			__snake_case			:     Optional[int]		,			__snake_case			:     str=None		,			__snake_case			:     Optional[int]="This is a photo of {}."		)			->		Tuple:
								UpperCAmelCase :       Any 							=		load_image(__snake_case		)
								UpperCAmelCase :       Any 							=		self.image_processor(images=[image]		,			return_tensors=self.framework		)
								UpperCAmelCase :       str 							=		candidate_labels
								UpperCAmelCase :       Dict 							=		[hypothesis_template.format(__snake_case		) for x in candidate_labels]
								UpperCAmelCase :       Dict 							=		self.tokenizer(__snake_case		,			return_tensors=self.framework		,			padding=__snake_case		)
								UpperCAmelCase :       Optional[int] 							=		[text_inputs]
								return inputs







	def      A	(						self			:     str		,			__snake_case			:     Optional[int]		)			->		Optional[Any]:
								UpperCAmelCase :       Optional[Any] 							=		model_inputs.pop('''candidate_labels'''		)
								UpperCAmelCase :       Optional[int] 							=		model_inputs.pop('''text_inputs'''		)
								if isinstance(text_inputs[0]		,			__snake_case		):
															UpperCAmelCase :       Union[str, Any] 							=		text_inputs[0]
								else:
															# Batching case.
															UpperCAmelCase :       Union[str, Any] 							=		text_inputs[0][0]

								UpperCAmelCase :       Optional[int] 							=		self.model(**__snake_case		,			**__snake_case		)

								UpperCAmelCase :       int 							=		{
								    '''candidate_labels''': candidate_labels,
								    '''logits''': outputs.logits_per_image,
								}
								return model_outputs







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

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










"""simple docstring"""






from functools import lru_cache






def      snake_case__   (		__lowerCamelCase				:    int	):
			"""simple docstring"""
			lowerCamelCase__		:		Optional[Any]			=2
			lowerCamelCase__		:		Optional[int]			=set()
			while i * i <= n:
						if n % i:
									i += 1
						else:
									n //= i
									factors.add(__lowerCamelCase	)
			if n > 1:
						factors.add(__lowerCamelCase	)
			return factors






@lru_cache
def      snake_case__   (		__lowerCamelCase				:    int	):
			"""simple docstring"""
			return len(unique_prime_factors(__lowerCamelCase	)	)






def      snake_case__   (		__lowerCamelCase				:    list	):
			"""simple docstring"""
			return len(set(__lowerCamelCase	)	) in (0, 1)






def      snake_case__   (		__lowerCamelCase				:    int	):
			"""simple docstring"""
			lowerCamelCase__		:		Tuple			=2

			while True:
						# Increment each value of a generated range
						lowerCamelCase__		:		Tuple			=[base + i for i in range(__lowerCamelCase	)]

						# Run elements through out unique_prime_factors function
						# Append our target number to the end.
						lowerCamelCase__		:		Optional[Any]			=[upf_len(__lowerCamelCase	) for x in group]
						checker.append(__lowerCamelCase	)

						# If all numbers in the list are equal, return the group variable.
						if equality(__lowerCamelCase	):
									return group

						# Increment our base variable by 1
						base += 1






def      snake_case__   (		__lowerCamelCase				:    int = 4	):
			"""simple docstring"""
			lowerCamelCase__		:		List[Any]			=run(__lowerCamelCase	)
			return results[0] if len(__lowerCamelCase	) else None


if __name__ == "__main__":
		print(solution())




