





'''simple docstring'''







import os
import warnings
from typing import List, Optional

from ...tokenization_utils_base import BatchEncoding
from ...utils import logging
from .configuration_rag import RagConfig


snake_case_     :       Any						=  logging.get_logger(__name__)


class 					__a      :

							def __init__(							self							:     int       ,     __magic_name__							:     str       ,     __magic_name__							:     str   )					->       Dict:







													"""simple docstring"""
													UpperCAmelCase_			:      Dict     						=  question_encoder
													UpperCAmelCase_			:      str     						=  generator
													UpperCAmelCase_			:      Dict     						=  self.question_encoder

							def     UpperCAmelCase__	(							self							:     List[str]       ,     __magic_name__							:     Optional[Any]   )					->       Optional[int]:







													"""simple docstring"""
													if os.path.isfile(__magic_name__   ):
																			raise ValueError(F"""Provided path ({save_directory}) should be a directory, not a file"""   )
													os.makedirs(__magic_name__       ,     exist_ok=__magic_name__   )
													UpperCAmelCase_			:      str     						=  os.path.join(__magic_name__       ,     '''question_encoder_tokenizer'''   )
													UpperCAmelCase_			:      Optional[int]     						=  os.path.join(__magic_name__       ,     '''generator_tokenizer'''   )
													self.question_encoder.save_pretrained(__magic_name__   )
													self.generator.save_pretrained(__magic_name__   )

							@classmethod
							def     UpperCAmelCase__	(							cls							:     Tuple       ,     __magic_name__							:     str       ,     **__magic_name__							:     Dict   )					->       Union[str, Any]:







													"""simple docstring"""
													from ..auto.tokenization_auto import AutoTokenizer

													UpperCAmelCase_			:      Dict     						=  kwargs.pop('''config'''       ,     __magic_name__   )

													if config is None:
																			UpperCAmelCase_			:      Optional[Any]     						=  RagConfig.from_pretrained(__magic_name__   )

													UpperCAmelCase_			:      List[Any]     						=  AutoTokenizer.from_pretrained(
													    __magic_name__       ,     config=config.question_encoder       ,     subfolder='''question_encoder_tokenizer'''   )
													UpperCAmelCase_			:      int     						=  AutoTokenizer.from_pretrained(
													    __magic_name__       ,     config=config.generator       ,     subfolder='''generator_tokenizer'''   )
													return cls(question_encoder=__magic_name__       ,     generator=__magic_name__   )

							def __call__(							self							:     Union[str, Any]       ,     *__magic_name__							:     Union[str, Any]       ,     **__magic_name__							:     List[str]   )					->       Any:







													"""simple docstring"""
													return self.current_tokenizer(*__magic_name__       ,     **__magic_name__   )

							def     UpperCAmelCase__	(							self							:     List[Any]       ,     *__magic_name__							:     Optional[int]       ,     **__magic_name__							:     Dict   )					->       Optional[int]:







													"""simple docstring"""
													return self.generator.batch_decode(*__magic_name__       ,     **__magic_name__   )

							def     UpperCAmelCase__	(							self							:     Union[str, Any]       ,     *__magic_name__							:     List[str]       ,     **__magic_name__							:     Optional[Any]   )					->       Optional[int]:







													"""simple docstring"""
													return self.generator.decode(*__magic_name__       ,     **__magic_name__   )

							def     UpperCAmelCase__	(							self							:     Dict   )					->       List[str]:







													"""simple docstring"""
													UpperCAmelCase_			:      int     						=  self.question_encoder

							def     UpperCAmelCase__	(							self							:     Any   )					->       Tuple:







													"""simple docstring"""
													UpperCAmelCase_			:      Tuple     						=  self.generator



							def     UpperCAmelCase__	(							self							:     Any       ,     __magic_name__							:     List[str]       ,     __magic_name__							:     Optional[List[str]] = None       ,     __magic_name__							:     Optional[int] = None       ,     __magic_name__							:     Optional[int] = None       ,     __magic_name__							:     str = "longest"       ,     __magic_name__							:     str = None       ,     __magic_name__							:     bool = True       ,     **__magic_name__							:     List[str]       ,     )					->       BatchEncoding:







													"""simple docstring"""
													warnings.warn(
													    '''`prepare_seq2seq_batch` is deprecated and will be removed in version 5 of 🤗 Transformers. Use the '''
													    '''regular `__call__` method to prepare your inputs and the tokenizer under the `with_target_tokenizer` '''
													    '''context manager to prepare your targets. See the documentation of your specific tokenizer for more '''
													    '''details'''       ,     __magic_name__       ,     )
													if max_length is None:
																			UpperCAmelCase_			:      List[Any]     						=  self.current_tokenizer.model_max_length
													UpperCAmelCase_			:      List[Any]     						=  self(
													    __magic_name__       ,     add_special_tokens=__magic_name__       ,     return_tensors=__magic_name__       ,     max_length=__magic_name__       ,     padding=__magic_name__       ,     truncation=__magic_name__       ,     **__magic_name__       ,     )
													if tgt_texts is None:
																			return model_inputs
													# Process tgt_texts
													if max_target_length is None:
																			UpperCAmelCase_			:      str     						=  self.current_tokenizer.model_max_length
													UpperCAmelCase_			:      Dict     						=  self(
													    text_target=__magic_name__       ,     add_special_tokens=__magic_name__       ,     return_tensors=__magic_name__       ,     padding=__magic_name__       ,     max_length=__magic_name__       ,     truncation=__magic_name__       ,     **__magic_name__       ,     )
													UpperCAmelCase_			:      Any     						=  labels['''input_ids''']
													return model_inputs












'''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 					__a      (lowerCamelCase     ):
							__a					:   List[Any]									=       "openai/whisper-base"
							__a					:   Optional[Any]									=       (
							    "This is a tool that transcribes an audio into text. It takes an input named `audio` and returns the "
							    "transcribed text."
							)
							__a					:   Any									=       "transcriber"
							__a					:   str									=       WhisperProcessor
							__a					:   List[Any]									=       WhisperForConditionalGeneration

							__a					:   int									=       ["audio"]
							__a					:   Optional[Any]									=       ["text"]

							def     UpperCAmelCase__	(							self							:     Dict       ,     __magic_name__							:     List[str]   )					->       Optional[int]:







													"""simple docstring"""
													return self.pre_processor(__magic_name__       ,     return_tensors='''pt'''   ).input_features

							def     UpperCAmelCase__	(							self							:     Dict       ,     __magic_name__							:     Dict   )					->       Tuple:







													"""simple docstring"""
													return self.model.generate(inputs=__magic_name__   )



							def     UpperCAmelCase__	(							self							:     List[str]       ,     __magic_name__							:     Dict   )					->       str:







													"""simple docstring"""
													return self.pre_processor.batch_decode(__magic_name__       ,     skip_special_tokens=__magic_name__   )[0]





