






"""simple docstring"""






from ..models.whisper import WhisperForConditionalGeneration, WhisperProcessor
from .base import PipelineTool





class       snake_case_       (    _lowerCamelCase       ):



	"""simple docstring"""

	SCREAMING_SNAKE_CASE_:							Union[str, Any]   			=					"""openai/whisper-base"""
	SCREAMING_SNAKE_CASE_:							Any   			=					(
	    """This is a tool that transcribes an audio into text. It takes an input named `audio` and returns the """
	    """transcribed text."""
	)
	SCREAMING_SNAKE_CASE_:							Any   			=					"""transcriber"""
	SCREAMING_SNAKE_CASE_:							Optional[int]   			=					WhisperProcessor
	SCREAMING_SNAKE_CASE_:							Dict   			=					WhisperForConditionalGeneration

	SCREAMING_SNAKE_CASE_:							str   			=					["""audio"""]
	SCREAMING_SNAKE_CASE_:							Union[str, Any]   			=					["""text"""]


	def       _UpperCAmelCase						(      self  ,					__a						):


					"""simple docstring"""

					return self.pre_processor(__a  ,					return_tensors='pt'						).input_features


	def       _UpperCAmelCase						(      self  ,					__a						):


					"""simple docstring"""

					return self.model.generate(inputs=__a						)






	def       _UpperCAmelCase						(      self  ,					__a						):


					"""simple docstring"""

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










"""simple docstring"""






from math import ceil



def  __lowerCamelCase					(					lowerCAmelCase__       ,lowerCAmelCase__				):
				A__							 =       list(range(0       ,lowerCAmelCase__				)				)

				A__							 =       [item for sublist in list(device_map.values()				) for item in sublist]

				# Duplicate check
				A__							 =       []
				for i in device_map_blocks:
								if device_map_blocks.count(lowerCAmelCase__				) > 1 and i not in duplicate_blocks:
												duplicate_blocks.append(lowerCAmelCase__				)
    # Missing blocks
				A__							 =       [i for i in blocks if i not in device_map_blocks]
				A__							 =       [i for i in device_map_blocks if i not in blocks]

				if len(lowerCAmelCase__				) != 0:
								raise ValueError(
								    'Duplicate attention blocks specified in device_map. Attention blocks must be specified to one device.'
								    ' These attention blocks were specified more than once: ' + str(lowerCAmelCase__				)				)
				if len(lowerCAmelCase__				) != 0:
								raise ValueError(
								    'There are attention blocks for this model that are not specified in the device_map. Add these attention '
								    'blocks to a device on the device_map: ' + str(lowerCAmelCase__				)				)
				if len(lowerCAmelCase__				) != 0:
								raise ValueError(
								    'The device_map contains more attention blocks than this model has. Remove these from the device_map:'
								    + str(lowerCAmelCase__				)				)







def  __lowerCamelCase					(					lowerCAmelCase__       ,lowerCAmelCase__				):
				A__							 =       list(range(lowerCAmelCase__				)				)
				A__							 =       int(ceil(n_layers / len(lowerCAmelCase__				)				)				)
				A__							 =       [layers[i : i + n_blocks] for i in range(0       ,lowerCAmelCase__       ,lowerCAmelCase__				)]

				return dict(zip(lowerCAmelCase__       ,lowerCAmelCase__				)				)


