



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

A_		:     Optional[Any]        =     logging.get_logger(__name__)



@add_end_docstrings(UpperCAmelCase__	)
class 		_lowercase		(       UpperCAmelCase__	):

   def __init__(      self			:       List[Any]							,   *__lowerCAmelCase			:       Optional[int]							,   **__lowerCAmelCase			:       List[str]							)       ->				List[Any]:


    """simple docstring"""






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

   def 		A							(      self			:       int							,   __lowerCAmelCase			:       Union[str, Any]=None							,   __lowerCAmelCase			:       List[Any]=None							,   __lowerCAmelCase			:       Optional[Any]=None							,   **__lowerCAmelCase			:       Tuple							)       ->				Dict:


    """simple docstring"""






    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			:       Optional[int]							,   __lowerCAmelCase			:       Union["Image.Image", str]							,   __lowerCAmelCase			:       str = None							,   **__lowerCAmelCase			:       Any							)       ->				List[str]:


    """simple docstring"""






    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 		A							(      self			:       int							,   __lowerCAmelCase			:       Dict							,   __lowerCAmelCase			:       Optional[int]=False							,   __lowerCAmelCase			:       Dict=False							)       ->				Tuple:


    """simple docstring"""






    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 		A							(      self			:       Union[str, Any]							,   __lowerCAmelCase			:       str							)       ->				Any:


    """simple docstring"""






    a						=		self.model(**__lowerCAmelCase							)
    return model_outputs




   def 		A							(      self			:       Tuple							,   __lowerCAmelCase			:       List[Any]							,   __lowerCAmelCase			:       Union[str, Any]=5							)       ->				Optional[Any]:


    """simple docstring"""






    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							)]






A_		:     Any        =     [4, 1, 7, 4, 2, 6, 4, 1, 5, 3, 7, 5]
A_		:     Tuple        =     [3, 7, 7, 4, 2, 6, 4, 1, 5, 3, 7, 5]
A_		:     Optional[int]        =     {
    0: '''Sunday''',
    1: '''Monday''',
    2: '''Tuesday''',
    3: '''Wednesday''',
    4: '''Thursday''',
    5: '''Friday''',
    6: '''Saturday''',
}


def 	UpperCAmelCase__      (      UpperCAmelCase__ :int ,					UpperCAmelCase__ :int ,					UpperCAmelCase__ :int					):






 '''simple docstring'''

 assert len(str(UpperCAmelCase__					)					) > 2, "year should be in YYYY format"
 assert 1 <= month <= 12, "month should be between 1 to 12"
 assert 1 <= day <= 31, "day should be between 1 to 31"

 # Doomsday algorithm:
 a						=		year // 1_00
 a						=		(5 * (century % 4) + 2) % 7
 a						=		year % 1_00
 a						=		centurian % 12
 a						=		(
     (centurian // 12) + centurian_m + (centurian_m // 4) + century_anchor
 ) % 7
 a						=		(
     DOOMSDAY_NOT_LEAP[month - 1]
     if (year % 4 != 0) or (centurian == 0 and (year % 4_00) == 0)
     else DOOMSDAY_LEAP[month - 1]
 )
 a						=		(dooms_day + day - day_anchor) % 7
 return WEEK_DAY_NAMES[week_day]


if __name__ == "__main__":
     import doctest

     doctest.testmod()

