




'''simple docstring'''


from ...processing_utils import ProcessorMixin

class      A       (						_a       ):
							lowercase_							     =							'WhisperFeatureExtractor'
							lowercase_							     =							'WhisperTokenizer'







							def __init__(    self			:    Union[str, Any]				,     lowerCAmelCase_			:    List[str]				,     lowerCAmelCase_			:    str   )     ->				List[Any]:


														"""simple docstring"""


														super().__init__(lowerCAmelCase_				,     lowerCAmelCase_   )
														_a      	=							self.feature_extractor
														_a      	=							False







							def   __lowerCAmelCase     (    self			:    Any				,     lowerCAmelCase_			:    Optional[Any]=None				,     lowerCAmelCase_			:    str=None				,     lowerCAmelCase_			:    Dict=True   )     ->				List[Any]:


														"""simple docstring"""


														return self.tokenizer.get_decoder_prompt_ids(task=lowerCAmelCase_				,     language=lowerCAmelCase_				,     no_timestamps=lowerCAmelCase_   )







							def __call__(    self			:    Any				,     *lowerCAmelCase_			:    List[Any]				,     **lowerCAmelCase_			:    List[str]   )     ->				Dict:


														"""simple docstring"""


														if self._in_target_context_manager:
																					return self.current_processor(*lowerCAmelCase_				,     **lowerCAmelCase_   )

														_a      	=							kwargs.pop('''audio'''				,     lowerCAmelCase_   )
														_a      	=							kwargs.pop('''sampling_rate'''				,     lowerCAmelCase_   )
														_a      	=							kwargs.pop('''text'''				,     lowerCAmelCase_   )
														if len(lowerCAmelCase_   ) > 0:
																					_a      	=							args[0]
																					_a      	=							args[1:]

														if audio is None and text is None:
																					raise ValueError('''You need to specify either an `audio` or `text` input to process.'''   )

														if audio is not None:
																					_a      	=							self.feature_extractor(lowerCAmelCase_				,     *lowerCAmelCase_				,     sampling_rate=lowerCAmelCase_				,     **lowerCAmelCase_   )
														if text is not None:
																					_a      	=							self.tokenizer(lowerCAmelCase_				,     **lowerCAmelCase_   )

														if text is None:
																					return inputs

														elif audio is None:
																					return encodings
														else:
																					_a      	=							encodings['''input_ids''']
																					return inputs







							def   __lowerCAmelCase     (    self			:    str				,     *lowerCAmelCase_			:    Dict				,     **lowerCAmelCase_			:    int   )     ->				Any:


														"""simple docstring"""


														return self.tokenizer.batch_decode(*lowerCAmelCase_				,     **lowerCAmelCase_   )







							def   __lowerCAmelCase     (    self			:    Dict				,     *lowerCAmelCase_			:    Tuple				,     **lowerCAmelCase_			:    Optional[Any]   )     ->				Union[str, Any]:


														"""simple docstring"""


														return self.tokenizer.decode(*lowerCAmelCase_				,     **lowerCAmelCase_   )







							def   __lowerCAmelCase     (    self			:    Optional[int]				,     lowerCAmelCase_			:    str				,     lowerCAmelCase_			:    str="np"   )     ->				Dict:


														"""simple docstring"""


														return self.tokenizer.get_prompt_ids(lowerCAmelCase_				,     return_tensors=lowerCAmelCase_   )



"""simple docstring"""





import unittest

import numpy as np
import torch

from .utils_summarization import build_mask, compute_token_type_ids, process_story, truncate_or_pad



class __lowerCAmelCase					(       unittest.TestCase   ):




			"""simple docstring"""







			def   lowerCamelCase__  (					self    :       Optional[int]						)   ->			List[str]:







								"""simple docstring"""
								A_								=    10




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







								"""simple docstring"""
								A_								=    [1, 2, 3, 4]
								A_								=    [1, 2, 3, 4, 0, 0, 0, 0, 0, 0]
								self.assertEqual(truncate_or_pad(_snake_case							, self.block_size							, 0						)							, _snake_case						)




			def   lowerCamelCase__  (					self    :       List[str]						)   ->			List[Any]:







								"""simple docstring"""
								A_								=    [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
								A_								=    [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
								self.assertEqual(truncate_or_pad(_snake_case							, self.block_size							, 0						)							, _snake_case						)




			def   lowerCamelCase__  (					self    :       str						)   ->			Dict:







								"""simple docstring"""
								A_								=    [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13]
								A_								=    [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
								self.assertEqual(truncate_or_pad(_snake_case							, self.block_size							, 0						)							, _snake_case						)




			def   lowerCamelCase__  (					self    :       Dict						)   ->			Dict:







								"""simple docstring"""
								A_								=    "It was the year of Our Lord one thousand seven hundred and\n        seventy-five.\n\nSpiritual revelations were conceded to England at that\n        favoured period, as at this."
								A_			,     A_								=    process_story(_snake_case						)
								self.assertEqual(_snake_case							, []						)




			def   lowerCamelCase__  (					self    :       str						)   ->			str:







								"""simple docstring"""
								A_								=    ""
								A_			,     A_								=    process_story(_snake_case						)
								self.assertEqual(_snake_case							, []						)
								self.assertEqual(_snake_case							, []						)




			def   lowerCamelCase__  (					self    :       Tuple						)   ->			Optional[Any]:







								"""simple docstring"""
								A_								=    (
								    "It was the year of Our Lord one thousand seven hundred and "
								    "seventy-five\n\nSpiritual revelations were conceded to England "
								    "at that favoured period, as at this.\n@highlight\n\nIt was the best of times"
								)
								A_			,     A_								=    process_story(_snake_case						)

								A_								=    [
								    "It was the year of Our Lord one thousand seven hundred and seventy-five.",
								    "Spiritual revelations were conceded to England at that favoured period, as at this.",
								]
								self.assertEqual(_snake_case							, _snake_case						)

								A_								=    ["It was the best of times."]
								self.assertEqual(_snake_case							, _snake_case						)




			def   lowerCamelCase__  (					self    :       List[str]						)   ->			Optional[Any]:







								"""simple docstring"""
								A_								=    torch.tensor([1, 2, 3, 4]						)
								A_								=    torch.tensor([1, 1, 1, 1]						)
								np.testing.assert_array_equal(build_mask(_snake_case							, 0						).numpy()							, expected.numpy()						)




			def   lowerCamelCase__  (					self    :       List[Any]						)   ->			Optional[int]:







								"""simple docstring"""
								A_								=    torch.tensor([1, 2, 3, 4, 23, 23, 23]						)
								A_								=    torch.tensor([1, 1, 1, 1, 0, 0, 0]						)
								np.testing.assert_array_equal(build_mask(_snake_case							, 23						).numpy()							, expected.numpy()						)




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







								"""simple docstring"""
								A_								=    torch.tensor([8, 2, 3, 4, 1, 1, 1]						)
								A_								=    torch.tensor([1, 1, 1, 1, 0, 0, 0]						)
								np.testing.assert_array_equal(build_mask(_snake_case							, 1						).numpy()							, expected.numpy()						)






			def   lowerCamelCase__  (					self    :       int						)   ->			List[str]:







								"""simple docstring"""
								A_								=    101
								A_								=    torch.tensor([[1, 2, 3, 4, 5, 6], [1, 2, 3, 101, 5, 6], [1, 101, 3, 4, 101, 6]]						)
								A_								=    torch.tensor([[1, 1, 1, 1, 1, 1], [1, 1, 1, 0, 0, 0], [1, 0, 0, 0, 1, 1]]						)

								A_								=    compute_token_type_ids(_snake_case							, _snake_case						)
								np.testing.assert_array_equal(_snake_case							, _snake_case						)




