






from ...processing_utils import ProcessorMixin


class     __SCREAMING_SNAKE_CASE					(   __lowercase):
						_SCREAMING_SNAKE_CASE	:       Union[str, Any]   =					'''WhisperFeatureExtractor'''
						_SCREAMING_SNAKE_CASE	:       int   =					'''WhisperTokenizer'''






						def __init__(	self     ,						_UpperCamelCase     ,						_UpperCamelCase   ):






												"""simple docstring"""
												super().__init__(_UpperCamelCase     ,						_UpperCamelCase   )
												lowerCAmelCase__    						=						self.feature_extractor
												lowerCAmelCase__    						=						False






						def       UpperCamelCase__      (	self     ,						_UpperCamelCase=None     ,						_UpperCamelCase=None     ,						_UpperCamelCase=True   ):






												"""simple docstring"""
												return self.tokenizer.get_decoder_prompt_ids(task=_UpperCamelCase     ,						language=_UpperCamelCase     ,						no_timestamps=_UpperCamelCase   )






						def __call__(	self     ,						*_UpperCamelCase     ,						**_UpperCamelCase   ):






												"""simple docstring"""
												# For backward compatibility
												if self._in_target_context_manager:
																		return self.current_processor(*_UpperCamelCase     ,						**_UpperCamelCase   )

												lowerCAmelCase__    						=						kwargs.pop('audio'     ,						_UpperCamelCase   )
												lowerCAmelCase__    						=						kwargs.pop('sampling_rate'     ,						_UpperCamelCase   )
												lowerCAmelCase__    						=						kwargs.pop('text'     ,						_UpperCamelCase   )
												if len(_UpperCamelCase   ) > 0:
																		lowerCAmelCase__    						=						args[0]
																		lowerCAmelCase__    						=						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:
																		lowerCAmelCase__    						=						self.feature_extractor(_UpperCamelCase     ,						*_UpperCamelCase     ,						sampling_rate=_UpperCamelCase     ,						**_UpperCamelCase   )
												if text is not None:
																		lowerCAmelCase__    						=						self.tokenizer(_UpperCamelCase     ,						**_UpperCamelCase   )

												if text is None:
																		return inputs

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






						def       UpperCamelCase__      (	self     ,						*_UpperCamelCase     ,						**_UpperCamelCase   ):






												"""simple docstring"""
												return self.tokenizer.batch_decode(*_UpperCamelCase     ,						**_UpperCamelCase   )






						def       UpperCamelCase__      (	self     ,						*_UpperCamelCase     ,						**_UpperCamelCase   ):






												"""simple docstring"""
												return self.tokenizer.decode(*_UpperCamelCase     ,						**_UpperCamelCase   )







						def       UpperCamelCase__      (	self     ,						_UpperCamelCase     ,						_UpperCamelCase="np"   ):






												"""simple docstring"""
												return self.tokenizer.get_prompt_ids(_UpperCamelCase     ,						return_tensors=_UpperCamelCase   )













import numpy as np
from PIL import Image







def 	_UpperCamelCase   (    UpperCamelCase_       :					np.ndarray    ,       UpperCamelCase_       :					int    ,       UpperCamelCase_       :					int		)  ->   np.ndarray:

						"""simple docstring"""



						lowerCAmelCase__    						=						np.array(UpperCamelCase_		)
						if arr.shape[0] != arr.shape[1]:
												raise ValueError('The input array is not a square matrix'		)
						lowerCAmelCase__    						=						0
						lowerCAmelCase__    						=						0
						lowerCAmelCase__    						=						0
						lowerCAmelCase__    						=						0

						# compute the shape of the output matrix
						lowerCAmelCase__    						=						(arr.shape[0] - size) // stride + 1
						# initialize the output matrix with zeros of shape maxpool_shape
						lowerCAmelCase__    						=						np.zeros((maxpool_shape, maxpool_shape)		)

						while i < arr.shape[0]:
												if i + size > arr.shape[0]:
																		# if the end of the matrix is reached, break
																		break
												while j < arr.shape[1]:
																		# if the end of the matrix is reached, break
																		if j + size > arr.shape[1]:
																								break
																		# compute the maximum of the pooling matrix
																		lowerCAmelCase__    						=						np.max(arr[i : i + size, j : j + size]		)
																		# shift the pooling matrix by stride of column pixels
																		j += stride
																		mat_j += 1

												# shift the pooling matrix by stride of row pixels
												i += stride
												mat_i += 1

												# reset the column index to 0
												lowerCAmelCase__    						=						0
												lowerCAmelCase__    						=						0

						return updated_arr







def 	_UpperCamelCase   (    UpperCamelCase_       :					np.ndarray    ,       UpperCamelCase_       :					int    ,       UpperCamelCase_       :					int		)  ->   np.ndarray:

						"""simple docstring"""



						lowerCAmelCase__    						=						np.array(UpperCamelCase_		)
						if arr.shape[0] != arr.shape[1]:
												raise ValueError('The input array is not a square matrix'		)
						lowerCAmelCase__    						=						0
						lowerCAmelCase__    						=						0
						lowerCAmelCase__    						=						0
						lowerCAmelCase__    						=						0

						# compute the shape of the output matrix
						lowerCAmelCase__    						=						(arr.shape[0] - size) // stride + 1
						# initialize the output matrix with zeros of shape avgpool_shape
						lowerCAmelCase__    						=						np.zeros((avgpool_shape, avgpool_shape)		)

						while i < arr.shape[0]:
												# if the end of the matrix is reached, break
												if i + size > arr.shape[0]:
																		break
												while j < arr.shape[1]:
																		# if the end of the matrix is reached, break
																		if j + size > arr.shape[1]:
																								break
																		# compute the average of the pooling matrix
																		lowerCAmelCase__    						=						int(np.average(arr[i : i + size, j : j + size]		)		)
																		# shift the pooling matrix by stride of column pixels
																		j += stride
																		mat_j += 1

												# shift the pooling matrix by stride of row pixels
												i += stride
												mat_i += 1
												# reset the column index to 0
												lowerCAmelCase__    						=						0
												lowerCAmelCase__    						=						0

						return updated_arr


# Main Function
if __name__ == "__main__":
					from doctest import testmod

					testmod(name="""avgpooling""", verbose=True)

					# Loading the image
					__snake_case    :    List[str]         =     Image.open("""path_to_image""")

					# Converting the image to numpy array and maxpooling, displaying the result
					# Ensure that the image is a square matrix

					Image.fromarray(maxpooling(np.array(image), size=3, stride=2)).show()

					# Converting the image to numpy array and averagepooling, displaying the result
					# Ensure that the image is a square matrix

					Image.fromarray(avgpooling(np.array(image), size=3, stride=2)).show()





