



from io import BytesIO
from typing import List, Union

import requests

from ..utils import add_end_docstrings, is_decord_available, is_torch_available, logging, requires_backends
from .base import PIPELINE_INIT_ARGS, Pipeline


if is_decord_available():
					import numpy as np
					from decord import VideoReader


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

UpperCamelCase_   	=	logging.get_logger(__name__)

@add_end_docstrings(__UpperCAmelCase					)
class       a		(   __UpperCAmelCase					):







							def __init__(						self  :  Optional[int]      ,				*snake_case__  :  List[Any]      ,				**snake_case__  :  int ):
								"""simple docstring"""







								super().__init__(*snake_case__      ,				**snake_case__ )
								requires_backends(self      ,				"decord" )
								self.check_model_type(snake_case__ )







							def       UpperCAmelCase__					(						self  :  Any      ,				snake_case__  :  str=None      ,				snake_case__  :  int=None      ,				snake_case__  :  List[str]=None ):
								"""simple docstring"""







								__lowerCAmelCase         =							{}
								if frame_sampling_rate is not None:
									__lowerCAmelCase         =							frame_sampling_rate
								if num_frames is not None:
									__lowerCAmelCase         =							num_frames

								__lowerCAmelCase         =							{}
								if top_k is not None:
									__lowerCAmelCase         =							top_k
								return preprocess_params, {}, postprocess_params







							def __call__(						self  :  Dict      ,				snake_case__  :  Union[str, List[str]]      ,				**snake_case__  :  Dict ):
								"""simple docstring"""







								return super().__call__(snake_case__      ,				**snake_case__ )







							def       UpperCAmelCase__					(						self  :  List[Any]      ,				snake_case__  :  Optional[Any]      ,				snake_case__  :  List[Any]=None      ,				snake_case__  :  Any=1 ):
								"""simple docstring"""







								if num_frames is None:
									__lowerCAmelCase         =							self.model.config.num_frames

								if video.startswith("http://" ) or video.startswith("https://" ):
									__lowerCAmelCase         =							BytesIO(requests.get(snake_case__ ).content )

								__lowerCAmelCase         =							VideoReader(snake_case__ )
								videoreader.seek(0 )

								__lowerCAmelCase         =							0
								__lowerCAmelCase         =							num_frames * frame_sampling_rate - 1
								__lowerCAmelCase         =							np.linspace(snake_case__      ,				snake_case__      ,				num=snake_case__      ,				dtype=np.intaa )

								__lowerCAmelCase         =							videoreader.get_batch(snake_case__ ).asnumpy()
								__lowerCAmelCase         =							list(snake_case__ )

								__lowerCAmelCase         =							self.image_processor(snake_case__      ,				return_tensors=self.framework )
								return model_inputs







							def       UpperCAmelCase__					(						self  :  Any      ,				snake_case__  :  Any ):
								"""simple docstring"""







								__lowerCAmelCase         =							self.model(**snake_case__ )
								return model_outputs







							def       UpperCAmelCase__					(						self  :  str      ,				snake_case__  :  Tuple      ,				snake_case__  :  str=5 ):
								"""simple docstring"""







								if top_k > self.model.config.num_labels:
									__lowerCAmelCase         =							self.model.config.num_labels

								if self.framework == "pt":
									__lowerCAmelCase         =							model_outputs.logits.softmax(-1 )[0]
									__lowerCAmelCase   ,						__lowerCAmelCase         =							probs.topk(snake_case__ )
								else:
									raise ValueError(F"Unsupported framework: {self.framework}" )

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








from collections import OrderedDict
from typing import Mapping

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


UpperCamelCase_   	=	logging.get_logger(__name__)

UpperCamelCase_   	=	{
    "distilbert-base-uncased": "https://huggingface.co/distilbert-base-uncased/resolve/main/config.json",
    "distilbert-base-uncased-distilled-squad": (
        "https://huggingface.co/distilbert-base-uncased-distilled-squad/resolve/main/config.json"
    ),
    "distilbert-base-cased": "https://huggingface.co/distilbert-base-cased/resolve/main/config.json",
    "distilbert-base-cased-distilled-squad": (
        "https://huggingface.co/distilbert-base-cased-distilled-squad/resolve/main/config.json"
    ),
    "distilbert-base-german-cased": "https://huggingface.co/distilbert-base-german-cased/resolve/main/config.json",
    "distilbert-base-multilingual-cased": (
        "https://huggingface.co/distilbert-base-multilingual-cased/resolve/main/config.json"
    ),
    "distilbert-base-uncased-finetuned-sst-2-english": (
        "https://huggingface.co/distilbert-base-uncased-finetuned-sst-2-english/resolve/main/config.json"
    ),
}

class       a		(   __UpperCAmelCase					):
							lowercase_		:						str   							=  'distilbert'
							lowercase_		:						Any   							=  {
							    'hidden_size': 'dim',
							    'num_attention_heads': 'n_heads',
							    'num_hidden_layers': 'n_layers',
							}







							def __init__(						self  :  Optional[int]      ,				snake_case__  :  int=30_522      ,				snake_case__  :  str=512      ,				snake_case__  :  Tuple=False      ,				snake_case__  :  Tuple=6      ,				snake_case__  :  Any=12      ,				snake_case__  :  Dict=768      ,				snake_case__  :  Any=4 * 768      ,				snake_case__  :  Union[str, Any]=0.1      ,				snake_case__  :  str=0.1      ,				snake_case__  :  Tuple="gelu"      ,				snake_case__  :  str=0.0_2      ,				snake_case__  :  Optional[Any]=0.1      ,				snake_case__  :  Optional[Any]=0.2      ,				snake_case__  :  str=0      ,				**snake_case__  :  Dict      ,				):
								"""simple docstring"""







								__lowerCAmelCase         =							vocab_size
								__lowerCAmelCase         =							max_position_embeddings
								__lowerCAmelCase         =							sinusoidal_pos_embds
								__lowerCAmelCase         =							n_layers
								__lowerCAmelCase         =							n_heads
								__lowerCAmelCase         =							dim
								__lowerCAmelCase         =							hidden_dim
								__lowerCAmelCase         =							dropout
								__lowerCAmelCase         =							attention_dropout
								__lowerCAmelCase         =							activation
								__lowerCAmelCase         =							initializer_range
								__lowerCAmelCase         =							qa_dropout
								__lowerCAmelCase         =							seq_classif_dropout
								super().__init__(**snake_case__      ,				pad_token_id=snake_case__ )

class       a		(   __UpperCAmelCase					):







							@property
							def       UpperCAmelCase__					(						self  :  Tuple ):
								"""simple docstring"""







								if self.task == "multiple-choice":
									__lowerCAmelCase         =							{0: "batch", 1: "choice", 2: "sequence"}
								else:
									__lowerCAmelCase         =							{0: "batch", 1: "sequence"}
								return OrderedDict(
								    [
								        ("input_ids", dynamic_axis),
								        ("attention_mask", dynamic_axis),
								    ] )






