

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

				__SCREAMING_SNAKE_CASE   :					str			     =     ['''audio''']
				__SCREAMING_SNAKE_CASE   :					List[Any]			     =     ['''text''']




				def        a				(   self ,  snake_case			):
											return self.pre_processor(snake_case ,  return_tensors='pt'			).input_features




				def        a				(   self ,  snake_case			):
											return self.model.generate(inputs=snake_case			)




				def        a				(   self ,  snake_case			):
											return self.pre_processor.batch_decode(snake_case ,  skip_special_tokens=snake_case			)[0]







import tempfile
import unittest

from make_student import create_student_by_copying_alternating_layers

from transformers import AutoConfig
from transformers.file_utils import cached_property
from transformers.testing_utils import require_torch


_UpperCAmelCase						:  Dict									=			"""sshleifer/bart-tiny-random"""
_UpperCAmelCase						:  Optional[Any]									=			"""patrickvonplaten/t5-tiny-random"""







@require_torch
class 					lowercase							(			unittest.TestCase     ):




				@cached_property
				def        a				(   self			):
											return AutoConfig.from_pretrained(snake_case			)




				def        a				(   self			):
											snake_case_							,       *snake_case_     							=       create_student_by_copying_alternating_layers(snake_case ,  tempfile.mkdtemp() ,  e=1 ,  d=1			)
											self.assertEqual(student.config.num_hidden_layers ,  1			)




				def        a				(   self			):
											snake_case_							,       *snake_case_     							=       create_student_by_copying_alternating_layers(snake_case ,  tempfile.mkdtemp() ,  e=1 ,  d=snake_case			)




				def        a				(   self			):
											snake_case_							,       *snake_case_     							=       create_student_by_copying_alternating_layers(snake_case ,  tempfile.mkdtemp() ,  e=1 ,  d=snake_case			)
											self.assertEqual(student.config.encoder_layers ,  1			)
											self.assertEqual(student.config.decoder_layers ,  self.teacher_config.encoder_layers			)




				def        a				(   self			):
											snake_case_							,       *snake_case_     							=       create_student_by_copying_alternating_layers(snake_case ,  tempfile.mkdtemp() ,  e=1 ,  d=1			)
											self.assertEqual(student.config.encoder_layers ,  1			)
											self.assertEqual(student.config.decoder_layers ,  1			)




				def        a				(   self			):
											with self.assertRaises(snake_case			):
																		create_student_by_copying_alternating_layers(snake_case ,  tempfile.mkdtemp() ,  e=snake_case ,  d=snake_case			)




