


"""simple docstring"""



import functools
import operator

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


__snake_case       =       logging.get_logger(__name__)

__snake_case       =       {
    """facebook/wav2vec2-base-960h""": """https://huggingface.co/facebook/wav2vec2-base-960h/resolve/main/config.json""",
    # See all Wav2Vec2 models at https://huggingface.co/models?filter=wav2vec2
}







class _lowerCAmelCase							( snake_case_      ):
   __UpperCAmelCase					:			List[str]				    =    '''wav2vec2'''







   def __init__(      self		,      UpperCamelCase__=32		,      UpperCamelCase__=768		,      UpperCamelCase__=12		,      UpperCamelCase__=12		,      UpperCamelCase__=3072		,      UpperCamelCase__="gelu"		,      UpperCamelCase__=0.1		,      UpperCamelCase__=0.1		,      UpperCamelCase__=0.1		,      UpperCamelCase__=0.0		,      UpperCamelCase__=0.0		,      UpperCamelCase__=0.1		,      UpperCamelCase__=0.1		,      UpperCamelCase__=0.02		,      UpperCamelCase__=1e-5		,      UpperCamelCase__="group"		,      UpperCamelCase__="gelu"		,      UpperCamelCase__=(512, 512, 512, 512, 512, 512, 512)		,      UpperCamelCase__=(5, 2, 2, 2, 2, 2, 2)		,      UpperCamelCase__=(10, 3, 3, 3, 3, 2, 2)		,      UpperCamelCase__=False		,      UpperCamelCase__=128		,      UpperCamelCase__=16		,      UpperCamelCase__=False		,      UpperCamelCase__=True		,      UpperCamelCase__=0.05		,      UpperCamelCase__=10		,      UpperCamelCase__=2		,      UpperCamelCase__=0.0		,      UpperCamelCase__=10		,      UpperCamelCase__=0		,      UpperCamelCase__=320		,      UpperCamelCase__=2		,      UpperCamelCase__=0.1		,      UpperCamelCase__=100		,      UpperCamelCase__=256		,      UpperCamelCase__=256		,      UpperCamelCase__=0.1		,      UpperCamelCase__="sum"		,      UpperCamelCase__=False		,      UpperCamelCase__=False		,      UpperCamelCase__=256		,      UpperCamelCase__=(512, 512, 512, 512, 1500)		,      UpperCamelCase__=(5, 3, 3, 1, 1)		,      UpperCamelCase__=(1, 2, 3, 1, 1)		,      UpperCamelCase__=512		,      UpperCamelCase__=0		,      UpperCamelCase__=1		,      UpperCamelCase__=2		,      UpperCamelCase__=False		,      UpperCamelCase__=3		,      UpperCamelCase__=2		,      UpperCamelCase__=3		,      UpperCamelCase__=None		,      UpperCamelCase__=None		,      **UpperCamelCase__		,      )      ->						List[Any]:

       '''simple docstring'''




       super().__init__(**UpperCamelCase__		,      pad_token_id=UpperCamelCase__		,      bos_token_id=UpperCamelCase__		,      eos_token_id=UpperCamelCase__		)
       snake_case       : str    =       hidden_size
       snake_case       : str    =       feat_extract_norm
       snake_case       : Optional[Any]    =       feat_extract_activation
       snake_case       : Dict    =       list(UpperCamelCase__		)
       snake_case       : int    =       list(UpperCamelCase__		)
       snake_case       : int    =       list(UpperCamelCase__		)
       snake_case       : str    =       conv_bias
       snake_case       : Optional[int]    =       num_conv_pos_embeddings
       snake_case       : Dict    =       num_conv_pos_embedding_groups
       snake_case       : Tuple    =       len(self.conv_dim		)
       snake_case       : Any    =       num_hidden_layers
       snake_case       : Optional[int]    =       intermediate_size
       snake_case       : int    =       hidden_act
       snake_case       : List[Any]    =       num_attention_heads
       snake_case       : List[Any]    =       hidden_dropout
       snake_case       : Tuple    =       attention_dropout
       snake_case       : Tuple    =       activation_dropout
       snake_case       : Tuple    =       feat_proj_dropout
       snake_case       : Tuple    =       final_dropout
       snake_case       : Union[str, Any]    =       layerdrop
       snake_case       : Optional[int]    =       layer_norm_eps
       snake_case       : List[Any]    =       initializer_range
       snake_case       : Optional[Any]    =       vocab_size
       snake_case       : Union[str, Any]    =       do_stable_layer_norm
       snake_case       : Any    =       use_weighted_layer_sum

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

       # fine-tuning config parameters for SpecAugment: https://arxiv.org/abs/1904.08779
       snake_case       : Tuple    =       apply_spec_augment
       snake_case       : str    =       mask_time_prob
       snake_case       : Dict    =       mask_time_length
       snake_case       : Tuple    =       mask_time_min_masks
       snake_case       : List[str]    =       mask_feature_prob
       snake_case       : Union[str, Any]    =       mask_feature_length
       snake_case       : Dict    =       mask_feature_min_masks

       # parameters for pretraining with codevector quantized representations
       snake_case       : List[Any]    =       num_codevectors_per_group
       snake_case       : Dict    =       num_codevector_groups
       snake_case       : Tuple    =       contrastive_logits_temperature
       snake_case       : List[str]    =       feat_quantizer_dropout
       snake_case       : int    =       num_negatives
       snake_case       : List[Any]    =       codevector_dim
       snake_case       : Union[str, Any]    =       proj_codevector_dim
       snake_case       : Any    =       diversity_loss_weight

       # ctc loss
       snake_case       : List[str]    =       ctc_loss_reduction
       snake_case       : List[str]    =       ctc_zero_infinity

       # adapter
       snake_case       : List[Any]    =       add_adapter
       snake_case       : Optional[Any]    =       adapter_kernel_size
       snake_case       : Union[str, Any]    =       adapter_stride
       snake_case       : List[Any]    =       num_adapter_layers
       snake_case       : Dict    =       output_hidden_size or hidden_size
       snake_case       : Dict    =       adapter_attn_dim

       # SequenceClassification-specific parameter. Feel free to ignore for other classes.
       snake_case       : int    =       classifier_proj_size

       # XVector-specific parameters. Feel free to ignore for other classes.
       snake_case       : List[str]    =       list(UpperCamelCase__		)
       snake_case       : Tuple    =       list(UpperCamelCase__		)
       snake_case       : int    =       list(UpperCamelCase__		)
       snake_case       : Any    =       xvector_output_dim







   @property
   def 					lowerCamelCase						(      self		)      ->						Dict:

       '''simple docstring'''




       return functools.reduce(operator.mul		,      self.conv_stride		,      1		)









"""simple docstring"""



# 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 ..models.whisper import WhisperForConditionalGeneration, WhisperProcessor
from .base import PipelineTool







class _lowerCAmelCase							( snake_case_      ):
   __UpperCAmelCase					:			List[str]				    =    '''openai/whisper-base'''
   __UpperCAmelCase					:			Any				    =    (
       '''This is a tool that transcribes an audio into text. It takes an input named `audio` and returns the '''
       '''transcribed text.'''
   )
   __UpperCAmelCase					:			Tuple				    =    '''transcriber'''
   __UpperCAmelCase					:			Union[str, Any]				    =    WhisperProcessor
   __UpperCAmelCase					:			str				    =    WhisperForConditionalGeneration

   __UpperCAmelCase					:			int				    =    ['''audio''']
   __UpperCAmelCase					:			Optional[int]				    =    ['''text''']







   def 					lowerCamelCase						(      self		,      UpperCamelCase__		)      ->						Tuple:

       '''simple docstring'''




       return self.pre_processor(UpperCamelCase__		,      return_tensors="pt"		).input_features







   def 					lowerCamelCase						(      self		,      UpperCamelCase__		)      ->						int:

       '''simple docstring'''




       return self.model.generate(inputs=UpperCamelCase__		)







   def 					lowerCamelCase						(      self		,      UpperCamelCase__		)      ->						Optional[Any]:

       '''simple docstring'''




       return self.pre_processor.batch_decode(UpperCamelCase__		,      skip_special_tokens=UpperCamelCase__		)[0]





