
"""simple docstring"""


from ...processing_utils import ProcessorMixin
from ...tokenization_utils_base import BatchEncoding







class 					lowerCAmelCase_					(   _lowercase     ):



						'''simple docstring'''


						_lowerCamelCase:     List[str]   =     '''ClapFeatureExtractor'''
						_lowerCamelCase:     int   =     ('''RobertaTokenizer''', '''RobertaTokenizerFast''')


						def __init__(			self  :   Dict	,A_  :   Any	,A_  :   Dict   )  -> Tuple:
							super().__init__(A_	,A_   )


						def __call__(			self  :   Tuple	,A_  :   Any=None	,A_  :   List[str]=None	,A_  :   List[str]=None	,**A_  :   Optional[Any]   )  -> Dict:
							A     = kwargs.pop('sampling_rate'	,A_   )

							if text is None and audios is None:
								raise ValueError('You have to specify either text or audios. Both cannot be none.'   )

							if text is not None:
								A     = self.tokenizer(A_	,return_tensors=A_	,**A_   )

							if audios is not None:
								A     = self.feature_extractor(
								    A_	,sampling_rate=A_	,return_tensors=A_	,**A_   )

							if text is not None and audios is not None:
								A     = audio_features.input_features
								return encoding
							elif text is not None:
								return encoding
							else:
								return BatchEncoding(data=dict(**A_   )	,tensor_type=A_   )


						def     _SCREAMING_SNAKE_CASE   (			self  :   int	,*A_  :   int	,**A_  :   Union[str, Any]   )  -> Optional[int]:
							return self.tokenizer.batch_decode(*A_	,**A_   )


						def     _SCREAMING_SNAKE_CASE   (			self  :   Union[str, Any]	,*A_  :   Optional[Any]	,**A_  :   Optional[int]   )  -> List[Any]:
							return self.tokenizer.decode(*A_	,**A_   )




						@property
						def     _SCREAMING_SNAKE_CASE   (			self  :   Optional[int]   )  -> int:
							A     = self.tokenizer.model_input_names
							A     = self.feature_extractor.model_input_names
							return list(dict.fromkeys(tokenizer_input_names + feature_extractor_input_names   )   )



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





