






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

lowerCamelCase	:							str				=logging.get_logger(__name__)





@add_end_docstrings(A__       )
class 			__a  (    A__       ):







 def __init__(		self					:   Dict							,   *SCREAMING_SNAKE_CASE					:   int							,   **SCREAMING_SNAKE_CASE					:   Dict						):


      '''simple docstring'''






      super().__init__(*SCREAMING_SNAKE_CASE							,   **SCREAMING_SNAKE_CASE						)
      self.check_model_type(SCREAMING_SNAKE_CASE						)







 def 					__lowercase					(		self					:   Union[str, Any]							,   SCREAMING_SNAKE_CASE					:   Dict=None							,   SCREAMING_SNAKE_CASE					:   Optional[int]=None							,   SCREAMING_SNAKE_CASE					:   Dict=None							,   **SCREAMING_SNAKE_CASE					:   int						):


      '''simple docstring'''






      UpperCamelCase__				,     UpperCamelCase__			:   List[str]       				=  {}, {}
      if padding is not None:
           UpperCamelCase__			:   List[Any]       				=  padding
      if truncation is not None:
           UpperCamelCase__			:   List[str]       				=  truncation
      if top_k is not None:
           UpperCamelCase__			:   List[str]       				=  top_k
      return preprocess_params, {}, postprocess_params







 def __call__(		self					:   Dict							,   SCREAMING_SNAKE_CASE					:   Union["Image.Image", str]							,   SCREAMING_SNAKE_CASE					:   str = None							,   **SCREAMING_SNAKE_CASE					:   Optional[Any]						):


      '''simple docstring'''






      if isinstance(SCREAMING_SNAKE_CASE							,   (Image.Image, str)						) and isinstance(SCREAMING_SNAKE_CASE							,   SCREAMING_SNAKE_CASE						):
           UpperCamelCase__			:   Optional[int]       				=  {"image": image, "question": question}
      else:
           UpperCamelCase__			:   int       				=  image
      UpperCamelCase__			:   Dict       				=  super().__call__(SCREAMING_SNAKE_CASE							,   **SCREAMING_SNAKE_CASE						)
      return results







 def 					__lowercase					(		self					:   Optional[int]							,   SCREAMING_SNAKE_CASE					:   Optional[int]							,   SCREAMING_SNAKE_CASE					:   Any=False							,   SCREAMING_SNAKE_CASE					:   Any=False						):


      '''simple docstring'''






      UpperCamelCase__			:   Union[str, Any]       				=  load_image(inputs["image"]						)
      UpperCamelCase__			:   int       				=  self.tokenizer(
          inputs["question"]							,   return_tensors=self.framework							,   padding=SCREAMING_SNAKE_CASE							,   truncation=SCREAMING_SNAKE_CASE						)
      UpperCamelCase__			:   str       				=  self.image_processor(images=SCREAMING_SNAKE_CASE							,   return_tensors=self.framework						)
      model_inputs.update(SCREAMING_SNAKE_CASE						)
      return model_inputs







 def 					__lowercase					(		self					:   Union[str, Any]							,   SCREAMING_SNAKE_CASE					:   Optional[int]						):


      '''simple docstring'''






      UpperCamelCase__			:   Any       				=  self.model(**SCREAMING_SNAKE_CASE						)
      return model_outputs







 def 					__lowercase					(		self					:   int							,   SCREAMING_SNAKE_CASE					:   Any							,   SCREAMING_SNAKE_CASE					:   Tuple=5						):


      '''simple docstring'''






      if top_k > self.model.config.num_labels:
           UpperCamelCase__			:   Any       				=  self.model.config.num_labels

      if self.framework == "pt":
           UpperCamelCase__			:   List[Any]       				=  model_outputs.logits.sigmoid()[0]
           UpperCamelCase__				,     UpperCamelCase__			:   List[Any]       				=  probs.topk(SCREAMING_SNAKE_CASE						)
      else:
           raise ValueError(F'Unsupported framework: {self.framework}'						)

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







from typing import TYPE_CHECKING

from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_speech_available, is_torch_available


lowerCamelCase	:							int				={
    '''configuration_audio_spectrogram_transformer''': [
        '''AUDIO_SPECTROGRAM_TRANSFORMER_PRETRAINED_CONFIG_ARCHIVE_MAP''',
        '''ASTConfig''',
    ]
}

try:
 if not is_torch_available():
  raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
 pass
else:
 lowerCamelCase	:							Union[str, Any]				=[
     '''AUDIO_SPECTROGRAM_TRANSFORMER_PRETRAINED_MODEL_ARCHIVE_LIST''',
     '''ASTForAudioClassification''',
     '''ASTModel''',
     '''ASTPreTrainedModel''',
 ]

try:
 if not is_speech_available():
  raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
 pass
else:
 lowerCamelCase	:							Optional[int]				=['''ASTFeatureExtractor''']

if TYPE_CHECKING:
 from .configuration_audio_spectrogram_transformer import (
     AUDIO_SPECTROGRAM_TRANSFORMER_PRETRAINED_CONFIG_ARCHIVE_MAP,
     ASTConfig,
 )

 try:
  if not is_torch_available():
   raise OptionalDependencyNotAvailable()
 except OptionalDependencyNotAvailable:
  pass
 else:
  from .modeling_audio_spectrogram_transformer import (
      AUDIO_SPECTROGRAM_TRANSFORMER_PRETRAINED_MODEL_ARCHIVE_LIST,
      ASTForAudioClassification,
      ASTModel,
      ASTPreTrainedModel,
  )

 try:
  if not is_speech_available():
   raise OptionalDependencyNotAvailable()
 except OptionalDependencyNotAvailable:
  pass
 else:
  from .feature_extraction_audio_spectrogram_transformer import ASTFeatureExtractor


else:
 import sys

 lowerCamelCase	:							Optional[int]				=_LazyModule(__name__, globals()['''__file__'''], _import_structure, module_spec=__spec__)