






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


lowerCamelCase__							=     logging.get_logger(__name__)

lowerCamelCase__							=     {
    """speechbrain/m-ctc-t-large""": """https://huggingface.co/speechbrain/m-ctc-t-large/resolve/main/config.json""",
    # See all M-CTC-T models at https://huggingface.co/models?filter=mctct
}




class 			snake_case__   (							lowercase_):

       '''simple docstring'''
       lowerCamelCase							:				Dict 				= "mctct"



       def __init__(							self			,						a__=80_65			,						a__=15_36			,						a__=36			,						a__=61_44			,						a__=4			,						a__=3_84			,						a__=9_20			,						a__=1e-5			,						a__=0.3			,						a__="relu"			,						a__=0.02			,						a__=0.3			,						a__=0.3			,						a__=1			,						a__=0			,						a__=2			,						a__=1			,						a__=0.3			,						a__=1			,						a__=(7,)			,						a__=(3,)			,						a__=80			,						a__=1			,						a__=None			,						a__="sum"			,						a__=False			,						**a__			,						) ->      Dict:






            '''simple docstring'''





            super().__init__(**a__			,						pad_token_id=a__			,						bos_token_id=a__			,						eos_token_id=a__    )
            __snake_case			:Dict          =						vocab_size
            __snake_case			:Optional[int]          =						hidden_size
            __snake_case			:List[Any]          =						num_hidden_layers
            __snake_case			:List[Any]          =						intermediate_size
            __snake_case			:List[Any]          =						num_attention_heads
            __snake_case			:List[str]          =						attention_head_dim
            __snake_case			:Any          =						max_position_embeddings
            __snake_case			:Optional[int]          =						layer_norm_eps
            __snake_case			:Optional[Any]          =						layerdrop
            __snake_case			:Tuple          =						hidden_act
            __snake_case			:Any          =						initializer_range
            __snake_case			:List[Any]          =						hidden_dropout_prob
            __snake_case			:int          =						attention_probs_dropout_prob
            __snake_case			:List[str]          =						pad_token_id
            __snake_case			:Dict          =						bos_token_id
            __snake_case			:Any          =						eos_token_id
            __snake_case			:str          =						conv_glu_dim
            __snake_case			:Dict          =						conv_dropout
            __snake_case			:int          =						num_conv_layers
            __snake_case			:str          =						input_feat_per_channel
            __snake_case			:Optional[Any]          =						input_channels
            __snake_case			:Any          =						conv_channels
            __snake_case			:str          =						ctc_loss_reduction
            __snake_case			:int          =						ctc_zero_infinity

            # prevents config testing fail with exporting to json
            __snake_case			:int          =						list(a__    )
            __snake_case			:str          =						list(a__    )

            if len(self.conv_kernel    ) != self.num_conv_layers:
                 raise ValueError(
                     """Configuration for convolutional module is incorrect. """
                     """It is required that `len(config.conv_kernel)` == `config.num_conv_layers` """
                     F'''but is `len(config.conv_kernel) = {len(self.conv_kernel    )}`, '''
                     F'''`config.num_conv_layers = {self.num_conv_layers}`.'''    )










# 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__   (							lowercase_):

       '''simple docstring'''
       lowerCamelCase							:				Tuple 				= "dandelin/vilt-b32-finetuned-vqa"
       lowerCamelCase							:				List[str] 				= (
           "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							:				Optional[Any] 				= "image_qa"
       lowerCamelCase							:				str 				= AutoProcessor
       lowerCamelCase							:				Union[str, Any] 				= AutoModelForVisualQuestionAnswering

       lowerCamelCase							:				Any 				= ["image", "text"]
       lowerCamelCase							:				Dict 				= ["text"]



       def __init__(							self			,						*a__			,						**a__    ) ->      Any:






            '''simple docstring'''





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



       def 					__lowercase						(							self			,						a__			,						a__    ) ->      int:






            '''simple docstring'''





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



       def 					__lowercase						(							self			,						a__    ) ->      Union[str, Any]:






            '''simple docstring'''





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



       def 					__lowercase						(							self			,						a__    ) ->      Tuple:






            '''simple docstring'''





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


