

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[Any]						     =  logging.get_logger(__name__)
@add_end_docstrings(__magic_name__)
class  _A		(  __magic_name__):

  def __init__(				self ,					*_SCREAMING_SNAKE_CASE ,					**_SCREAMING_SNAKE_CASE					):





        """simple docstring"""







        super().__init__(*_SCREAMING_SNAKE_CASE ,					**_SCREAMING_SNAKE_CASE					)
        requires_backends(self ,					'decord'					)
        self.check_model_type(_SCREAMING_SNAKE_CASE					)

  def  UpperCAmelCase    (				self ,					_SCREAMING_SNAKE_CASE=None ,					_SCREAMING_SNAKE_CASE=None ,					_SCREAMING_SNAKE_CASE=None					):





        """simple docstring"""







        SCREAMING_SNAKE_CASE_				:  Tuple           =     {}
        if frame_sampling_rate is not None:
              SCREAMING_SNAKE_CASE_				:  List[Any]           =     frame_sampling_rate
        if num_frames is not None:
              SCREAMING_SNAKE_CASE_				:  List[Any]           =     num_frames

        SCREAMING_SNAKE_CASE_				:  Any           =     {}
        if top_k is not None:
              SCREAMING_SNAKE_CASE_				:  Optional[Any]           =     top_k
        return preprocess_params, {}, postprocess_params

  def __call__(				self ,					_SCREAMING_SNAKE_CASE ,					**_SCREAMING_SNAKE_CASE					):





        """simple docstring"""







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

  def  UpperCAmelCase    (				self ,					_SCREAMING_SNAKE_CASE ,					_SCREAMING_SNAKE_CASE=None ,					_SCREAMING_SNAKE_CASE=1					):





        """simple docstring"""







        if num_frames is None:
              SCREAMING_SNAKE_CASE_				:  Dict           =     self.model.config.num_frames

        if video.startswith('http://'					) or video.startswith('https://'					):
              SCREAMING_SNAKE_CASE_				:  Optional[int]           =     BytesIO(requests.get(_SCREAMING_SNAKE_CASE					).content					)

        SCREAMING_SNAKE_CASE_				:  Any           =     VideoReader(_SCREAMING_SNAKE_CASE					)
        videoreader.seek(0					)

        SCREAMING_SNAKE_CASE_				:  Optional[int]           =     0
        SCREAMING_SNAKE_CASE_				:  Optional[int]           =     num_frames * frame_sampling_rate - 1
        SCREAMING_SNAKE_CASE_				:  Tuple           =     np.linspace(_SCREAMING_SNAKE_CASE ,					_SCREAMING_SNAKE_CASE ,					num=_SCREAMING_SNAKE_CASE ,					dtype=np.intaa					)

        SCREAMING_SNAKE_CASE_				:  Union[str, Any]           =     videoreader.get_batch(_SCREAMING_SNAKE_CASE					).asnumpy()
        SCREAMING_SNAKE_CASE_				:  List[str]           =     list(_SCREAMING_SNAKE_CASE					)

        SCREAMING_SNAKE_CASE_				:  Union[str, Any]           =     self.image_processor(_SCREAMING_SNAKE_CASE ,					return_tensors=self.framework					)
        return model_inputs

  def  UpperCAmelCase    (				self ,					_SCREAMING_SNAKE_CASE					):





        """simple docstring"""







        SCREAMING_SNAKE_CASE_				:  List[Any]           =     self.model(**_SCREAMING_SNAKE_CASE					)
        return model_outputs



  def  UpperCAmelCase    (				self ,					_SCREAMING_SNAKE_CASE ,					_SCREAMING_SNAKE_CASE=5					):





        """simple docstring"""







        if top_k > self.model.config.num_labels:
              SCREAMING_SNAKE_CASE_				:  Union[str, Any]           =     self.model.config.num_labels

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

        SCREAMING_SNAKE_CASE_				:  str           =     scores.tolist()
        SCREAMING_SNAKE_CASE_				:  Union[str, Any]           =     ids.tolist()
        return [{"score": score, "label": self.model.config.idalabel[_id]} for score, _id in zip(_SCREAMING_SNAKE_CASE ,					_SCREAMING_SNAKE_CASE					)]









from __future__ import annotations

import math

lowerCAmelCase     :   List[str]						     =  '2020.9.26'
lowerCAmelCase     :   List[Any]						     =  'xcodz-dot, cclaus, dhruvmanila'

def    A_  (							a					,   a					,   a					,   a					,   a  ):

      """simple docstring"""



      if not all(isinstance(a					,   (float, int)  ) for val in locals().values()  ):
            SCREAMING_SNAKE_CASE_				:  Optional[Any]           =     f"Input values must either be float or int: {list(locals().values()  )}"
            raise TypeError(a  )
      SCREAMING_SNAKE_CASE_				:  Optional[Any]           =     ((x * distance) / (z + distance)) * scale
      SCREAMING_SNAKE_CASE_				:  int           =     ((y * distance) / (z + distance)) * scale
      return projected_x, projected_y

def    A_  (							a					,   a					,   a					,   a					,   a  ):

      """simple docstring"""



      if not isinstance(a					,   a  ):
            raise TypeError('Axis must be a str'  )
      SCREAMING_SNAKE_CASE_				:  Any           =     locals()
      del input_variables["axis"]
      if not all(isinstance(a					,   (float, int)  ) for val in input_variables.values()  ):
            SCREAMING_SNAKE_CASE_				:  Optional[Any]           =     (
                'Input values except axis must either be float or int: '
                f"{list(input_variables.values()  )}"
            )
            raise TypeError(a  )
      SCREAMING_SNAKE_CASE_				:  List[Any]           =     (angle % 3_6_0) / 4_5_0 * 1_8_0 / math.pi
      if axis == "z":
            SCREAMING_SNAKE_CASE_				:  List[str]           =     x * math.cos(a  ) - y * math.sin(a  )
            SCREAMING_SNAKE_CASE_				:  List[Any]           =     y * math.cos(a  ) + x * math.sin(a  )
            SCREAMING_SNAKE_CASE_				:  Dict           =     z
      elif axis == "x":
            SCREAMING_SNAKE_CASE_				:  Any           =     y * math.cos(a  ) - z * math.sin(a  )
            SCREAMING_SNAKE_CASE_				:  Optional[Any]           =     z * math.cos(a  ) + y * math.sin(a  )
            SCREAMING_SNAKE_CASE_				:  str           =     x
      elif axis == "y":
            SCREAMING_SNAKE_CASE_				:  str           =     x * math.cos(a  ) - z * math.sin(a  )
            SCREAMING_SNAKE_CASE_				:  List[str]           =     z * math.cos(a  ) + x * math.sin(a  )
            SCREAMING_SNAKE_CASE_				:  Any           =     y
      else:
            raise ValueError('not a valid axis, choose one of \'x\', \'y\', \'z\''  )

      return new_x, new_y, new_z


if __name__ == "__main__":
    import doctest

    doctest.testmod()
    print(F'{convert_to_ad(1.0, 2.0, 3.0, 10.0, 10.0) = }')
    print(F'{rotate(1.0, 2.0, 3.0, "y", 90.0) = }')






