




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		:  List[str]	=   logging.get_logger(__name__)




@add_end_docstrings(lowerCAmelCase)
class       __lowerCAmelCase				(							lowerCAmelCase):






       def __init__(      self:    Optional[int]				,    *_lowerCAmelCase:    Any				,    **_lowerCAmelCase:    Optional[Any] ):
         super().__init__(*_lowerCAmelCase				,    **_lowerCAmelCase )
         requires_backends(self				,    "decord" )
         self.check_model_type(_lowerCAmelCase )






       def     SCREAMING_SNAKE_CASE			(      self:    Optional[int]				,    _lowerCAmelCase:    int=None				,    _lowerCAmelCase:    List[str]=None				,    _lowerCAmelCase:    Optional[Any]=None ):
         lowercase			:Any							=  {}
         if frame_sampling_rate is not None:
           lowercase			:Union[str, Any]							=  frame_sampling_rate
         if num_frames is not None:
           lowercase			:List[str]							=  num_frames

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






       def __call__(      self:    Optional[int]				,    _lowerCAmelCase:    Union[str, List[str]]				,    **_lowerCAmelCase:    str ):
         return super().__call__(_lowerCAmelCase				,    **_lowerCAmelCase )






       def     SCREAMING_SNAKE_CASE			(      self:    str				,    _lowerCAmelCase:    Union[str, Any]				,    _lowerCAmelCase:    Any=None				,    _lowerCAmelCase:    int=1 ):
         if num_frames is None:
           lowercase			:int							=  self.model.config.num_frames

         if video.startswith("http://" ) or video.startswith("https://" ):
           lowercase			:List[str]							=  BytesIO(requests.get(_lowerCAmelCase ).content )

         lowercase			:str							=  VideoReader(_lowerCAmelCase )
         videoreader.seek(0 )

         lowercase			:Optional[int]							=  0
         lowercase			:int							=  num_frames * frame_sampling_rate - 1
         lowercase			:Union[str, Any]							=  np.linspace(_lowerCAmelCase				,    _lowerCAmelCase				,    num=_lowerCAmelCase				,    dtype=np.intaa )

         lowercase			:Dict							=  videoreader.get_batch(_lowerCAmelCase ).asnumpy()
         lowercase			:str							=  list(_lowerCAmelCase )

         lowercase			:int							=  self.image_processor(_lowerCAmelCase				,    return_tensors=self.framework )
         return model_inputs






       def     SCREAMING_SNAKE_CASE			(      self:    List[str]				,    _lowerCAmelCase:    Optional[Any] ):
         lowercase			:int							=  self.model(**_lowerCAmelCase )
         return model_outputs






       def     SCREAMING_SNAKE_CASE			(      self:    Union[str, Any]				,    _lowerCAmelCase:    List[str]				,    _lowerCAmelCase:    Union[str, Any]=5 ):
         if top_k > self.model.config.num_labels:
           lowercase			:Tuple							=  self.model.config.num_labels

         if self.framework == "pt":
           lowercase			:Dict							=  model_outputs.logits.softmax(-1 )[0]
           lowercase		,			lowercase			:Optional[int]							=  probs.topk(_lowerCAmelCase )
         else:
           raise ValueError(F"Unsupported framework: {self.framework}" )

         lowercase			:List[Any]							=  scores.tolist()
         lowercase			:int							=  ids.tolist()
         return [{"score": score, "label": self.model.config.idalabel[_id]} for score, _id in zip(_lowerCAmelCase				,    _lowerCAmelCase )]









import os
from math import logaa



def 					UpperCAmelCase__     (   lowerCamelCase = "base_exp.txt"      ):
  lowercase			:float							=  0
  lowercase			:str							=  0
  for i, line in enumerate(open(os.path.join(os.path.dirname(lowerCamelCase      ),	lowerCamelCase      )      )      ):
    lowercase		,			lowercase			:str							=  list(map(lowerCamelCase,	line.split(","      )      )      )
    if x * logaa(lowerCamelCase      ) > largest:
      lowercase			:Optional[Any]							=  x * logaa(lowerCamelCase      )
      lowercase			:Any							=  i + 1
  return result


if __name__ == "__main__":
     print(solution())



