




'''simple docstring'''







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

A     :   Tuple									=logging.get_logger(__name__)


@add_end_docstrings(__a				)
class     _a						(			__a				):
       def __init__(			self		:			Any     ,       *lowercase		:			Optional[int]     ,       **lowercase		:			Optional[Any]       ):



           '''simple docstring'''

           super().__init__(*lowercase     ,       **lowercase       )
           requires_backends(self     ,       '''decord'''       )
           self.check_model_type(lowercase       )
       def 					A   (			self		:			Optional[Any]     ,       lowercase		:			Dict=None     ,       lowercase		:			List[str]=None     ,       lowercase		:			int=None       ):



           '''simple docstring'''

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

           UpperCAmelCase     =	{}
           if top_k is not None:
               UpperCAmelCase     =	top_k
           return preprocess_params, {}, postprocess_params
       def __call__(			self		:			Union[str, Any]     ,       lowercase		:			Union[str, List[str]]     ,       **lowercase		:			int       ):



           '''simple docstring'''

           return super().__call__(lowercase     ,       **lowercase       )
       def 					A   (			self		:			List[str]     ,       lowercase		:			List[str]     ,       lowercase		:			str=None     ,       lowercase		:			List[Any]=1       ):



           '''simple docstring'''

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

           if video.startswith('''http://'''       ) or video.startswith('''https://'''       ):
               UpperCAmelCase     =	BytesIO(requests.get(lowercase       ).content       )

           UpperCAmelCase     =	VideoReader(lowercase       )
           videoreader.seek(0       )

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

           UpperCAmelCase     =	videoreader.get_batch(lowercase       ).asnumpy()
           UpperCAmelCase     =	list(lowercase       )

           UpperCAmelCase     =	self.image_processor(lowercase     ,       return_tensors=self.framework       )
           return model_inputs
       def 					A   (			self		:			Optional[int]     ,       lowercase		:			str       ):



           '''simple docstring'''

           UpperCAmelCase     =	self.model(**lowercase       )
           return model_outputs







       def 					A   (			self		:			Tuple     ,       lowercase		:			Any     ,       lowercase		:			List[Any]=5       ):



           '''simple docstring'''

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

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

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










'''simple docstring'''







from .configuration_bert_masked import MaskedBertConfig
from .modeling_bert_masked import (
    MaskedBertForMultipleChoice,
    MaskedBertForQuestionAnswering,
    MaskedBertForSequenceClassification,
    MaskedBertForTokenClassification,
    MaskedBertModel,
)
from .modules import *




