






# 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 							_UpperCamelCase			(a_			):
      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  __UpperCAmelCase		(	self					,						__UpperCamelCase	)->	Optional[Any]:
           return self.pre_processor(__UpperCamelCase					,						return_tensors="pt"	).input_features


      def  __UpperCAmelCase		(	self					,						__UpperCamelCase	)->	Union[str, Any]:
           return self.model.generate(inputs=__UpperCamelCase	)


      def  __UpperCAmelCase		(	self					,						__UpperCamelCase	)->	Any:
           return self.pre_processor.batch_decode(__UpperCamelCase					,						skip_special_tokens=__UpperCamelCase	)[0]














from __future__ import annotations





def       __lowerCAmelCase      (						__snake_case					, __snake_case					, __snake_case       ):
     __lowerCAmelCase								=					list(range(len(__snake_case       )       )       )
     __lowerCAmelCase								=					[v / w for v, w in zip(__snake_case					, __snake_case       )]
     index.sort(key=lambda __snake_case       : ratio[i]					, reverse=__snake_case       )

     __lowerCAmelCase								=					0
     __lowerCAmelCase								=					[0] * len(__snake_case       )
     for i in index:
          if weight[i] <= capacity:
               __lowerCAmelCase								=					1
               max_value += value[i]
               capacity -= weight[i]
          else:
               __lowerCAmelCase								=					capacity / weight[i]
               max_value += value[i] * capacity / weight[i]
               break

     return max_value, fractions


if __name__ == "__main__":
 import doctest

 doctest.testmod()






