



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(SCREAMING_SNAKE_CASE)
class  __snake_case      (   SCREAMING_SNAKE_CASE):







							'''simple docstring'''






							def __init__(							self  ,  *a_  ,  **a_		):
											super().__init__(*a_  ,  **a_		)
											requires_backends(self  ,  """decord"""		)
											self.check_model_type(a_		)


							def _a      (							self  ,  a_=None  ,  a_=None  ,  a_=None		):
											a__				      =		{}
											if frame_sampling_rate is not None:
															a__				      =		frame_sampling_rate
											if num_frames is not None:
															a__				      =		num_frames

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


							def __call__(							self  ,  a_  ,  **a_		):
											return super().__call__(a_  ,  **a_		)


							def _a      (							self  ,  a_  ,  a_=None  ,  a_=1		):
											if num_frames is None:
															a__				      =		self.model.config.num_frames

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

											a__				      =		VideoReader(a_		)
											videoreader.seek(0		)

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

											a__				      =		videoreader.get_batch(a_		).asnumpy()
											a__				      =		list(a_		)

											a__				      =		self.image_processor(a_  ,  return_tensors=self.framework		)
											return model_inputs


							def _a      (							self  ,  a_		):
											a__				      =		self.model(**a_		)
											return model_outputs







							def _a      (							self  ,  a_  ,  a_=5		):
											if top_k > self.model.config.num_labels:
															a__				      =		self.model.config.num_labels

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

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






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

