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

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






@add_end_docstrings(UpperCAmelCase   )
class 						A   (   UpperCAmelCase   ):





							def __init__(      self				:							Optional[Any]     ,		*__a				:							Union[str, Any]     ,		**__a				:							str	)							->	int:
								super().__init__(*__a     ,		**__a	)
								requires_backends(self     ,		'''decord'''	)
								self.check_model_type(__a	)





							def       snake_case__						(      self				:							Tuple     ,		__a				:							Tuple=None     ,		__a				:							Optional[Any]=None     ,		__a				:							Optional[int]=None	)							->	Any:
								__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				:							Dict     ,		__a				:							Union[str, List[str]]     ,		**__a				:							Dict	)							->	Optional[Any]:
								return super().__call__(__a     ,		**__a	)





							def       snake_case__						(      self				:							Union[str, Any]     ,		__a				:							Tuple     ,		__a				:							List[Any]=None     ,		__a				:							Optional[int]=1	)							->	List[str]:
								if num_frames is None:
									__UpperCAmelCase							=			self.model.config.num_frames

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

								__UpperCAmelCase							=			VideoReader(__a	)
								videoreader.seek(0	)

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

								__UpperCAmelCase							=			videoreader.get_batch(__a	).asnumpy()
								__UpperCAmelCase							=			list(__a	)

								__UpperCAmelCase							=			self.image_processor(__a     ,		return_tensors=self.framework	)
								return model_inputs





							def       snake_case__						(      self				:							Optional[Any]     ,		__a				:							Union[str, Any]	)							->	Optional[int]:
								__UpperCAmelCase							=			self.model(**__a	)
								return model_outputs






							def       snake_case__						(      self				:							Optional[int]     ,		__a				:							List[Any]     ,		__a				:							str=5	)							->	int:
								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(__a	)
								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(__a     ,		__a	)]

'''simple docstring'''


def       lowerCAmelCase					(		UpperCamelCase__				:   int       ):


	"""simple docstring"""

	if not isinstance(UpperCamelCase__    ,					UpperCamelCase__       ):
		__UpperCAmelCase							=			f"""Input value of [number={number}] must be an integer"""
		raise TypeError(UpperCamelCase__       )

	if number < 1:
		__UpperCAmelCase							=			f"""Input value of [number={number}] must be > 0"""
		raise ValueError(UpperCamelCase__       )

	__UpperCAmelCase							=			1

	for i in range(1    ,					UpperCamelCase__       ):
		current_number *= 4 * i - 2
		current_number //= i + 1

	return current_number


if __name__ == "__main__":
					import doctest

					doctest.testmod()
