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

lowercase__  :      Tuple        =					logging.get_logger(__name__)







@add_end_docstrings(lowerCamelCase					)
class lowerCamelCase							(	lowerCamelCase					):




  '''simple docstring'''



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






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






  def  lowerCAmelCase__ (      self			:       List[Any]  ,							UpperCAmelCase__			:       Optional[int]  ,							UpperCAmelCase__			:       Optional[Any]=None  ,							UpperCAmelCase__			:       Tuple=1  )				->str:
        if num_frames is None:
              UpperCAmelCase_            =  self.model.config.num_frames

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

        UpperCAmelCase_            =  VideoReader(UpperCAmelCase__  )
        videoreader.seek(0  )

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

        UpperCAmelCase_            =  videoreader.get_batch(UpperCAmelCase__  ).asnumpy()
        UpperCAmelCase_            =  list(UpperCAmelCase__  )

        UpperCAmelCase_            =  self.image_processor(UpperCAmelCase__  ,							return_tensors=self.framework  )
        return model_inputs






  def  lowerCAmelCase__ (      self			:       List[str]  ,							UpperCAmelCase__			:       List[str]  )				->Tuple:
        UpperCAmelCase_            =  self.model(**UpperCAmelCase__  )
        return model_outputs






  def  lowerCAmelCase__ (      self			:       Dict  ,							UpperCAmelCase__			:       Tuple  ,							UpperCAmelCase__			:       Optional[int]=5  )				->Tuple:
        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(UpperCAmelCase__  )
        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(UpperCAmelCase__  ,							UpperCAmelCase__  )]






'''simple docstring'''
from collections.abc import Callable



def  __lowerCamelCase       (      _UpperCamelCase  :  Callable[[float], float]							,    _UpperCamelCase  :  float							,    _UpperCamelCase  :  float					):


      '''simple docstring'''


      UpperCAmelCase_            =  a
      UpperCAmelCase_            =  b
      if function(_UpperCamelCase					) == 0:  # one of the a or b is a root for the function
            return a
      elif function(_UpperCamelCase					) == 0:
            return b
      elif (
          function(_UpperCamelCase					) * function(_UpperCamelCase					) > 0
      ):  # if none of these are root and they are both positive or negative,
            # then this algorithm can't find the root
            raise ValueError('''could not find root in given interval.'''					)
      else:
            UpperCAmelCase_            =  start + (end - start) / 2.0
            while abs(start - mid					) > 10**-7:  # until precisely equals to 10^-7
                  if function(_UpperCamelCase					) == 0:
                        return mid
                  elif function(_UpperCamelCase					) * function(_UpperCamelCase					) < 0:
                        UpperCAmelCase_            =  mid
                  else:
                        UpperCAmelCase_            =  mid
                  UpperCAmelCase_            =  start + (end - start) / 2.0
            return mid



def  __lowerCamelCase       (      _UpperCamelCase  :  float					):


      '''simple docstring'''


      return x**3 - 2 * x - 5


if __name__ == "__main__":
      print(bisection(f, 1, 1000))

      import doctest

      doctest.testmod()





