



# 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 				__A					( A_      ):
			UpperCamelCase					:Tuple     =			'''openai/whisper-base'''
			UpperCamelCase					:Union[str, Any]     =			(
			    '''This is a tool that transcribes an audio into text. It takes an input named `audio` and returns the '''
			    '''transcribed text.'''
			)
			UpperCamelCase					:Any     =			'''transcriber'''
			UpperCamelCase					:str     =			WhisperProcessor
			UpperCamelCase					:Tuple     =			WhisperForConditionalGeneration

			UpperCamelCase					:Union[str, Any]     =			['''audio''']
			UpperCamelCase					:Any     =			['''text''']





			def        _snake_case    (self							,    __magic_name__				):
						return self.pre_processor(__magic_name__							,    return_tensors="""pt"""				).input_features





			def        _snake_case    (self							,    __magic_name__				):
						return self.model.generate(inputs=__magic_name__				)





			def        _snake_case    (self							,    __magic_name__				):
						return self.pre_processor.batch_decode(__magic_name__							,    skip_special_tokens=__magic_name__				)[0]








import copy
from dataclasses import dataclass, field
from typing import ClassVar, Dict

from ..features import Audio, Features, Value
from .base import TaskTemplate
@dataclass(frozen=A_      )
class 				__A					( A_      ):
			UpperCamelCase					:str     =			field(default='''automatic-speech-recognition'''					, metadata={'''include_in_asdict_even_if_is_default''': True}      )
			UpperCamelCase					:ClassVar[Features]     =			Features({'''audio''': Audio()}      )
			UpperCamelCase					:ClassVar[Features]     =			Features({'''transcription''': Value('''string'''      )}      )
			UpperCamelCase					:str     =			"audio"
			UpperCamelCase					:str     =			"transcription"





			def        _snake_case    (self							,    __magic_name__				):
						if self.audio_column not in features:
									raise ValueError(f"Column {self.audio_column} is not present in features."				)
						if not isinstance(features[self.audio_column]							,    __magic_name__				):
									raise ValueError(f"Column {self.audio_column} is not an Audio type."				)
						lowerCamelCase__ :      int								=		copy.deepcopy(self				)
						lowerCamelCase__ :      Tuple								=		self.input_schema.copy()
						lowerCamelCase__ :      Tuple								=		features[self.audio_column]
						lowerCamelCase__ :      List[str]								=		input_schema
						return task_template





			@property
			def        _snake_case    (self				):
						return {self.audio_column: "audio", self.transcription_column: "transcription"}



