


'''simple docstring'''






from typing import Any, Dict, List, Union

from ..utils import add_end_docstrings, is_torch_available, is_vision_available, logging, requires_backends
from .base import PIPELINE_INIT_ARGS, ChunkPipeline


if is_vision_available():
		from PIL import Image

		from ..image_utils import load_image

if is_torch_available():
		import torch

		from transformers.modeling_outputs import BaseModelOutput

		from ..models.auto.modeling_auto import MODEL_FOR_ZERO_SHOT_OBJECT_DETECTION_MAPPING

__UpperCAmelCase       =							logging.get_logger(__name__)




@add_end_docstrings(a__  )
class 		a__    (							a__  ):





							'''simple docstring'''






							def __init__(		self ,   **lowerCamelCase_       )	->							List[str]:
														super().__init__(**lowerCamelCase_       )

														if self.framework == "tf":
																					raise ValueError(F"""The {self.__class__} is only available in PyTorch."""       )

														requires_backends(self ,   '''vision'''       )
														self.check_model_type(lowerCamelCase_       )







							def __call__(		self ,   lowerCamelCase_ ,   lowerCamelCase_ = None ,   **lowerCamelCase_ ,   )	->							Optional[int]:
														if "text_queries" in kwargs:
																					lowerCAmelCase__	       =     kwargs.pop('''text_queries'''       )

														if isinstance(lowerCamelCase_ ,   (str, Image.Image)       ):
																					lowerCAmelCase__	       =     {'''image''': image, '''candidate_labels''': candidate_labels}
														else:
																					lowerCAmelCase__	       =     image
														lowerCAmelCase__	       =     super().__call__(lowerCamelCase_ ,   **lowerCamelCase_       )
														return results







							def   __SCREAMING_SNAKE_CASE							(		self ,   **lowerCamelCase_       )	->							Dict:
														lowerCAmelCase__	       =     {}
														if "threshold" in kwargs:
																					lowerCAmelCase__	       =     kwargs['''threshold''']
														if "top_k" in kwargs:
																					lowerCAmelCase__	       =     kwargs['''top_k''']
														return {}, {}, postprocess_params







							def   __SCREAMING_SNAKE_CASE							(		self ,   lowerCamelCase_       )	->							Union[str, Any]:
														lowerCAmelCase__	       =     load_image(inputs['''image''']       )
														lowerCAmelCase__	       =     inputs['''candidate_labels''']
														if isinstance(lowerCamelCase_ ,   lowerCamelCase_       ):
																					lowerCAmelCase__	       =     candidate_labels.split(''','''       )

														lowerCAmelCase__	       =     torch.tensor([[image.height, image.width]] ,   dtype=torch.intaa       )
														for i, candidate_label in enumerate(lowerCamelCase_       ):
																					lowerCAmelCase__	       =     self.tokenizer(lowerCamelCase_ ,   return_tensors=self.framework       )
																					lowerCAmelCase__	       =     self.image_processor(lowerCamelCase_ ,   return_tensors=self.framework       )
																					yield {
																					    "is_last": i == len(lowerCamelCase_       ) - 1,
																					    "target_size": target_size,
																					    "candidate_label": candidate_label,
																					    **text_inputs,
																					    **image_features,
																					}







							def   __SCREAMING_SNAKE_CASE							(		self ,   lowerCamelCase_       )	->							Optional[Any]:
														lowerCAmelCase__	       =     model_inputs.pop('''target_size'''       )
														lowerCAmelCase__	       =     model_inputs.pop('''candidate_label'''       )
														lowerCAmelCase__	       =     model_inputs.pop('''is_last'''       )

														lowerCAmelCase__	       =     self.model(**lowerCamelCase_       )

														lowerCAmelCase__	       =     {'''target_size''': target_size, '''candidate_label''': candidate_label, '''is_last''': is_last, **outputs}
														return model_outputs







							def   __SCREAMING_SNAKE_CASE							(		self ,   lowerCamelCase_ ,   lowerCamelCase_=0.1 ,   lowerCamelCase_=None       )	->							Dict:
														lowerCAmelCase__	       =     []
														for model_output in model_outputs:
																					lowerCAmelCase__	       =     model_output['''candidate_label''']
																					lowerCAmelCase__	       =     BaseModelOutput(lowerCamelCase_       )
																					lowerCAmelCase__	       =     self.image_processor.post_process_object_detection(
																					    outputs=lowerCamelCase_ ,   threshold=lowerCamelCase_ ,   target_sizes=model_output['''target_size''']       )[0]

																					for index in outputs["scores"].nonzero():
																												lowerCAmelCase__	       =     outputs['''scores'''][index].item()
																												lowerCAmelCase__	       =     self._get_bounding_box(outputs['''boxes'''][index][0]       )

																												lowerCAmelCase__	       =     {'''score''': score, '''label''': label, '''box''': box}
																												results.append(lowerCamelCase_       )

														lowerCAmelCase__	       =     sorted(lowerCamelCase_ ,   key=lambda lowerCamelCase_       : x["score"] ,   reverse=lowerCamelCase_       )
														if top_k:
																					lowerCAmelCase__	       =     results[:top_k]

														return results







							def   __SCREAMING_SNAKE_CASE							(		self ,   lowerCamelCase_       )	->							Dict[str, int]:
														if self.framework != "pt":
																					raise ValueError('''The ZeroShotObjectDetectionPipeline is only available in PyTorch.'''       )
														lowerCAmelCase__       , lowerCAmelCase__       , lowerCAmelCase__       , lowerCAmelCase__	       =     box.int().tolist()
														lowerCAmelCase__	       =     {
														    '''xmin''': xmin,
														    '''ymin''': ymin,
														    '''xmax''': xmax,
														    '''ymax''': ymax,
														}
														return bbox



'''simple docstring'''






def  _snake_case       (					A = 10	)						->   str:
							if not isinstance(A			,   A	) or n < 0:
														raise ValueError('''Invalid input'''	)
							lowerCAmelCase__	       =     10**n
							lowerCAmelCase__	       =     28433 * (pow(2			,   7830457			,   A	)) + 1
							return str(number % modulus	)


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

		testmod()
		print(f"""{solution(10) = }""")