



import json
from typing import List, Optional, Tuple

from tokenizers import pre_tokenizers, processors

from ...tokenization_utils_base import AddedToken, BatchEncoding
from ...tokenization_utils_fast import PreTrainedTokenizerFast
from ...utils import logging
from .tokenization_bart import BartTokenizer


_lowercase  				=    logging.get_logger(__name__)


_lowercase  				=    {'''vocab_file''': '''vocab.json''', '''merges_file''': '''merges.txt''', '''tokenizer_file''': '''tokenizer.json'''}

# See all BART models at https://huggingface.co/models?filter=bart
_lowercase  				=    {
    '''vocab_file''': {
        '''facebook/bart-base''': '''https://huggingface.co/facebook/bart-base/resolve/main/vocab.json''',
        '''facebook/bart-large''': '''https://huggingface.co/facebook/bart-large/resolve/main/vocab.json''',
        '''facebook/bart-large-mnli''': '''https://huggingface.co/facebook/bart-large-mnli/resolve/main/vocab.json''',
        '''facebook/bart-large-cnn''': '''https://huggingface.co/facebook/bart-large-cnn/resolve/main/vocab.json''',
        '''facebook/bart-large-xsum''': '''https://huggingface.co/facebook/bart-large-xsum/resolve/main/vocab.json''',
        '''yjernite/bart_eli5''': '''https://huggingface.co/yjernite/bart_eli5/resolve/main/vocab.json''',
    },
    '''merges_file''': {
        '''facebook/bart-base''': '''https://huggingface.co/facebook/bart-base/resolve/main/merges.txt''',
        '''facebook/bart-large''': '''https://huggingface.co/facebook/bart-large/resolve/main/merges.txt''',
        '''facebook/bart-large-mnli''': '''https://huggingface.co/facebook/bart-large-mnli/resolve/main/merges.txt''',
        '''facebook/bart-large-cnn''': '''https://huggingface.co/facebook/bart-large-cnn/resolve/main/merges.txt''',
        '''facebook/bart-large-xsum''': '''https://huggingface.co/facebook/bart-large-xsum/resolve/main/merges.txt''',
        '''yjernite/bart_eli5''': '''https://huggingface.co/yjernite/bart_eli5/resolve/main/merges.txt''',
    },
    '''tokenizer_file''': {
        '''facebook/bart-base''': '''https://huggingface.co/facebook/bart-base/resolve/main/tokenizer.json''',
        '''facebook/bart-large''': '''https://huggingface.co/facebook/bart-large/resolve/main/tokenizer.json''',
        '''facebook/bart-large-mnli''': '''https://huggingface.co/facebook/bart-large-mnli/resolve/main/tokenizer.json''',
        '''facebook/bart-large-cnn''': '''https://huggingface.co/facebook/bart-large-cnn/resolve/main/tokenizer.json''',
        '''facebook/bart-large-xsum''': '''https://huggingface.co/facebook/bart-large-xsum/resolve/main/tokenizer.json''',
        '''yjernite/bart_eli5''': '''https://huggingface.co/yjernite/bart_eli5/resolve/main/tokenizer.json''',
    },
}

_lowercase  				=    {
    '''facebook/bart-base''': 10_24,
    '''facebook/bart-large''': 10_24,
    '''facebook/bart-large-mnli''': 10_24,
    '''facebook/bart-large-cnn''': 10_24,
    '''facebook/bart-large-xsum''': 10_24,
    '''yjernite/bart_eli5''': 10_24,
}
class 					__A       (			__SCREAMING_SNAKE_CASE   ):
			UpperCamelCase       :Dict	 =      VOCAB_FILES_NAMES
			UpperCamelCase       :str	 =      PRETRAINED_VOCAB_FILES_MAP
			UpperCamelCase       :Union[str, Any]	 =      PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES
			UpperCamelCase       :Any	 =      ['''input_ids''', '''attention_mask''']
			UpperCamelCase       :Optional[int]	 =      BartTokenizer





			def __init__(self				,     __magic_name__=None				,     __magic_name__=None				,     __magic_name__=None				,     __magic_name__="replace"				,     __magic_name__="<s>"				,     __magic_name__="</s>"				,     __magic_name__="</s>"				,     __magic_name__="<s>"				,     __magic_name__="<unk>"				,     __magic_name__="<pad>"				,     __magic_name__="<mask>"				,     __magic_name__=False				,     __magic_name__=True				,     **__magic_name__				,     ):
						super().__init__(
						    __lowerCamelCase				,     __lowerCamelCase				,     tokenizer_file=__lowerCamelCase				,     errors=__lowerCamelCase				,     bos_token=__lowerCamelCase				,     eos_token=__lowerCamelCase				,     sep_token=__lowerCamelCase				,     cls_token=__lowerCamelCase				,     unk_token=__lowerCamelCase				,     pad_token=__lowerCamelCase				,     mask_token=__lowerCamelCase				,     add_prefix_space=__lowerCamelCase				,     trim_offsets=__lowerCamelCase				,     **__lowerCamelCase				,     )

						lowerCamelCase__			:   Any										=		json.loads(self.backend_tokenizer.pre_tokenizer.__getstate__()					)
						if pre_tok_state.get("""add_prefix_space"""				,     __lowerCamelCase					) != add_prefix_space:
									lowerCamelCase__			:   Union[str, Any]										=		getattr(__lowerCamelCase				,     pre_tok_state.pop("""type"""					)					)
									lowerCamelCase__			:   Any										=		add_prefix_space
									lowerCamelCase__			:   List[Any]										=		pre_tok_class(**__lowerCamelCase					)

						lowerCamelCase__			:   Union[str, Any]										=		add_prefix_space

						# the pre_tokenizer is already updated in the GPT2TokenizerFast `__init__`
						lowerCamelCase__			:   Optional[Any]										=		"""post_processor"""
						lowerCamelCase__			:   str										=		getattr(self.backend_tokenizer				,     __lowerCamelCase				,     __lowerCamelCase					)
						if tokenizer_component_instance:
									lowerCamelCase__			:   Any										=		json.loads(tokenizer_component_instance.__getstate__()					)

									# The lists 'sep' and 'cls' must be cased in tuples for the object `post_processor_class`
									if "sep" in state:
												lowerCamelCase__			:   Optional[int]										=		tuple(state["""sep"""]					)
									if "cls" in state:
												lowerCamelCase__			:   List[Any]										=		tuple(state["""cls"""]					)

									lowerCamelCase__			:   Dict										=		False

									if state.get("""add_prefix_space"""				,     __lowerCamelCase					) != add_prefix_space:
												lowerCamelCase__			:   Tuple										=		add_prefix_space
												lowerCamelCase__			:   Tuple										=		True

									if state.get("""trim_offsets"""				,     __lowerCamelCase					) != trim_offsets:
												lowerCamelCase__			:   Tuple										=		trim_offsets
												lowerCamelCase__			:   int										=		True

									if changes_to_apply:
												lowerCamelCase__			:   List[Any]										=		getattr(__lowerCamelCase				,     state.pop("""type"""					)					)
												lowerCamelCase__			:   Optional[Any]										=		component_class(**__lowerCamelCase					)
												setattr(self.backend_tokenizer				,     __lowerCamelCase				,     __lowerCamelCase					)





			@property
			def 							_snake_case     (self					):
						if self._mask_token is None:
									if self.verbose:
												logger.error("""Using mask_token, but it is not set yet."""					)
									return None
						return str(self._mask_token					)





			@mask_token.setter
			def 							_snake_case     (self				,     __magic_name__					):
						lowerCamelCase__			:   List[str]										=		AddedToken(__lowerCamelCase				,     lstrip=__lowerCamelCase				,     rstrip=__lowerCamelCase					) if isinstance(__lowerCamelCase				,     __lowerCamelCase					) else value
						lowerCamelCase__			:   Any										=		value





			def 							_snake_case     (self				,     *__magic_name__				,     **__magic_name__					):
						lowerCamelCase__			:   Union[str, Any]										=		kwargs.get("""is_split_into_words"""				,     __lowerCamelCase					)

						if is_split_into_words and not self.add_prefix_space:
									raise ValueError(
									    f"You need to instantiate {self.__class__.__name__} with add_prefix_space=True "
									    """to use it with pretokenized inputs."""					)

						return super()._batch_encode_plus(*__lowerCamelCase				,     **__lowerCamelCase					)





			def 							_snake_case     (self				,     *__magic_name__				,     **__magic_name__					):
						lowerCamelCase__			:   Union[str, Any]										=		kwargs.get("""is_split_into_words"""				,     __lowerCamelCase					)

						if is_split_into_words and not self.add_prefix_space:
									raise ValueError(
									    f"You need to instantiate {self.__class__.__name__} with add_prefix_space=True "
									    """to use it with pretokenized inputs."""					)

						return super()._encode_plus(*__lowerCamelCase				,     **__lowerCamelCase					)





			def 							_snake_case     (self				,     __magic_name__				,     __magic_name__ = None					):
						lowerCamelCase__			:   Any										=		self._tokenizer.model.save(__lowerCamelCase				,     name=__lowerCamelCase					)
						return tuple(__lowerCamelCase					)





			def 							_snake_case     (self				,     __magic_name__				,     __magic_name__=None					):
						lowerCamelCase__			:   Dict										=		[self.bos_token_id] + token_ids_a + [self.eos_token_id]
						if token_ids_a is None:
									return output

						return output + [self.eos_token_id] + token_ids_a + [self.eos_token_id]





			def 							_snake_case     (self				,     __magic_name__				,     __magic_name__ = None					):
						lowerCamelCase__			:   Optional[int]										=		[self.sep_token_id]
						lowerCamelCase__			:   Optional[int]										=		[self.cls_token_id]

						if token_ids_a is None:
									return len(cls + token_ids_a + sep					) * [0]
						return len(cls + token_ids_a + sep + sep + token_ids_a + sep					) * [0]








"""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     UpperCAmelCase    (	__SCREAMING_SNAKE_CASE  ):
   A__		:	str           =  '''openai/whisper-base'''
   A__		:	List[Any]           =  (
       '''This is a tool that transcribes an audio into text. It takes an input named `audio` and returns the '''
       '''transcribed text.'''
   )
   A__		:	str           =  '''transcriber'''
   A__		:	List[Any]           =  WhisperProcessor
   A__		:	Optional[int]           =  WhisperForConditionalGeneration

   A__		:	List[str]           =  ['''audio''']
   A__		:	Optional[int]           =  ['''text''']



   def    __UpperCAmelCase    (       self    :	Tuple							,       __lowerCamelCase    :	List[Any]				):



     """simple docstring"""
     return self.pre_processor(__lowerCamelCase							,       return_tensors='''pt'''				).input_features



   def    __UpperCAmelCase    (       self    :	Optional[int]							,       __lowerCamelCase    :	List[str]				):



     """simple docstring"""
     return self.model.generate(inputs=__lowerCamelCase				)





   def    __UpperCAmelCase    (       self    :	List[str]							,       __lowerCamelCase    :	int				):



     """simple docstring"""
     return self.pre_processor.batch_decode(__lowerCamelCase							,       skip_special_tokens=__lowerCamelCase				)[0]





