
"""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

SCREAMING_SNAKE_CASE_					     =	logging.get_logger(__name__)
@add_end_docstrings(_UpperCamelCase )
class       lowerCAmelCase_		(				_UpperCamelCase ):



							'''simple docstring'''





							def __init__( self    ,				*snake_case_    ,				**snake_case_				)       ->  Any:
													super().__init__(*_UpperCAmelCase    ,				**_UpperCAmelCase				)
													requires_backends(self    ,				"""decord"""				)
													self.check_model_type(_UpperCAmelCase				)




							def    A__						( self    ,				snake_case_=None    ,				snake_case_=None    ,				snake_case_=None				)       ->  List[str]:
													__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    ,				snake_case_    ,				**snake_case_				)       ->  List[Any]:
													return super().__call__(_UpperCAmelCase    ,				**_UpperCAmelCase				)




							def    A__						( self    ,				snake_case_    ,				snake_case_=None    ,				snake_case_=1				)       ->  Optional[Any]:
													if num_frames is None:
																			__lowerCAmelCase     =  self.model.config.num_frames

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

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

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

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

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




							def    A__						( self    ,				snake_case_				)       ->  int:
													__lowerCAmelCase     =  self.model(**_UpperCAmelCase				)
													return model_outputs




							def    A__						( self    ,				snake_case_    ,				snake_case_=5				)       ->  str:
													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     =  probs.topk(_UpperCAmelCase				)
													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(_UpperCAmelCase    ,				_UpperCAmelCase				)]





'''simple docstring'''

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




