


from typing import TYPE_CHECKING

from ...utils import (
    OptionalDependencyNotAvailable,
    _LazyModule,
    is_sentencepiece_available,
    is_speech_available,
    is_tf_available,
    is_torch_available,
)


SCREAMING_SNAKE_CASE       :      List[str]												= {
    "configuration_speech_to_text": ["SPEECH_TO_TEXT_PRETRAINED_CONFIG_ARCHIVE_MAP", "Speech2TextConfig"],
    "processing_speech_to_text": ["Speech2TextProcessor"],
}

try:
 if not is_sentencepiece_available():
  raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
 pass
else:
 SCREAMING_SNAKE_CASE       :      Union[str, Any]												= ["Speech2TextTokenizer"]

try:
 if not is_speech_available():
  raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
 pass
else:
 SCREAMING_SNAKE_CASE       :      int												= ["Speech2TextFeatureExtractor"]

try:
 if not is_tf_available():
  raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
 pass
else:
 SCREAMING_SNAKE_CASE       :      Optional[Any]												= [
     "TF_SPEECH_TO_TEXT_PRETRAINED_MODEL_ARCHIVE_LIST",
     "TFSpeech2TextForConditionalGeneration",
     "TFSpeech2TextModel",
     "TFSpeech2TextPreTrainedModel",
 ]

try:
 if not is_torch_available():
  raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
 pass
else:
 SCREAMING_SNAKE_CASE       :      str												= [
     "SPEECH_TO_TEXT_PRETRAINED_MODEL_ARCHIVE_LIST",
     "Speech2TextForConditionalGeneration",
     "Speech2TextModel",
     "Speech2TextPreTrainedModel",
 ]


if TYPE_CHECKING:
 from .configuration_speech_to_text import SPEECH_TO_TEXT_PRETRAINED_CONFIG_ARCHIVE_MAP, SpeechaTextConfig
 from .processing_speech_to_text import SpeechaTextProcessor

 try:
  if not is_sentencepiece_available():
   raise OptionalDependencyNotAvailable()
 except OptionalDependencyNotAvailable:
  pass
 else:
  from .tokenization_speech_to_text import SpeechaTextTokenizer

 try:
  if not is_speech_available():
   raise OptionalDependencyNotAvailable()
 except OptionalDependencyNotAvailable:
  pass
 else:
  from .feature_extraction_speech_to_text import SpeechaTextFeatureExtractor

 try:
  if not is_tf_available():
   raise OptionalDependencyNotAvailable()
 except OptionalDependencyNotAvailable:
  pass
 else:
  from .modeling_tf_speech_to_text import (
      TF_SPEECH_TO_TEXT_PRETRAINED_MODEL_ARCHIVE_LIST,
      TFSpeechaTextForConditionalGeneration,
      TFSpeechaTextModel,
      TFSpeechaTextPreTrainedModel,
  )

 try:
  if not is_torch_available():
   raise OptionalDependencyNotAvailable()
 except OptionalDependencyNotAvailable:
  pass
 else:
  from .modeling_speech_to_text import (
      SPEECH_TO_TEXT_PRETRAINED_MODEL_ARCHIVE_LIST,
      SpeechaTextForConditionalGeneration,
      SpeechaTextModel,
      SpeechaTextPreTrainedModel,
  )

else:
 import sys

 SCREAMING_SNAKE_CASE       :      Optional[Any]												= _LazyModule(__name__, globals()["__file__"], _import_structure, module_spec=__spec__)






from typing import List, Union

from ..utils import (
    add_end_docstrings,
    is_tf_available,
    is_torch_available,
    is_vision_available,
    logging,
    requires_backends,
)
from .base import PIPELINE_INIT_ARGS, Pipeline


if is_vision_available():
 from PIL import Image

 from ..image_utils import load_image

if is_tf_available():
 import tensorflow as tf

 from ..models.auto.modeling_tf_auto import TF_MODEL_FOR_IMAGE_CLASSIFICATION_MAPPING
 from ..tf_utils import stable_softmax

if is_torch_available():
 from ..models.auto.modeling_auto import MODEL_FOR_IMAGE_CLASSIFICATION_MAPPING

SCREAMING_SNAKE_CASE       :      List[str]												= logging.get_logger(__name__)






@add_end_docstrings(_a   )
class _lowerCamelCase(						_a   ):
       def __init__(					self,      *lowerCamelCase,      **lowerCamelCase)       ->   int:




           """simple docstring"""

           super().__init__(*lowerCamelCase,      **lowerCamelCase)
           requires_backends(self,      'vision')
           self.check_model_type(
               TF_MODEL_FOR_IMAGE_CLASSIFICATION_MAPPING
               if self.framework == 'tf'
               else MODEL_FOR_IMAGE_CLASSIFICATION_MAPPING)
       def 			UpperCamelCase     (					self,      lowerCamelCase=None)       ->   int:




           """simple docstring"""

           _lowercase       :							Dict      		=		{}
           if top_k is not None:
               _lowercase       :							List[str]      		=		top_k
           return {}, {}, postprocess_params
       def __call__(					self,      lowerCamelCase,      **lowerCamelCase)       ->   Tuple:




           """simple docstring"""

           return super().__call__(lowerCamelCase,      **lowerCamelCase)
       def 			UpperCamelCase     (					self,      lowerCamelCase)       ->   str:




           """simple docstring"""

           _lowercase       :							Optional[Any]      		=		load_image(lowerCamelCase)
           _lowercase       :							List[str]      		=		self.image_processor(images=lowerCamelCase,      return_tensors=self.framework)
           return model_inputs
       def 			UpperCamelCase     (					self,      lowerCamelCase)       ->   List[str]:




           """simple docstring"""

           _lowercase       :							Optional[int]      		=		self.model(**lowerCamelCase)
           return model_outputs




       def 			UpperCamelCase     (					self,      lowerCamelCase,      lowerCamelCase=5)       ->   Dict:




           """simple docstring"""

           if top_k > self.model.config.num_labels:
               _lowercase       :							List[Any]      		=		self.model.config.num_labels

           if self.framework == "pt":
               _lowercase       :							int      		=		model_outputs.logits.softmax(-1)[0]
               _lowercase		,				_lowercase       :							Union[str, Any]      		=		probs.topk(lowerCamelCase)
           elif self.framework == "tf":
               _lowercase       :							int      		=		stable_softmax(model_outputs.logits,      axis=-1)[0]
               _lowercase       :							List[Any]      		=		tf.math.top_k(lowerCamelCase,      k=lowerCamelCase)
               _lowercase		,				_lowercase       :							Any      		=		topk.values.numpy(), topk.indices.numpy()
           else:
               raise ValueError(F'''Unsupported framework: {self.framework}''')

           _lowercase       :							str      		=		scores.tolist()
           _lowercase       :							str      		=		ids.tolist()
           return [{"score": score, "label": self.model.config.idalabel[_id]} for score, _id in zip(lowerCamelCase,      lowerCamelCase)]


