
from typing import List, Optional, Union

from ...configuration_utils import PretrainedConfig
from ...utils import logging


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

lowerCamelCase__    :		List[str]          =   {
    """huggingface/time-series-transformer-tourism-monthly""": (
        """https://huggingface.co/huggingface/time-series-transformer-tourism-monthly/resolve/main/config.json"""
    ),
    # See all TimeSeriesTransformer models at https://huggingface.co/models?filter=time_series_transformer
}



class       _snake_case   (	UpperCAmelCase_							):
 __lowerCAmelCase  :     Optional[int]        =			'time_series_transformer'
 __lowerCAmelCase  :     str        =			{
     'hidden_size': 'd_model',
     'num_attention_heads': 'encoder_attention_heads',
     'num_hidden_layers': 'encoder_layers',
 }


 def __init__(					self					,  SCREAMING_SNAKE_CASE_ = None					,  SCREAMING_SNAKE_CASE_ = None					,  SCREAMING_SNAKE_CASE_ = "student_t"					,  SCREAMING_SNAKE_CASE_ = "nll"					,  SCREAMING_SNAKE_CASE_ = 1					,  SCREAMING_SNAKE_CASE_ = [1, 2, 3, 4, 5, 6, 7]					,  SCREAMING_SNAKE_CASE_ = "mean"					,  SCREAMING_SNAKE_CASE_ = 0					,  SCREAMING_SNAKE_CASE_ = 0					,  SCREAMING_SNAKE_CASE_ = 0					,  SCREAMING_SNAKE_CASE_ = 0					,  SCREAMING_SNAKE_CASE_ = None					,  SCREAMING_SNAKE_CASE_ = None					,  SCREAMING_SNAKE_CASE_ = 32					,  SCREAMING_SNAKE_CASE_ = 32					,  SCREAMING_SNAKE_CASE_ = 2					,  SCREAMING_SNAKE_CASE_ = 2					,  SCREAMING_SNAKE_CASE_ = 2					,  SCREAMING_SNAKE_CASE_ = 2					,  SCREAMING_SNAKE_CASE_ = True					,  SCREAMING_SNAKE_CASE_ = "gelu"					,  SCREAMING_SNAKE_CASE_ = 64					,  SCREAMING_SNAKE_CASE_ = 0.1					,  SCREAMING_SNAKE_CASE_ = 0.1					,  SCREAMING_SNAKE_CASE_ = 0.1					,  SCREAMING_SNAKE_CASE_ = 0.1					,  SCREAMING_SNAKE_CASE_ = 0.1					,  SCREAMING_SNAKE_CASE_ = 1_00					,  SCREAMING_SNAKE_CASE_ = 0.0_2					,  SCREAMING_SNAKE_CASE_=True					,  **SCREAMING_SNAKE_CASE_					,  ):


   '''simple docstring'''




   lowercase__  :   int    		=      prediction_length
   lowercase__  :   Optional[Any]    		=      context_length or prediction_length
   lowercase__  :   Dict    		=      distribution_output
   lowercase__  :   Optional[int]    		=      loss
   lowercase__  :   List[Any]    		=      input_size
   lowercase__  :   Union[str, Any]    		=      num_time_features
   lowercase__  :   Optional[Any]    		=      lags_sequence
   lowercase__  :   Tuple    		=      scaling
   lowercase__  :   List[Any]    		=      num_dynamic_real_features
   lowercase__  :   Union[str, Any]    		=      num_static_real_features
   lowercase__  :   Union[str, Any]    		=      num_static_categorical_features
   if cardinality and num_static_categorical_features > 0:
     if len(SCREAMING_SNAKE_CASE_) != num_static_categorical_features:
       raise ValueError(
           """The cardinality should be a list of the same length as `num_static_categorical_features`""")
     lowercase__  :   int    		=      cardinality
   else:
     lowercase__  :   str    		=      [0]
   if embedding_dimension and num_static_categorical_features > 0:
     if len(SCREAMING_SNAKE_CASE_) != num_static_categorical_features:
       raise ValueError(
           """The embedding dimension should be a list of the same length as `num_static_categorical_features`""")
     lowercase__  :   Optional[int]    		=      embedding_dimension
   else:
     lowercase__  :   str    		=      [min(50					,  (cat + 1) // 2) for cat in self.cardinality]
   lowercase__  :   List[str]    		=      num_parallel_samples

   # Transformer architecture configuration
   lowercase__  :   Any    		=      input_size * len(SCREAMING_SNAKE_CASE_) + self._number_of_features
   lowercase__  :   Union[str, Any]    		=      d_model
   lowercase__  :   Union[str, Any]    		=      encoder_attention_heads
   lowercase__  :   Optional[Any]    		=      decoder_attention_heads
   lowercase__  :   Any    		=      encoder_ffn_dim
   lowercase__  :   Any    		=      decoder_ffn_dim
   lowercase__  :   List[str]    		=      encoder_layers
   lowercase__  :   Any    		=      decoder_layers

   lowercase__  :   Union[str, Any]    		=      dropout
   lowercase__  :   Dict    		=      attention_dropout
   lowercase__  :   List[Any]    		=      activation_dropout
   lowercase__  :   Tuple    		=      encoder_layerdrop
   lowercase__  :   List[str]    		=      decoder_layerdrop

   lowercase__  :   Dict    		=      activation_function
   lowercase__  :   Any    		=      init_std

   lowercase__  :   Tuple    		=      use_cache

   super().__init__(is_encoder_decoder=SCREAMING_SNAKE_CASE_					,  **SCREAMING_SNAKE_CASE_)



 @property
 def      lowercase__     (					self):


   '''simple docstring'''




   return (
       sum(self.embedding_dimension)
       + self.num_dynamic_real_features
       + self.num_time_features
       + self.num_static_real_features
       + self.input_size * 2  # the log1p(abs(loc)) and log(scale) features
   )








# Copyright 2023 The HuggingFace Inc. team. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from typing import TYPE_CHECKING

import torch

from ..models.auto import AutoModelForVisualQuestionAnswering, AutoProcessor
from ..utils import requires_backends
from .base import PipelineTool


if TYPE_CHECKING:
     from PIL import Image



class       _snake_case   (	UpperCAmelCase_							):
 __lowerCAmelCase  :     Any        =			'dandelin/vilt-b32-finetuned-vqa'
 __lowerCAmelCase  :     Union[str, Any]        =			(
     'This is a tool that answers a question about an image. It takes an input named `image` which should be the '
     'image containing the information, as well as a `question` which should be the question in English. It '
     'returns a text that is the answer to the question.'
 )
 __lowerCAmelCase  :     str        =			'image_qa'
 __lowerCAmelCase  :     int        =			AutoProcessor
 __lowerCAmelCase  :     Optional[Any]        =			AutoModelForVisualQuestionAnswering

 __lowerCAmelCase  :     str        =			['image', 'text']
 __lowerCAmelCase  :     Optional[int]        =			['text']


 def __init__(					self					,  *SCREAMING_SNAKE_CASE_					,  **SCREAMING_SNAKE_CASE_):


   '''simple docstring'''




   requires_backends(self					,  ["""vision"""])
   super().__init__(*SCREAMING_SNAKE_CASE_					,  **SCREAMING_SNAKE_CASE_)


 def      lowercase__     (					self					,  SCREAMING_SNAKE_CASE_					,  SCREAMING_SNAKE_CASE_):


   '''simple docstring'''




   return self.pre_processor(SCREAMING_SNAKE_CASE_					,  SCREAMING_SNAKE_CASE_					,  return_tensors="""pt""")


 def      lowercase__     (					self					,  SCREAMING_SNAKE_CASE_):


   '''simple docstring'''




   with torch.no_grad():
     return self.model(**SCREAMING_SNAKE_CASE_).logits



 def      lowercase__     (					self					,  SCREAMING_SNAKE_CASE_):


   '''simple docstring'''




   lowercase__  :   Dict    		=      outputs.argmax(-1).item()
   return self.model.config.idalabel[idx]






