


import importlib.metadata
import operator
import re
import sys
from typing import Optional

from packaging import version


_snake_case             =     {
    '''<''': operator.lt,
    '''<=''': operator.le,
    '''==''': operator.eq,
    '''!=''': operator.ne,
    '''>=''': operator.ge,
    '''>''': operator.gt,
}






def 		lowercase_(  SCREAMING_SNAKE_CASE_      ,						SCREAMING_SNAKE_CASE_      ,						SCREAMING_SNAKE_CASE_      ,						SCREAMING_SNAKE_CASE_      ,						SCREAMING_SNAKE_CASE_      ,						SCREAMING_SNAKE_CASE_	):


  '''simple docstring'''

  if got_ver is None or want_ver is None:
    raise ValueError(
        f"""Unable to compare versions for {requirement}: need={want_ver} found={got_ver}. This is unusual. Consider"""
        f""" reinstalling {pkg}."""	)
  if not ops[op](version.parse(SCREAMING_SNAKE_CASE_	)      ,						version.parse(SCREAMING_SNAKE_CASE_	)	):
    raise ImportError(
        f"""{requirement} is required for a normal functioning of this module, but found {pkg}=={got_ver}.{hint}"""	)






def 		lowercase_(  SCREAMING_SNAKE_CASE_      ,						SCREAMING_SNAKE_CASE_ = None	):


  '''simple docstring'''

  lowerCamelCase :					Union[str, Any]    =				f"""\n{hint}""" if hint is not None else ""

  # non-versioned check
  if re.match(r"^[\w_\-\d]+$"      ,						SCREAMING_SNAKE_CASE_	):
    lowerCamelCase    ,	lowerCamelCase    ,	lowerCamelCase :					Union[str, Any]    =				requirement, None, None
  else:
    lowerCamelCase :					Any    =				re.findall(r"^([^!=<>\s]+)([\s!=<>]{1,2}.+)"      ,						SCREAMING_SNAKE_CASE_	)
    if not match:
      raise ValueError(
          "requirement needs to be in the pip package format, .e.g., package_a==1.23, or package_b>=1.23, but"
          f""" got {requirement}"""	)
    lowerCamelCase    ,	lowerCamelCase :					Tuple    =				match[0]
    lowerCamelCase :					Union[str, Any]    =				want_full.split(","	)  # there could be multiple requirements
    lowerCamelCase :					str    =				{}
    for w in want_range:
      lowerCamelCase :					Dict    =				re.findall(r"^([\s!=<>]{1,2})(.+)"      ,						SCREAMING_SNAKE_CASE_	)
      if not match:
        raise ValueError(
            "requirement needs to be in the pip package format, .e.g., package_a==1.23, or package_b>=1.23,"
            f""" but got {requirement}"""	)
      lowerCamelCase    ,	lowerCamelCase :					List[Any]    =				match[0]
      lowerCamelCase :					Tuple    =				want_ver
      if op not in ops:
        raise ValueError(f"""{requirement}: need one of {list(ops.keys()	)}, but got {op}"""	)

    # special case
  if pkg == "python":
    lowerCamelCase :					Union[str, Any]    =				".".join([str(SCREAMING_SNAKE_CASE_	) for x in sys.version_info[:3]]	)
    for op, want_ver in wanted.items():
      _compare_versions(SCREAMING_SNAKE_CASE_      ,						SCREAMING_SNAKE_CASE_      ,						SCREAMING_SNAKE_CASE_      ,						SCREAMING_SNAKE_CASE_      ,						SCREAMING_SNAKE_CASE_      ,						SCREAMING_SNAKE_CASE_	)
    return

  # check if any version is installed
  try:
    lowerCamelCase :					Tuple    =				importlib.metadata.version(SCREAMING_SNAKE_CASE_	)
  except importlib.metadata.PackageNotFoundError:
    raise importlib.metadata.PackageNotFoundError(
        f"""The '{requirement}' distribution was not found and is required by this application. {hint}"""	)

  # check that the right version is installed if version number or a range was provided
  if want_ver is not None:
    for op, want_ver in wanted.items():
      _compare_versions(SCREAMING_SNAKE_CASE_      ,						SCREAMING_SNAKE_CASE_      ,						SCREAMING_SNAKE_CASE_      ,						SCREAMING_SNAKE_CASE_      ,						SCREAMING_SNAKE_CASE_      ,						SCREAMING_SNAKE_CASE_	)







def 		lowercase_(  SCREAMING_SNAKE_CASE_	):


  '''simple docstring'''

  lowerCamelCase :					List[str]    =				"Try: pip install transformers -U or pip install -e '.[dev]' if you're working with git main"
  return require_version(SCREAMING_SNAKE_CASE_      ,						SCREAMING_SNAKE_CASE_	)







# 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_					(					UpperCamelCase    ):

   '''simple docstring'''




   __A :      Dict     		=		"openai/whisper-base"
   __A :      str     		=		(
       "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 :      Any     		=		WhisperProcessor
   __A :      int     		=		WhisperForConditionalGeneration

   __A :      Any     		=		["audio"]
   __A :      List[str]     		=		["text"]






   def _snake_case    (		self						,				__A ):






     """simple docstring"""





     return self.pre_processor(__A						,				return_tensors="pt" ).input_features






   def _snake_case    (		self						,				__A ):






     """simple docstring"""





     return self.model.generate(inputs=__A )






   def _snake_case    (		self						,				__A ):






     """simple docstring"""





     return self.pre_processor.batch_decode(__A						,				skip_special_tokens=__A )[0]



