



'''simple docstring'''


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_tf_available():
   import tensorflow as tf

   from ..models.auto.modeling_tf_auto import TF_MODEL_FOR_IMAGE_CLASSIFICATION_MAPPING
   from ..tf_utils import stable_softmax

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

_lowerCamelCase	:       str      	=	logging.get_logger(__name__)

@add_end_docstrings(_a		)
class  SCREAMING_SNAKE_CASE (  _a		):






    """simple docstring"""





    def __init__(  self      :					Tuple  ,						*UpperCamelCase__      :					Optional[int]  ,						**UpperCamelCase__      :					str ):


       """simple docstring"""







       super().__init__(*UpperCamelCase__  ,						**UpperCamelCase__ )
       requires_backends(self  ,						'vision' )
       self.check_model_type(
           TF_MODEL_FOR_IMAGE_CLASSIFICATION_MAPPING
           if self.framework == 'tf'
           else MODEL_FOR_IMAGE_CLASSIFICATION_MAPPING )






    def  A       (  self      :					List[Any]  ,						UpperCamelCase__      :					Union[str, Any]=None ):


       """simple docstring"""







       UpperCamelCase					=  {}
       if top_k is not None:
          UpperCamelCase					=  top_k
       return {}, {}, postprocess_params






    def __call__(  self      :					str  ,						UpperCamelCase__      :					Union[str, List[str], "Image.Image", List["Image.Image"]]  ,						**UpperCamelCase__      :					Optional[int] ):


       """simple docstring"""







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






    def  A       (  self      :					int  ,						UpperCamelCase__      :					List[str] ):


       """simple docstring"""







       UpperCamelCase					=  load_image(UpperCamelCase__ )
       UpperCamelCase					=  self.image_processor(images=UpperCamelCase__  ,						return_tensors=self.framework )
       return model_inputs






    def  A       (  self      :					Any  ,						UpperCamelCase__      :					int ):


       """simple docstring"""







       UpperCamelCase					=  self.model(**UpperCamelCase__ )
       return model_outputs






    def  A       (  self      :					Any  ,						UpperCamelCase__      :					Optional[Any]  ,						UpperCamelCase__      :					str=5 ):


       """simple docstring"""







       if top_k > self.model.config.num_labels:
          UpperCamelCase					=  self.model.config.num_labels

       if self.framework == "pt":
          UpperCamelCase					=  model_outputs.logits.softmax(-1 )[0]
          UpperCamelCase				,      UpperCamelCase					=  probs.topk(UpperCamelCase__ )
       elif self.framework == "tf":
          UpperCamelCase					=  stable_softmax(model_outputs.logits  ,						axis=-1 )[0]
          UpperCamelCase					=  tf.math.top_k(UpperCamelCase__  ,						k=UpperCamelCase__ )
          UpperCamelCase				,      UpperCamelCase					=  topk.values.numpy(), topk.indices.numpy()
       else:
          raise ValueError(f"""Unsupported framework: {self.framework}""" )

       UpperCamelCase					=  scores.tolist()
       UpperCamelCase					=  ids.tolist()
       return [{"score": score, "label": self.model.config.idalabel[_id]} for score, _id in zip(UpperCamelCase__  ,						UpperCamelCase__ )]






"""simple docstring"""







from ...configuration_utils import PretrainedConfig


lowerCAmelCase_   						=   {
    'google/tapas-base-finetuned-sqa': (
        'https://huggingface.co/google/tapas-base-finetuned-sqa/resolve/main/config.json'
    ),
    'google/tapas-base-finetuned-wtq': (
        'https://huggingface.co/google/tapas-base-finetuned-wtq/resolve/main/config.json'
    ),
    'google/tapas-base-finetuned-wikisql-supervised': (
        'https://huggingface.co/google/tapas-base-finetuned-wikisql-supervised/resolve/main/config.json'
    ),
    'google/tapas-base-finetuned-tabfact': (
        'https://huggingface.co/google/tapas-base-finetuned-tabfact/resolve/main/config.json'
    ),
}
class        __A       (	A_    ):







		'''simple docstring'''





		lowerCAmelCase			:					str   	=				"tapas"







		def __init__(	self						:  List[Any]			,_snake_case						:  Dict=30_522			,_snake_case						:  Union[str, Any]=768			,_snake_case						:  int=12			,_snake_case						:  Union[str, Any]=12			,_snake_case						:  Union[str, Any]=3_072			,_snake_case						:  List[Any]="gelu"			,_snake_case						:  Optional[int]=0.1			,_snake_case						:  Tuple=0.1			,_snake_case						:  List[Any]=1_024			,_snake_case						:  Any=[3, 256, 256, 2, 256, 256, 10]			,_snake_case						:  List[Any]=0.02			,_snake_case						:  Union[str, Any]=1e-12			,_snake_case						:  str=0			,_snake_case						:  Any=10.0			,_snake_case						:  int=0			,_snake_case						:  Optional[Any]=1.0			,_snake_case						:  List[str]=None			,_snake_case						:  Tuple=1.0			,_snake_case						:  Tuple=False			,_snake_case						:  List[Any]=None			,_snake_case						:  int=1.0			,_snake_case						:  List[Any]=1.0			,_snake_case						:  Optional[int]=False			,_snake_case						:  Optional[int]=False			,_snake_case						:  Optional[int]="ratio"			,_snake_case						:  Any=None			,_snake_case						:  Union[str, Any]=None			,_snake_case						:  List[str]=64			,_snake_case						:  Optional[Any]=32			,_snake_case						:  Optional[Any]=False			,_snake_case						:  Optional[int]=True			,_snake_case						:  Dict=False			,_snake_case						:  Tuple=False			,_snake_case						:  int=True			,_snake_case						:  List[str]=False			,_snake_case						:  Dict=None			,_snake_case						:  Optional[int]=None			,**_snake_case						:  int			,)					->		List[Any]:






				"""simple docstring"""



				super().__init__(pad_token_id=_snake_case			,**_snake_case						)

				# BERT hyperparameters (with updated max_position_embeddings and type_vocab_sizes)
				lowercase__   :    Optional[int]				=			vocab_size
				lowercase__   :    List[str]				=			hidden_size
				lowercase__   :    Any				=			num_hidden_layers
				lowercase__   :    Optional[Any]				=			num_attention_heads
				lowercase__   :    Optional[int]				=			hidden_act
				lowercase__   :    List[Any]				=			intermediate_size
				lowercase__   :    List[Any]				=			hidden_dropout_prob
				lowercase__   :    Dict				=			attention_probs_dropout_prob
				lowercase__   :    str				=			max_position_embeddings
				lowercase__   :    Dict				=			type_vocab_sizes
				lowercase__   :    Optional[Any]				=			initializer_range
				lowercase__   :    Dict				=			layer_norm_eps

				# Fine-tuning task hyperparameters
				lowercase__   :    Any				=			positive_label_weight
				lowercase__   :    int				=			num_aggregation_labels
				lowercase__   :    List[str]				=			aggregation_loss_weight
				lowercase__   :    Optional[int]				=			use_answer_as_supervision
				lowercase__   :    Optional[Any]				=			answer_loss_importance
				lowercase__   :    Union[str, Any]				=			use_normalized_answer_loss
				lowercase__   :    str				=			huber_loss_delta
				lowercase__   :    str				=			temperature
				lowercase__   :    int				=			aggregation_temperature
				lowercase__   :    List[Any]				=			use_gumbel_for_cells
				lowercase__   :    Tuple				=			use_gumbel_for_aggregation
				lowercase__   :    Union[str, Any]				=			average_approximation_function
				lowercase__   :    Union[str, Any]				=			cell_selection_preference
				lowercase__   :    Any				=			answer_loss_cutoff
				lowercase__   :    List[Any]				=			max_num_rows
				lowercase__   :    str				=			max_num_columns
				lowercase__   :    int				=			average_logits_per_cell
				lowercase__   :    str				=			select_one_column
				lowercase__   :    str				=			allow_empty_column_selection
				lowercase__   :    Any				=			init_cell_selection_weights_to_zero
				lowercase__   :    Optional[int]				=			reset_position_index_per_cell
				lowercase__   :    Union[str, Any]				=			disable_per_token_loss

				# Aggregation hyperparameters
				lowercase__   :    Optional[Any]				=			aggregation_labels
				lowercase__   :    List[Any]				=			no_aggregation_label_index

				if isinstance(self.aggregation_labels			,_snake_case						):
						lowercase__   :    Union[str, Any]				=			{int(_snake_case						): v for k, v in aggregation_labels.items()}
