
from collections import UserDict
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_torch_available():
		from ..models.auto.modeling_auto import MODEL_FOR_ZERO_SHOT_IMAGE_CLASSIFICATION_MAPPING

if is_tf_available():
		from ..models.auto.modeling_tf_auto import TF_MODEL_FOR_ZERO_SHOT_IMAGE_CLASSIFICATION_MAPPING
		from ..tf_utils import stable_softmax

lowercase						:      int									= logging.get_logger(__name__)




@add_end_docstrings(__lowercase)
class 				lowerCamelCase__							(       __lowercase):




	'''simple docstring'''




	def __init__(      self	:Any  ,     **a	:Any		)	->				str:
								super().__init__(**a		)

								requires_backends(self  ,     "vision"		)
								self.check_model_type(
								    TF_MODEL_FOR_ZERO_SHOT_IMAGE_CLASSIFICATION_MAPPING
								    if self.framework == "tf"
								    else MODEL_FOR_ZERO_SHOT_IMAGE_CLASSIFICATION_MAPPING		)







	def __call__(      self	:List[str]  ,     a	:Union[str, List[str], "Image", List["Image"]]  ,     **a	:Dict		)	->				Union[str, Any]:
								return super().__call__(a  ,     **a		)







	def      _lowerCamelCase       (      self	:int  ,     **a	:Any		)	->				Dict:
								__UpperCamelCase			:     Dict         =      {}
								if "candidate_labels" in kwargs:
															__UpperCamelCase			:     List[str]         =      kwargs["candidate_labels"]
								if "hypothesis_template" in kwargs:
															__UpperCamelCase			:     List[Any]         =      kwargs["hypothesis_template"]

								return preprocess_params, {}, {}







	def      _lowerCamelCase       (      self	:Tuple  ,     a	:Tuple  ,     a	:Tuple=None  ,     a	:Optional[Any]="This is a photo of {}."		)	->				List[str]:
								__UpperCamelCase			:     Optional[int]         =      load_image(a		)
								__UpperCamelCase			:     Union[str, Any]         =      self.image_processor(images=[image]  ,     return_tensors=self.framework		)
								__UpperCamelCase			:     Optional[Any]         =      candidate_labels
								__UpperCamelCase			:     str         =      [hypothesis_template.format(a		) for x in candidate_labels]
								__UpperCamelCase			:     List[str]         =      self.tokenizer(a  ,     return_tensors=self.framework  ,     padding=a		)
								__UpperCamelCase			:     Tuple         =      [text_inputs]
								return inputs







	def      _lowerCamelCase       (      self	:int  ,     a	:str		)	->				List[Any]:
								__UpperCamelCase			:     int         =      model_inputs.pop("candidate_labels"		)
								__UpperCamelCase			:     Optional[int]         =      model_inputs.pop("text_inputs"		)
								if isinstance(text_inputs[0]  ,     a		):
															__UpperCamelCase			:     int         =      text_inputs[0]
								else:
															# Batching case.
															__UpperCamelCase			:     Optional[int]         =      text_inputs[0][0]

								__UpperCamelCase			:     Any         =      self.model(**a  ,     **a		)

								__UpperCamelCase			:     Union[str, Any]         =      {
								    "candidate_labels": candidate_labels,
								    "logits": outputs.logits_per_image,
								}
								return model_outputs







	def      _lowerCamelCase       (      self	:Optional[int]  ,     a	:Union[str, Any]		)	->				str:
								__UpperCamelCase			:     List[str]         =      model_outputs.pop("candidate_labels"		)
								__UpperCamelCase			:     Optional[Any]         =      model_outputs["logits"][0]
								if self.framework == "pt":
															__UpperCamelCase			:     str         =      logits.softmax(dim=-1		).squeeze(-1		)
															__UpperCamelCase			:     Any         =      probs.tolist()
															if not isinstance(a  ,     a		):
																						__UpperCamelCase			:     Optional[int]         =      [scores]
								elif self.framework == "tf":
															__UpperCamelCase			:     Union[str, Any]         =      stable_softmax(a  ,     axis=-1		)
															__UpperCamelCase			:     str         =      probs.numpy().tolist()
								else:
															raise ValueError(f'Unsupported framework: {self.framework}'		)

								__UpperCamelCase			:     Any         =      [
								    {"score": score, "label": candidate_label}
								    for score, candidate_label in sorted(zip(a  ,     a		)  ,     key=lambda a		: -x[0]		)
								]
								return result

from ...configuration_utils import PretrainedConfig
from ...utils import logging


lowercase						:      Dict									= logging.get_logger(__name__)

lowercase						:      Optional[Any]									= {
    'facebook/s2t-wav2vec2-large-en-de': (
        'https://huggingface.co/facebook/s2t-wav2vec2-large-en-de/resolve/main/config.json'
    ),
    # See all Speech2Text models at https://huggingface.co/models?filter=speech2text2
}




class 				lowerCamelCase__							(       __lowercase):




	'''simple docstring'''




	_A			=  'speech_to_text_2'
	_A			=  ['past_key_values']
	_A			=  {'num_attention_heads': 'decoder_attention_heads', 'hidden_size': 'd_model'}







	def __init__(      self	:Dict  ,     a	:Tuple=1_0_0_0_0  ,     a	:Optional[int]=6  ,     a	:List[str]=2_0_4_8  ,     a	:Tuple=4  ,     a	:List[Any]=0.0  ,     a	:str=True  ,     a	:Any="relu"  ,     a	:Any=2_5_6  ,     a	:Optional[int]=0.1  ,     a	:Any=0.0  ,     a	:int=0.0  ,     a	:int=0.02  ,     a	:List[Any]=2  ,     a	:Tuple=True  ,     a	:str=1  ,     a	:Optional[int]=0  ,     a	:List[Any]=2  ,     a	:Any=1_0_2_4  ,     **a	:str  ,     )	->				int:
								__UpperCamelCase			:     List[str]         =      vocab_size
								__UpperCamelCase			:     int         =      d_model
								__UpperCamelCase			:     Optional[int]         =      decoder_ffn_dim
								__UpperCamelCase			:     Any         =      decoder_layers
								__UpperCamelCase			:     Any         =      decoder_attention_heads
								__UpperCamelCase			:     Tuple         =      dropout
								__UpperCamelCase			:     Any         =      attention_dropout
								__UpperCamelCase			:     Any         =      activation_dropout
								__UpperCamelCase			:     Dict         =      activation_function
								__UpperCamelCase			:     int         =      init_std
								__UpperCamelCase			:     List[str]         =      decoder_layerdrop
								__UpperCamelCase			:     Optional[Any]         =      use_cache
								__UpperCamelCase			:     int         =      decoder_layers
								__UpperCamelCase			:     Union[str, Any]         =      scale_embedding  # scale factor will be sqrt(d_model) if True
								__UpperCamelCase			:     Dict         =      max_target_positions

								super().__init__(
								    pad_token_id=a  ,     bos_token_id=a  ,     eos_token_id=a  ,     decoder_start_token_id=a  ,     **a  ,     )