

"""simple docstring"""


from ..utils import DummyObject, requires_backends





class lowerCamelCase__   (				metaclass=SCREAMING_SNAKE_CASE    ):



    '''simple docstring'''




    _lowerCamelCase					=   ['''sentencepiece''']




    def __init__( self ,*lowerCamelCase_ ,**lowerCamelCase_    )    ->      Tuple:
          requires_backends(self ,["""sentencepiece"""]    )





class lowerCamelCase__   (				metaclass=SCREAMING_SNAKE_CASE    ):



    '''simple docstring'''




    _lowerCamelCase					=   ['''sentencepiece''']




    def __init__( self ,*lowerCamelCase_ ,**lowerCamelCase_    )    ->      Optional[int]:
          requires_backends(self ,["""sentencepiece"""]    )





class lowerCamelCase__   (				metaclass=SCREAMING_SNAKE_CASE    ):



    '''simple docstring'''




    _lowerCamelCase					=   ['''sentencepiece''']




    def __init__( self ,*lowerCamelCase_ ,**lowerCamelCase_    )    ->      List[str]:
          requires_backends(self ,["""sentencepiece"""]    )





class lowerCamelCase__   (				metaclass=SCREAMING_SNAKE_CASE    ):



    '''simple docstring'''




    _lowerCamelCase					=   ['''sentencepiece''']




    def __init__( self ,*lowerCamelCase_ ,**lowerCamelCase_    )    ->      int:
          requires_backends(self ,["""sentencepiece"""]    )





class lowerCamelCase__   (				metaclass=SCREAMING_SNAKE_CASE    ):



    '''simple docstring'''




    _lowerCamelCase					=   ['''sentencepiece''']




    def __init__( self ,*lowerCamelCase_ ,**lowerCamelCase_    )    ->      Optional[int]:
          requires_backends(self ,["""sentencepiece"""]    )





class lowerCamelCase__   (				metaclass=SCREAMING_SNAKE_CASE    ):



    '''simple docstring'''




    _lowerCamelCase					=   ['''sentencepiece''']




    def __init__( self ,*lowerCamelCase_ ,**lowerCamelCase_    )    ->      List[str]:
          requires_backends(self ,["""sentencepiece"""]    )





class lowerCamelCase__   (				metaclass=SCREAMING_SNAKE_CASE    ):



    '''simple docstring'''




    _lowerCamelCase					=   ['''sentencepiece''']




    def __init__( self ,*lowerCamelCase_ ,**lowerCamelCase_    )    ->      Dict:
          requires_backends(self ,["""sentencepiece"""]    )





class lowerCamelCase__   (				metaclass=SCREAMING_SNAKE_CASE    ):



    '''simple docstring'''




    _lowerCamelCase					=   ['''sentencepiece''']




    def __init__( self ,*lowerCamelCase_ ,**lowerCamelCase_    )    ->      List[str]:
          requires_backends(self ,["""sentencepiece"""]    )





class lowerCamelCase__   (				metaclass=SCREAMING_SNAKE_CASE    ):



    '''simple docstring'''




    _lowerCamelCase					=   ['''sentencepiece''']




    def __init__( self ,*lowerCamelCase_ ,**lowerCamelCase_    )    ->      Any:
          requires_backends(self ,["""sentencepiece"""]    )





class lowerCamelCase__   (				metaclass=SCREAMING_SNAKE_CASE    ):



    '''simple docstring'''




    _lowerCamelCase					=   ['''sentencepiece''']




    def __init__( self ,*lowerCamelCase_ ,**lowerCamelCase_    )    ->      int:
          requires_backends(self ,["""sentencepiece"""]    )





class lowerCamelCase__   (				metaclass=SCREAMING_SNAKE_CASE    ):



    '''simple docstring'''




    _lowerCamelCase					=   ['''sentencepiece''']




    def __init__( self ,*lowerCamelCase_ ,**lowerCamelCase_    )    ->      Optional[Any]:
          requires_backends(self ,["""sentencepiece"""]    )





class lowerCamelCase__   (				metaclass=SCREAMING_SNAKE_CASE    ):



    '''simple docstring'''




    _lowerCamelCase					=   ['''sentencepiece''']




    def __init__( self ,*lowerCamelCase_ ,**lowerCamelCase_    )    ->      Optional[int]:
          requires_backends(self ,["""sentencepiece"""]    )





class lowerCamelCase__   (				metaclass=SCREAMING_SNAKE_CASE    ):



    '''simple docstring'''




    _lowerCamelCase					=   ['''sentencepiece''']




    def __init__( self ,*lowerCamelCase_ ,**lowerCamelCase_    )    ->      str:
          requires_backends(self ,["""sentencepiece"""]    )





class lowerCamelCase__   (				metaclass=SCREAMING_SNAKE_CASE    ):



    '''simple docstring'''




    _lowerCamelCase					=   ['''sentencepiece''']




    def __init__( self ,*lowerCamelCase_ ,**lowerCamelCase_    )    ->      List[Any]:
          requires_backends(self ,["""sentencepiece"""]    )





class lowerCamelCase__   (				metaclass=SCREAMING_SNAKE_CASE    ):



    '''simple docstring'''




    _lowerCamelCase					=   ['''sentencepiece''']




    def __init__( self ,*lowerCamelCase_ ,**lowerCamelCase_    )    ->      int:
          requires_backends(self ,["""sentencepiece"""]    )





class lowerCamelCase__   (				metaclass=SCREAMING_SNAKE_CASE    ):



    '''simple docstring'''




    _lowerCamelCase					=   ['''sentencepiece''']




    def __init__( self ,*lowerCamelCase_ ,**lowerCamelCase_    )    ->      Any:
          requires_backends(self ,["""sentencepiece"""]    )





class lowerCamelCase__   (				metaclass=SCREAMING_SNAKE_CASE    ):



    '''simple docstring'''




    _lowerCamelCase					=   ['''sentencepiece''']




    def __init__( self ,*lowerCamelCase_ ,**lowerCamelCase_    )    ->      Tuple:
          requires_backends(self ,["""sentencepiece"""]    )





class lowerCamelCase__   (				metaclass=SCREAMING_SNAKE_CASE    ):



    '''simple docstring'''




    _lowerCamelCase					=   ['''sentencepiece''']




    def __init__( self ,*lowerCamelCase_ ,**lowerCamelCase_    )    ->      Union[str, Any]:
          requires_backends(self ,["""sentencepiece"""]    )





class lowerCamelCase__   (				metaclass=SCREAMING_SNAKE_CASE    ):



    '''simple docstring'''




    _lowerCamelCase					=   ['''sentencepiece''']




    def __init__( self ,*lowerCamelCase_ ,**lowerCamelCase_    )    ->      Any:
          requires_backends(self ,["""sentencepiece"""]    )





class lowerCamelCase__   (				metaclass=SCREAMING_SNAKE_CASE    ):



    '''simple docstring'''




    _lowerCamelCase					=   ['''sentencepiece''']




    def __init__( self ,*lowerCamelCase_ ,**lowerCamelCase_    )    ->      int:
          requires_backends(self ,["""sentencepiece"""]    )





class lowerCamelCase__   (				metaclass=SCREAMING_SNAKE_CASE    ):



    '''simple docstring'''




    _lowerCamelCase					=   ['''sentencepiece''']




    def __init__( self ,*lowerCamelCase_ ,**lowerCamelCase_    )    ->      Dict:
          requires_backends(self ,["""sentencepiece"""]    )





class lowerCamelCase__   (				metaclass=SCREAMING_SNAKE_CASE    ):



    '''simple docstring'''




    _lowerCamelCase					=   ['''sentencepiece''']




    def __init__( self ,*lowerCamelCase_ ,**lowerCamelCase_    )    ->      Union[str, Any]:
          requires_backends(self ,["""sentencepiece"""]    )





class lowerCamelCase__   (				metaclass=SCREAMING_SNAKE_CASE    ):



    '''simple docstring'''




    _lowerCamelCase					=   ['''sentencepiece''']




    def __init__( self ,*lowerCamelCase_ ,**lowerCamelCase_    )    ->      int:
          requires_backends(self ,["""sentencepiece"""]    )





class lowerCamelCase__   (				metaclass=SCREAMING_SNAKE_CASE    ):



    '''simple docstring'''




    _lowerCamelCase					=   ['''sentencepiece''']




    def __init__( self ,*lowerCamelCase_ ,**lowerCamelCase_    )    ->      Tuple:
          requires_backends(self ,["""sentencepiece"""]    )





class lowerCamelCase__   (				metaclass=SCREAMING_SNAKE_CASE    ):



    '''simple docstring'''




    _lowerCamelCase					=   ['''sentencepiece''']




    def __init__( self ,*lowerCamelCase_ ,**lowerCamelCase_    )    ->      List[str]:
          requires_backends(self ,["""sentencepiece"""]    )





class lowerCamelCase__   (				metaclass=SCREAMING_SNAKE_CASE    ):



    '''simple docstring'''




    _lowerCamelCase					=   ['''sentencepiece''']




    def __init__( self ,*lowerCamelCase_ ,**lowerCamelCase_    )    ->      Optional[Any]:
          requires_backends(self ,["""sentencepiece"""]    )





class lowerCamelCase__   (				metaclass=SCREAMING_SNAKE_CASE    ):



    '''simple docstring'''




    _lowerCamelCase					=   ['''sentencepiece''']




    def __init__( self ,*lowerCamelCase_ ,**lowerCamelCase_    )    ->      Tuple:
          requires_backends(self ,["""sentencepiece"""]    )





class lowerCamelCase__   (				metaclass=SCREAMING_SNAKE_CASE    ):



    '''simple docstring'''




    _lowerCamelCase					=   ['''sentencepiece''']




    def __init__( self ,*lowerCamelCase_ ,**lowerCamelCase_    )    ->      str:
          requires_backends(self ,["""sentencepiece"""]    )





class lowerCamelCase__   (				metaclass=SCREAMING_SNAKE_CASE    ):



    '''simple docstring'''




    _lowerCamelCase					=   ['''sentencepiece''']




    def __init__( self ,*lowerCamelCase_ ,**lowerCamelCase_    )    ->      Union[str, Any]:
          requires_backends(self ,["""sentencepiece"""]    )





class lowerCamelCase__   (				metaclass=SCREAMING_SNAKE_CASE    ):



    '''simple docstring'''




    _lowerCamelCase					=   ['''sentencepiece''']




    def __init__( self ,*lowerCamelCase_ ,**lowerCamelCase_    )    ->      Dict:
          requires_backends(self ,["""sentencepiece"""]    )





class lowerCamelCase__   (				metaclass=SCREAMING_SNAKE_CASE    ):



    '''simple docstring'''




    _lowerCamelCase					=   ['''sentencepiece''']




    def __init__( self ,*lowerCamelCase_ ,**lowerCamelCase_    )    ->      Optional[Any]:
          requires_backends(self ,["""sentencepiece"""]    )







"""simple docstring"""


from typing import Union

from ..utils import add_end_docstrings, is_torch_available, is_vision_available, logging
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_VISUAL_QUESTION_ANSWERING_MAPPING

UpperCAmelCase													=logging.get_logger(__name__)





@add_end_docstrings(SCREAMING_SNAKE_CASE    )
class lowerCamelCase__   (				SCREAMING_SNAKE_CASE    ):



    '''simple docstring'''




    def __init__( self ,*lowerCamelCase_ ,**lowerCamelCase_    )    ->      str:
          super().__init__(*lowerCamelCase_ ,**lowerCamelCase_    )
          self.check_model_type(lowerCamelCase_    )




    def UpperCamelCase__		( self ,lowerCamelCase_=None ,lowerCamelCase_=None ,lowerCamelCase_=None ,**lowerCamelCase_    )    ->      List[Any]:
          A  ,			A				  =		{}, {}
          if padding is not None:
                A				  =		padding
          if truncation is not None:
                A				  =		truncation
          if top_k is not None:
                A				  =		top_k
          return preprocess_params, {}, postprocess_params




    def __call__( self ,lowerCamelCase_ ,lowerCamelCase_ = None ,**lowerCamelCase_    )    ->      Dict:
          if isinstance(lowerCamelCase_ ,(Image.Image, str)    ) and isinstance(lowerCamelCase_ ,lowerCamelCase_    ):
                A				  =		{"""image""": image, """question""": question}
          else:
                A				  =		image
          A				  =		super().__call__(lowerCamelCase_ ,**lowerCamelCase_    )
          return results




    def UpperCamelCase__		( self ,lowerCamelCase_ ,lowerCamelCase_=False ,lowerCamelCase_=False    )    ->      List[Any]:
          A				  =		load_image(inputs["""image"""]    )
          A				  =		self.tokenizer(
              inputs["""question"""] ,return_tensors=self.framework ,padding=lowerCamelCase_ ,truncation=lowerCamelCase_    )
          A				  =		self.image_processor(images=lowerCamelCase_ ,return_tensors=self.framework    )
          model_inputs.update(lowerCamelCase_    )
          return model_inputs




    def UpperCamelCase__		( self ,lowerCamelCase_    )    ->      Union[str, Any]:
          A				  =		self.model(**lowerCamelCase_    )
          return model_outputs




    def UpperCamelCase__		( self ,lowerCamelCase_ ,lowerCamelCase_=5    )    ->      int:
          if top_k > self.model.config.num_labels:
                A				  =		self.model.config.num_labels

          if self.framework == "pt":
                A				  =		model_outputs.logits.sigmoid()[0]
                A  ,			A				  =		probs.topk(lowerCamelCase_    )
          else:
                raise ValueError(f'Unsupported framework: {self.framework}'    )

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




