





from dataclasses import dataclass, field
from typing import TYPE_CHECKING, Any, ClassVar, Dict, List, Optional, Union

import pyarrow as pa


if TYPE_CHECKING:
		from .features import FeatureType




@dataclass
class 			__lowercase     :







					'''simple docstring'''




					__lowerCAmelCase					=					42
					__lowerCAmelCase					=					None
					# Automatically constructed
					__lowerCAmelCase					=					"dict"
					__lowerCAmelCase					=					None
					__lowerCAmelCase					=					field(default='''Translation'''				, init=_UpperCamelCase				, repr=_UpperCamelCase							)







					def __call__(  self       ):
									return pa.struct({lang: pa.string() for lang in sorted(self.languages       )}       )







					def 	_lowerCamelCase						(  self       ):
									from .features import Value

									return {k: Value('''string'''       ) for k in sorted(self.languages       )}






@dataclass
class 			__lowercase     :







					'''simple docstring'''




					__lowerCAmelCase					=					None
					__lowerCAmelCase					=					None
					__lowerCAmelCase					=					None
					# Automatically constructed
					__lowerCAmelCase					=					"dict"
					__lowerCAmelCase					=					None
					__lowerCAmelCase					=					field(default='''TranslationVariableLanguages'''				, init=_UpperCamelCase				, repr=_UpperCamelCase							)







					def 	_lowerCamelCase						(  self       ):
									__a	:  List[Any]         =					sorted(set(self.languages       )       ) if self.languages else None
									__a	:  List[str]         =					len(self.languages       ) if self.languages else None







					def __call__(  self       ):
									return pa.struct({'''language''': pa.list_(pa.string()       ), '''translation''': pa.list_(pa.string()       )}       )







					def 	_lowerCamelCase						(  self		,     _UpperCAmelCase       ):
									__a	:  Optional[Any]         =					set(self.languages       )
									if self.languages and set(_UpperCAmelCase       ) - lang_set:
													raise ValueError(
													    f"""Some languages in example ({", ".join(sorted(set(_UpperCAmelCase       ) - lang_set       )       )}) are not in valid set ({", ".join(_UpperCAmelCase       )})."""       )

									# Convert dictionary into tuples, splitting out cases where there are
									# multiple translations for a single language.
									__a	:  Any         =					[]
									for lang, text in translation_dict.items():
													if isinstance(_UpperCAmelCase		,     _UpperCAmelCase       ):
																	translation_tuples.append((lang, text)       )
													else:
																	translation_tuples.extend([(lang, el) for el in text]       )

        # Ensure translations are in ascending order by language code.
									__a	:  List[Any]         =					zip(*sorted(_UpperCAmelCase       )       )

									return {"language": languages, "translation": translations}







					def 	_lowerCamelCase						(  self       ):
									from .features import Sequence, Value

									return {
									    "language": Sequence(Value('''string'''       )       ),
									    "translation": Sequence(Value('''string'''       )       ),
									}






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