



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

__lowerCAmelCase		     =  logging.get_logger(__name__)

@add_end_docstrings(_UpperCamelCase  )
class       __magic_name__		(       _UpperCamelCase  ):







							def __init__(				self   :			Any      ,*_UpperCAmelCase   :			str      ,**_UpperCAmelCase   :			Optional[int]						):
									super().__init__(*_UpperCAmelCase      ,**_UpperCAmelCase						)
									self.check_model_type(_UpperCAmelCase						)







							def 				__lowercase     (				self   :			Optional[int]      ,_UpperCAmelCase   :			str=None      ,_UpperCAmelCase   :			Optional[Any]=None      ,_UpperCAmelCase   :			str=None      ,**_UpperCAmelCase   :			Optional[int]						):
									_a			,   _a	: Union[str, Any]								=				{}, {}
									if padding is not None:
											_a	: Tuple								=				padding
									if truncation is not None:
											_a	: Dict								=				truncation
									if top_k is not None:
											_a	: int								=				top_k
									return preprocess_params, {}, postprocess_params







							def __call__(				self   :			List[Any]      ,_UpperCAmelCase   :			Union["Image.Image", str]      ,_UpperCAmelCase   :			str = None      ,**_UpperCAmelCase   :			Dict						):
									if isinstance(_UpperCAmelCase      ,(Image.Image, str)						) and isinstance(_UpperCAmelCase      ,_UpperCAmelCase						):
											_a	: List[Any]								=				{'image': image, 'question': question}
									else:
											_a	: Any								=				image
									_a	: int								=				super().__call__(_UpperCAmelCase      ,**_UpperCAmelCase						)
									return results







							def 				__lowercase     (				self   :			Dict      ,_UpperCAmelCase   :			Union[str, Any]      ,_UpperCAmelCase   :			List[str]=False      ,_UpperCAmelCase   :			Tuple=False						):
									_a	: Tuple								=				load_image(inputs['image']						)
									_a	: str								=				self.tokenizer(
									    inputs['question']      ,return_tensors=self.framework      ,padding=_UpperCAmelCase      ,truncation=_UpperCAmelCase						)
									_a	: List[str]								=				self.image_processor(images=_UpperCAmelCase      ,return_tensors=self.framework						)
									model_inputs.update(_UpperCAmelCase						)
									return model_inputs







							def 				__lowercase     (				self   :			Union[str, Any]      ,_UpperCAmelCase   :			List[Any]						):
									_a	: Any								=				self.model(**_UpperCAmelCase						)
									return model_outputs







							def 				__lowercase     (				self   :			int      ,_UpperCAmelCase   :			int      ,_UpperCAmelCase   :			Optional[Any]=5						):
									if top_k > self.model.config.num_labels:
											_a	: List[Any]								=				self.model.config.num_labels

									if self.framework == "pt":
											_a	: Any								=				model_outputs.logits.sigmoid()[0]
											_a			,   _a	: Optional[int]								=				probs.topk(_UpperCAmelCase						)
									else:
											raise ValueError(F"""Unsupported framework: {self.framework}"""						)

									_a	: Optional[int]								=				scores.tolist()
									_a	: Optional[Any]								=				ids.tolist()
									return [{"score": score, "answer": self.model.config.idalabel[_id]} for score, _id in zip(_UpperCAmelCase      ,_UpperCAmelCase						)]









'''simple docstring'''

import warnings

from ...utils import logging
from .image_processing_deit import DeiTImageProcessor


__lowerCAmelCase		     =  logging.get_logger(__name__)

class       __magic_name__		(       _UpperCamelCase  ):







							def __init__(				self   :			Tuple      ,*_UpperCAmelCase   :			str      ,**_UpperCAmelCase   :			int						):
									warnings.warn(
									    'The class DeiTFeatureExtractor is deprecated and will be removed in version 5 of Transformers. Please'
									    ' use DeiTImageProcessor instead.'      ,_UpperCAmelCase      ,)
									super().__init__(*_UpperCAmelCase      ,**_UpperCAmelCase						)




