




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

UpperCamelCase_    	=				logging.get_logger(__name__)






@add_end_docstrings(SCREAMING_SNAKE_CASE )
class 							_a				(			SCREAMING_SNAKE_CASE ):





       '''simple docstring'''






       def __init__(      self,							*A,							**A  ):







             '''simple docstring'''







             super().__init__(*A,							**A  )
             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        UpperCamelCase_							(      self,							A=None  ):







             '''simple docstring'''







             SCREAMING_SNAKE_CASE   :      List[str]    					=						{}
             if top_k is not None:
                   SCREAMING_SNAKE_CASE   :      Optional[Any]    					=						top_k
             return {}, {}, postprocess_params







       def __call__(      self,							A,							**A  ):







             '''simple docstring'''







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







       def        UpperCamelCase_							(      self,							A  ):







             '''simple docstring'''







             SCREAMING_SNAKE_CASE   :      Any    					=						load_image(A  )
             SCREAMING_SNAKE_CASE   :      Optional[Any]    					=						self.image_processor(images=A,							return_tensors=self.framework  )
             return model_inputs







       def        UpperCamelCase_							(      self,							A  ):







             '''simple docstring'''







             SCREAMING_SNAKE_CASE   :      List[str]    					=						self.model(**A  )
             return model_outputs







       def        UpperCamelCase_							(      self,							A,							A=5  ):







             '''simple docstring'''







             if top_k > self.model.config.num_labels:
                   SCREAMING_SNAKE_CASE   :      int    					=						self.model.config.num_labels

             if self.framework == "pt":
                   SCREAMING_SNAKE_CASE   :      str    					=						model_outputs.logits.softmax(-1  )[0]
                   SCREAMING_SNAKE_CASE					,    SCREAMING_SNAKE_CASE   :      str    					=						probs.topk(A  )
             elif self.framework == "tf":
                   SCREAMING_SNAKE_CASE   :      Optional[Any]    					=						stable_softmax(model_outputs.logits,							axis=-1  )[0]
                   SCREAMING_SNAKE_CASE   :      int    					=						tf.math.top_k(A,							k=A  )
                   SCREAMING_SNAKE_CASE					,    SCREAMING_SNAKE_CASE   :      List[str]    					=						topk.values.numpy(), topk.indices.numpy()
             else:
                   raise ValueError(F"Unsupported framework: {self.framework}"  )

             SCREAMING_SNAKE_CASE   :      Optional[int]    					=						scores.tolist()
             SCREAMING_SNAKE_CASE   :      str    					=						ids.tolist()
             return [{"score": score, "label": self.model.config.idalabel[_id]} for score, _id in zip(A,							A  )]




from ...configuration_utils import PretrainedConfig
from ...utils import logging


__lowerCAmelCase					   =       logging.get_logger(__name__)

__lowerCAmelCase					   =       {
    'microsoft/biogpt': 'https://huggingface.co/microsoft/biogpt/resolve/main/config.json',
    # See all BioGPT models at https://huggingface.co/models?filter=biogpt
}





class     lowerCamelCase      (       __lowerCamelCase					):
	UpperCamelCase_  :					Union[str, Any]    		=	'biogpt'







	def __init__(     self      :Tuple   ,     lowercase      :Union[str, Any]=4_2_3_8_4   ,     lowercase      :str=1_0_2_4   ,     lowercase      :Any=2_4   ,     lowercase      :List[str]=1_6   ,     lowercase      :List[str]=4_0_9_6   ,     lowercase      :int="gelu"   ,     lowercase      :List[Any]=0.1   ,     lowercase      :int=0.1   ,     lowercase      :int=1_0_2_4   ,     lowercase      :Optional[Any]=0.02   ,     lowercase      :Union[str, Any]=1e-12   ,     lowercase      :Tuple=True   ,     lowercase      :int=True   ,     lowercase      :Optional[int]=0.0   ,     lowercase      :Any=0.0   ,     lowercase      :str=1   ,     lowercase      :Any=0   ,     lowercase      :int=2   ,     **lowercase      :Tuple   ,     )		->      Optional[int]:







				"""simple docstring"""






				SCREAMING_SNAKE_CASE     						= vocab_size
				SCREAMING_SNAKE_CASE     						= max_position_embeddings
				SCREAMING_SNAKE_CASE     						= hidden_size
				SCREAMING_SNAKE_CASE     						= num_hidden_layers
				SCREAMING_SNAKE_CASE     						= num_attention_heads
				SCREAMING_SNAKE_CASE     						= intermediate_size
				SCREAMING_SNAKE_CASE     						= hidden_act
				SCREAMING_SNAKE_CASE     						= hidden_dropout_prob
				SCREAMING_SNAKE_CASE     						= attention_probs_dropout_prob
				SCREAMING_SNAKE_CASE     						= initializer_range
				SCREAMING_SNAKE_CASE     						= layer_norm_eps
				SCREAMING_SNAKE_CASE     						= scale_embedding
				SCREAMING_SNAKE_CASE     						= use_cache
				SCREAMING_SNAKE_CASE     						= layerdrop
				SCREAMING_SNAKE_CASE     						= activation_dropout
				super().__init__(pad_token_id=lowercase   ,     bos_token_id=lowercase   ,     eos_token_id=lowercase   ,     **lowercase			)