

"""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_					:	int							  =						logging.get_logger(__name__)



@add_end_docstrings(_UpperCamelCase				)
class 					a						(       _UpperCamelCase				):



    """simple docstring"""



    def __init__(     self: Optional[int]    ,						*UpperCamelCase: List[str]    ,						**UpperCamelCase: Optional[Any]       ):






         """simple docstring"""


         super().__init__(*UpperCamelCase    ,						**UpperCamelCase       )
         requires_backends(self    ,						"""decord"""       )
         self.check_model_type(UpperCamelCase       )

    def 				UpperCamelCase	(     self: List[Any]    ,						UpperCamelCase: List[str]=None    ,						UpperCamelCase: int=None    ,						UpperCamelCase: str=None       ):






         """simple docstring"""


         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: Union[str, Any]    ,						UpperCamelCase: Union[str, List[str]]    ,						**UpperCamelCase: str       ):






         """simple docstring"""


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

    def 				UpperCamelCase	(     self: Optional[int]    ,						UpperCamelCase: Union[str, Any]    ,						UpperCamelCase: List[str]=None    ,						UpperCamelCase: Optional[int]=1       ):






         """simple docstring"""


         if num_frames is None:
              A__										=  self.model.config.num_frames

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

         A__										=  VideoReader(UpperCamelCase       )
         videoreader.seek(0       )

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

         A__										=  videoreader.get_batch(UpperCamelCase       ).asnumpy()
         A__										=  list(UpperCamelCase       )

         A__										=  self.image_processor(UpperCamelCase    ,						return_tensors=self.framework       )
         return model_inputs

    def 				UpperCamelCase	(     self: Dict    ,						UpperCamelCase: str       ):






         """simple docstring"""


         A__										=  self.model(**UpperCamelCase       )
         return model_outputs





    def 				UpperCamelCase	(     self: str    ,						UpperCamelCase: Any    ,						UpperCamelCase: int=5       ):






         """simple docstring"""


         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__										=  probs.topk(UpperCamelCase       )
         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(UpperCamelCase    ,						UpperCamelCase       )]









"""simple docstring"""



import warnings

from ...utils import logging
from .image_processing_videomae import VideoMAEImageProcessor


SCREAMING_SNAKE_CASE_					:	List[Any]							  =						logging.get_logger(__name__)



class 					a						(       _lowerCamelCase				):



    """simple docstring"""



    def __init__(     self: Tuple    ,						*UpperCamelCase: Optional[int]    ,						**UpperCamelCase: Tuple       ):






         """simple docstring"""


         warnings.warn(
             """The class VideoMAEFeatureExtractor is deprecated and will be removed in version 5 of Transformers."""
             """ Please use VideoMAEImageProcessor instead."""    ,						UpperCamelCase    ,						)
         super().__init__(*UpperCamelCase    ,						**UpperCamelCase       )






