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

SCREAMING_SNAKE_CASE__:str			=	logging.get_logger(__name__)






@add_end_docstrings(lowercase__   )
class 				snake_case__     (   lowercase__   ):


 def __init__(				self  ,						*lowerCamelCase  ,						**lowerCamelCase		):
        super().__init__(*_UpperCamelCase  ,						**_UpperCamelCase		)
        self.check_model_type(_UpperCamelCase		)


 def 		a__ (				self  ,						lowerCamelCase=None  ,						lowerCamelCase=None  ,						lowerCamelCase=None  ,						**lowerCamelCase		):
        __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		):
        if isinstance(_UpperCamelCase  ,						(Image.Image, str)		) and isinstance(_UpperCamelCase  ,						_UpperCamelCase		):
               __a     				=  {"""image""": image, """question""": question}
        else:
               __a     				=  image
        __a     				=  super().__call__(_UpperCamelCase  ,						**_UpperCamelCase		)
        return results


 def 		a__ (				self  ,						lowerCamelCase  ,						lowerCamelCase=False  ,						lowerCamelCase=False		):
        __a     				=  load_image(inputs["image"]		)
        __a     				=  self.tokenizer(
            inputs["question"]  ,						return_tensors=self.framework  ,						padding=_UpperCamelCase  ,						truncation=_UpperCamelCase		)
        __a     				=  self.image_processor(images=_UpperCamelCase  ,						return_tensors=self.framework		)
        model_inputs.update(_UpperCamelCase		)
        return model_inputs


 def 		a__ (				self  ,						lowerCamelCase		):
        __a     				=  self.model(**_UpperCamelCase		)
        return model_outputs






 def 		a__ (				self  ,						lowerCamelCase  ,						lowerCamelCase=5		):
        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     				=  probs.topk(_UpperCamelCase		)
        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(_UpperCamelCase  ,						_UpperCamelCase		)]

"""simple docstring"""



from ..utils import DummyObject, requires_backends






class 				snake_case__     (   metaclass=snake_case_   ):
 _snake_case   :			Union[str, Any]           =		["""onnx"""]


 def __init__(				self  ,						*lowerCamelCase  ,						**lowerCamelCase		):
        requires_backends(self  ,						["onnx"]		)


 @classmethod
 def 		a__ (				cls  ,						*lowerCamelCase  ,						**lowerCamelCase		):
        requires_backends(cls  ,						["onnx"]		)






 @classmethod
 def 		a__ (				cls  ,						*lowerCamelCase  ,						**lowerCamelCase		):
        requires_backends(cls  ,						["onnx"]		)
