






'''simple docstring'''







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





class 	SCREAMING_SNAKE_CASE					(					SCREAMING_SNAKE_CASE_       ):
			snake_case__  =				"openai/whisper-base"
			snake_case__  =				(
			    "This is a tool that transcribes an audio into text. It takes an input named `audio` and returns the "
			    "transcribed text."
			)
			snake_case__  =				"transcriber"
			snake_case__  =				WhisperProcessor
			snake_case__  =				WhisperForConditionalGeneration

			snake_case__  =				["audio"]
			snake_case__  =				["text"]






			def 			SCREAMING_SNAKE_CASE      ( self      :			Any  ,						__SCREAMING_SNAKE_CASE      :			Any					)			->			int:
							return self.pre_processor(__SCREAMING_SNAKE_CASE  ,						return_tensors='''pt'''					).input_features






			def 			SCREAMING_SNAKE_CASE      ( self      :			Tuple  ,						__SCREAMING_SNAKE_CASE      :			Optional[Any]					)			->			int:
							return self.model.generate(inputs=__SCREAMING_SNAKE_CASE					)







			def 			SCREAMING_SNAKE_CASE      ( self      :			Union[str, Any]  ,						__SCREAMING_SNAKE_CASE      :			Union[str, Any]					)			->			str:
							return self.pre_processor.batch_decode(__SCREAMING_SNAKE_CASE  ,						skip_special_tokens=__SCREAMING_SNAKE_CASE					)[0]












'''simple docstring'''







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 	SCREAMING_SNAKE_CASE					:
			snake_case__  =				42
			snake_case__  =				None
			# Automatically constructed
			snake_case__  =				"dict"
			snake_case__  =				None
			snake_case__  =				field(default="Translation"	,   init=SCREAMING_SNAKE_CASE_	,   repr=SCREAMING_SNAKE_CASE_       )






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







			def 			SCREAMING_SNAKE_CASE      ( self      :			Union[str, Any]					)			->			Union["FeatureType", Dict[str, "FeatureType"]]:
							from .features import Value

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





@dataclass
class 	SCREAMING_SNAKE_CASE					:
			snake_case__  =				None
			snake_case__  =				None
			snake_case__  =				None
			# Automatically constructed
			snake_case__  =				"dict"
			snake_case__  =				None
			snake_case__  =				field(default="TranslationVariableLanguages"	,   init=SCREAMING_SNAKE_CASE_	,   repr=SCREAMING_SNAKE_CASE_       )






			def 			SCREAMING_SNAKE_CASE      ( self      :			Tuple					)			->			Dict:
							a_		:  List[str]											=      sorted(set(self.languages					)					) if self.languages else None
							a_		:  Optional[Any]											=      len(self.languages					) if self.languages else None






			def __call__( self      :			Any					)			->			Optional[Any]:
							return pa.struct({'''language''': pa.list_(pa.string()					), '''translation''': pa.list_(pa.string()					)}					)






			def 			SCREAMING_SNAKE_CASE      ( self      :			Optional[int]  ,						__SCREAMING_SNAKE_CASE      :			Optional[Any]					)			->			Optional[Any]:
							a_		:  str											=      set(self.languages					)
							if self.languages and set(__SCREAMING_SNAKE_CASE					) - lang_set:
											raise ValueError(
											    f'Some languages in example ({", ".join(sorted(set(__SCREAMING_SNAKE_CASE					) - lang_set					)					)}) are not in valid set ({", ".join(__SCREAMING_SNAKE_CASE					)}).'					)

							# Convert dictionary into tuples, splitting out cases where there are
							# multiple translations for a single language.
							a_		:  int											=      []
							for lang, text in translation_dict.items():
											if isinstance(__SCREAMING_SNAKE_CASE  ,						__SCREAMING_SNAKE_CASE					):
															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_				,			a_		:  List[Any]											=      zip(*sorted(__SCREAMING_SNAKE_CASE					)					)

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







			def 			SCREAMING_SNAKE_CASE      ( self      :			Any					)			->			Union["FeatureType", Dict[str, "FeatureType"]]:
							from .features import Sequence, Value

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




