





from typing import List

import numpy as np

def       __A (     a_  :dict)						->						int:
				__a	:  Any         =					{key: len(a_) for key, value in gen_kwargs.items() if isinstance(a_				,    a_)}
				if len(set(lists_lengths.values())) > 1:
								raise RuntimeError(
								    (
								        '''Sharding is ambiguous for this dataset: '''
								        + '''we found several data sources lists of different lengths, and we don\'t know over which list we should parallelize:\n'''
								        + '''\n'''.join(F"""\t- key {key} has length {length}""" for key, length in lists_lengths.items())
								        + '''\nTo fix this, check the \'gen_kwargs\' and make sure to use lists only for data sources, '''
								        + '''and use tuples otherwise. In the end there should only be one single list, or several lists with the same length.'''
								    ))
				__a	:  List[str]         =					max(lists_lengths.values()				,    default=0)
				return max(1				,    a_)

def       __A (     a_  :int				,    a_  :int)						->						List[range]:
				__a	:  int         =					[]
				for group_idx in range(a_):
								__a	:  Optional[Any]         =					num_shards // max_num_jobs + (group_idx < (num_shards % max_num_jobs))
								if num_shards_to_add == 0:
												break
								__a	:  Dict         =					shards_indices_per_group[-1].stop if shards_indices_per_group else 0
								__a	:  List[Any]         =					range(a_				,    start + num_shards_to_add)
								shards_indices_per_group.append(a_)
				return shards_indices_per_group

def       __A (     a_  :dict				,    a_  :int)						->						List[dict]:
				__a	:  Any         =					_number_of_shards_in_gen_kwargs(a_)
				if num_shards == 1:
								return [dict(a_)]
				else:
								__a	:  int         =					_distribute_shards(num_shards=a_				,    max_num_jobs=a_)
								return [
								    {
								        key: [value[shard_idx] for shard_idx in shard_indices_per_group[group_idx]]
								        if isinstance(a_				,    a_)
								        else value
								        for key, value in gen_kwargs.items()
								    }
								    for group_idx in range(len(a_))
								]

def       __A (     a_  :List[dict])						->						dict:
				return {
				    key: [value for gen_kwargs in gen_kwargs_list for value in gen_kwargs[key]]
				    if isinstance(gen_kwargs_list[0][key]				,    a_)
				    else gen_kwargs_list[0][key]
				    for key in gen_kwargs_list[0]
				}






def       __A (     a_  :np.random.Generator				,    a_  :dict)						->						dict:
				__a	:  List[str]         =					{len(a_) for value in gen_kwargs.values() if isinstance(a_				,    a_)}
				__a	:  Optional[int]         =					{}
				for size in list_sizes:
								__a	:  str         =					list(range(a_))
								rng.shuffle(indices_per_size[size])
				# Now let's copy the gen_kwargs and shuffle the lists based on their sizes
				__a	:  Any         =					dict(a_)
				for key, value in shuffled_kwargs.items():
								if isinstance(a_				,    a_):
												__a	:  Any         =					[value[i] for i in indices_per_size[len(a_)]]
				return shuffled_kwargs






"""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 			__lowercase     (     _UpperCamelCase							):







					'''simple docstring'''




					__lowerCAmelCase					=					'''openai/whisper-base'''
					__lowerCAmelCase					=					(
					    '''This is a tool that transcribes an audio into text. It takes an input named `audio` and returns the '''
					    '''transcribed text.'''
					)
					__lowerCAmelCase					=					'''transcriber'''
					__lowerCAmelCase					=					WhisperProcessor
					__lowerCAmelCase					=					WhisperForConditionalGeneration

					__lowerCAmelCase					=					['''audio''']
					__lowerCAmelCase					=					['''text''']







					def 	_lowerCamelCase						(  self		,     _UpperCAmelCase       ):
									return self.pre_processor(_UpperCAmelCase		,     return_tensors='''pt'''       ).input_features







					def 	_lowerCamelCase						(  self		,     _UpperCAmelCase       ):
									return self.model.generate(inputs=_UpperCAmelCase       )







					def 	_lowerCamelCase						(  self		,     _UpperCAmelCase       ):
									return self.pre_processor.batch_decode(_UpperCAmelCase		,     skip_special_tokens=_UpperCAmelCase       )[0]