


from collections import UserDict
from typing import Union

import numpy as np
import requests

from ..utils import (
    add_end_docstrings,
    logging,
)
from .audio_classification import ffmpeg_read
from .base import PIPELINE_INIT_ARGS, Pipeline


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

@add_end_docstrings(_lowerCAmelCase				)
class     a		(_lowerCAmelCase				):




							"""simple docstring"""


							def __init__(							self	:  Optional[Any]   ,     **lowerCamelCase	:  List[str]    )     ->   Dict:
														super().__init__(**lowerCamelCase    )

														if self.framework != "pt":
																					raise ValueError(F'The {self.__class__} is only available in PyTorch.'    )
														# No specific FOR_XXX available yet

							def __call__(							self	:  List[Any]   ,     lowerCamelCase	:  Union[np.ndarray, bytes, str]   ,     **lowerCamelCase	:  Union[str, Any]    )     ->   Tuple:
														return super().__call__(lowerCamelCase   ,     **lowerCamelCase    )

							def    __snake_case (							self	:  Optional[Any]   ,     **lowerCamelCase	:  Optional[Any]    )     ->   str:
														__snake_case		:      List[Any]										=       {}
														if "candidate_labels" in kwargs:
																					__snake_case		:      Optional[int]										=       kwargs["candidate_labels"]
														if "hypothesis_template" in kwargs:
																					__snake_case		:      List[str]										=       kwargs["hypothesis_template"]

														return preprocess_params, {}, {}

							def    __snake_case (							self	:  List[str]   ,     lowerCamelCase	:  Union[str, Any]   ,     lowerCamelCase	:  Dict=None   ,     lowerCamelCase	:  Dict="This is a sound of {}."    )     ->   Optional[int]:
														if isinstance(lowerCamelCase   ,     lowerCamelCase    ):
																					if audio.startswith("http://"    ) or audio.startswith("https://"    ):
																												# We need to actually check for a real protocol, otherwise it's impossible to use a local file
																												# like http_huggingface_co.png
																												__snake_case		:      Dict										=       requests.get(lowerCamelCase    ).content
																					else:
																												with open(lowerCamelCase   ,     "rb"    ) as f:
																																			__snake_case		:      List[Any]										=       f.read()

														if isinstance(lowerCamelCase   ,     lowerCamelCase    ):
																					__snake_case		:      List[Any]										=       ffmpeg_read(lowerCamelCase   ,     self.feature_extractor.sampling_rate    )

														if not isinstance(lowerCamelCase   ,     np.ndarray    ):
																					raise ValueError("We expect a numpy ndarray as input"    )
														if len(audio.shape    ) != 1:
																					raise ValueError("We expect a single channel audio input for ZeroShotAudioClassificationPipeline"    )

														__snake_case		:      List[Any]										=       self.feature_extractor(
														    [audio]   ,     sampling_rate=self.feature_extractor.sampling_rate   ,     return_tensors="pt"    )
														__snake_case		:      str										=       candidate_labels
														__snake_case		:      List[str]										=       [hypothesis_template.format(lowerCamelCase    ) for x in candidate_labels]
														__snake_case		:      Union[str, Any]										=       self.tokenizer(lowerCamelCase   ,     return_tensors=self.framework   ,     padding=lowerCamelCase    )
														__snake_case		:      int										=       [text_inputs]
														return inputs

							def    __snake_case (							self	:  List[str]   ,     lowerCamelCase	:  Union[str, Any]    )     ->   List[str]:
														__snake_case		:      List[str]										=       model_inputs.pop("candidate_labels"    )
														__snake_case		:      str										=       model_inputs.pop("text_inputs"    )
														if isinstance(text_inputs[0]   ,     lowerCamelCase    ):
																					__snake_case		:      List[Any]										=       text_inputs[0]
														else:
																					# Batching case.
																					__snake_case		:      str										=       text_inputs[0][0]

														__snake_case		:      str										=       self.model(**lowerCamelCase   ,     **lowerCamelCase    )

														__snake_case		:      Tuple										=       {
														    "candidate_labels": candidate_labels,
														    "logits": outputs.logits_per_audio,
														}
														return model_outputs






							def    __snake_case (							self	:  Union[str, Any]   ,     lowerCamelCase	:  Union[str, Any]    )     ->   Optional[Any]:
														__snake_case		:      int										=       model_outputs.pop("candidate_labels"    )
														__snake_case		:      Union[str, Any]										=       model_outputs["logits"][0]

														if self.framework == "pt":
																					__snake_case		:      Tuple										=       logits.softmax(dim=0    )
																					__snake_case		:      int										=       probs.tolist()
														else:
																					raise ValueError("`tf` framework not supported."    )

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





from collections import OrderedDict
from typing import Mapping

from packaging import version

from ...configuration_utils import PretrainedConfig
from ...onnx import OnnxConfig
from ...utils import logging


_snake_case					:		int      =    logging.get_logger(__name__)

_snake_case					:		int      =    {
    "microsoft/beit-base-patch16-224-pt22k": (
        "https://huggingface.co/microsoft/beit-base-patch16-224-pt22k/resolve/main/config.json"
    ),
    # See all BEiT models at https://huggingface.co/models?filter=beit
}

class     a		(_lowerCAmelCase				):




							"""simple docstring"""


							__UpperCAmelCase   :							Union[str, Any]					  =  "beit"

							def __init__(							self	:  Union[str, Any]   ,     lowerCamelCase	:  Any=8192   ,     lowerCamelCase	:  Dict=768   ,     lowerCamelCase	:  int=12   ,     lowerCamelCase	:  Optional[Any]=12   ,     lowerCamelCase	:  List[str]=3072   ,     lowerCamelCase	:  Tuple="gelu"   ,     lowerCamelCase	:  Union[str, Any]=0.0   ,     lowerCamelCase	:  int=0.0   ,     lowerCamelCase	:  Dict=0.02   ,     lowerCamelCase	:  List[str]=1E-12   ,     lowerCamelCase	:  Optional[Any]=224   ,     lowerCamelCase	:  Optional[int]=16   ,     lowerCamelCase	:  Any=3   ,     lowerCamelCase	:  Optional[int]=False   ,     lowerCamelCase	:  Any=False   ,     lowerCamelCase	:  Optional[Any]=False   ,     lowerCamelCase	:  int=False   ,     lowerCamelCase	:  Any=0.1   ,     lowerCamelCase	:  Tuple=0.1   ,     lowerCamelCase	:  Optional[int]=True   ,     lowerCamelCase	:  int=[3, 5, 7, 11]   ,     lowerCamelCase	:  str=[1, 2, 3, 6]   ,     lowerCamelCase	:  int=True   ,     lowerCamelCase	:  List[Any]=0.4   ,     lowerCamelCase	:  int=256   ,     lowerCamelCase	:  str=1   ,     lowerCamelCase	:  List[str]=False   ,     lowerCamelCase	:  List[str]=255   ,     **lowerCamelCase	:  Dict   ,     )     ->   int:
														super().__init__(**lowerCamelCase    )

														__snake_case		:      Any										=       vocab_size
														__snake_case		:      List[str]										=       hidden_size
														__snake_case		:      List[Any]										=       num_hidden_layers
														__snake_case		:      Tuple										=       num_attention_heads
														__snake_case		:      Dict										=       intermediate_size
														__snake_case		:      Union[str, Any]										=       hidden_act
														__snake_case		:      Optional[Any]										=       hidden_dropout_prob
														__snake_case		:      Optional[int]										=       attention_probs_dropout_prob
														__snake_case		:      Union[str, Any]										=       initializer_range
														__snake_case		:      str										=       layer_norm_eps

														__snake_case		:      Optional[Any]										=       image_size
														__snake_case		:      List[str]										=       patch_size
														__snake_case		:      Optional[Any]										=       num_channels
														__snake_case		:      Any										=       use_mask_token
														__snake_case		:      List[str]										=       use_absolute_position_embeddings
														__snake_case		:      List[Any]										=       use_relative_position_bias
														__snake_case		:      str										=       use_shared_relative_position_bias
														__snake_case		:      str										=       layer_scale_init_value
														__snake_case		:      Any										=       drop_path_rate
														__snake_case		:      int										=       use_mean_pooling
														# decode head attributes (semantic segmentation)
														__snake_case		:      Optional[Any]										=       out_indices
														__snake_case		:      List[str]										=       pool_scales
														# auxiliary head attributes (semantic segmentation)
														__snake_case		:      int										=       use_auxiliary_head
														__snake_case		:      int										=       auxiliary_loss_weight
														__snake_case		:      Optional[int]										=       auxiliary_channels
														__snake_case		:      int										=       auxiliary_num_convs
														__snake_case		:      str										=       auxiliary_concat_input
														__snake_case		:      List[str]										=       semantic_loss_ignore_index

class     a		(_lowerCAmelCase				):




							"""simple docstring"""


							__UpperCAmelCase   :							Union[str, Any]					  =  version.parse("1.11"				)

							@property
							def    __snake_case (							self	:  Dict    )     ->   Mapping[str, Mapping[int, str]]:
														return OrderedDict(
														    [
														        ("pixel_values", {0: "batch", 1: "num_channels", 2: "height", 3: "width"}),
														    ]    )






							@property
							def    __snake_case (							self	:  str    )     ->   float:
														return 1E-4

