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

__UpperCAmelCase     							=logging.get_logger(__name__)




@add_end_docstrings(UpperCAmelCase__ )
class     a__      (   UpperCAmelCase__ ):






     def __init__( self		:		Optional[Any]  ,				*a		:		Union[str, Any]  ,				**a		:		Tuple    ):





         """simple docstring"""



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






     def    SCREAMING_SNAKE_CASE__   ( self		:		List[str]  ,				a		:		Optional[int]=None  ,				a		:		str=None  ,				a		:		List[str]=None    ):





         """simple docstring"""



         __lowerCamelCase		=  {}
         if frame_sampling_rate is not None:
             __lowerCamelCase		=  frame_sampling_rate
         if num_frames is not None:
             __lowerCamelCase		=  num_frames

         __lowerCamelCase		=  {}
         if top_k is not None:
             __lowerCamelCase		=  top_k
         return preprocess_params, {}, postprocess_params






     def __call__( self		:		Optional[Any]  ,				a		:		Union[str, List[str]]  ,				**a		:		Union[str, Any]    ):





         """simple docstring"""



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






     def    SCREAMING_SNAKE_CASE__   ( self		:		int  ,				a		:		List[Any]  ,				a		:		Any=None  ,				a		:		Optional[int]=1    ):





         """simple docstring"""



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

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

         __lowerCamelCase		=  VideoReader(a    )
         videoreader.seek(0    )

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

         __lowerCamelCase		=  videoreader.get_batch(a    ).asnumpy()
         __lowerCamelCase		=  list(a    )

         __lowerCamelCase		=  self.image_processor(a  ,				return_tensors=self.framework    )
         return model_inputs






     def    SCREAMING_SNAKE_CASE__   ( self		:		List[str]  ,				a		:		Union[str, Any]    ):





         """simple docstring"""



         __lowerCamelCase		=  self.model(**a    )
         return model_outputs






     def    SCREAMING_SNAKE_CASE__   ( self		:		Dict  ,				a		:		Any  ,				a		:		List[str]=5    ):





         """simple docstring"""



         if top_k > self.model.config.num_labels:
             __lowerCamelCase		=  self.model.config.num_labels

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

         __lowerCamelCase		=  scores.tolist()
         __lowerCamelCase		=  ids.tolist()
         return [{"score": score, "label": self.model.config.idalabel[_id]} for score, _id in zip(a  ,				a    )]





from ...configuration_utils import PretrainedConfig
from ...utils import logging


a_   :Optional[int]        =      logging.get_logger(__name__)

a_   :Dict        =      {"openai-gpt": "https://huggingface.co/openai-gpt/resolve/main/config.json"}




class 					snake_case__						(       lowerCAmelCase_     ):






     """simple docstring"""


     _SCREAMING_SNAKE_CASE						=	"""openai-gpt"""
     _SCREAMING_SNAKE_CASE						=	{
         """max_position_embeddings""": """n_positions""",
         """hidden_size""": """n_embd""",
         """num_attention_heads""": """n_head""",
         """num_hidden_layers""": """n_layer""",
     }






     def __init__(       self  :  Optional[int], _snake_case  :  Dict=4_0_4_7_8, _snake_case  :  str=5_1_2, _snake_case  :  int=7_6_8, _snake_case  :  Tuple=1_2, _snake_case  :  Any=1_2, _snake_case  :  str="gelu", _snake_case  :  List[str]=0.1, _snake_case  :  Any=0.1, _snake_case  :  Dict=0.1, _snake_case  :  int=1e-5, _snake_case  :  Optional[Any]=0.0_2, _snake_case  :  List[Any]="cls_index", _snake_case  :  Any=True, _snake_case  :  Any=None, _snake_case  :  int=True, _snake_case  :  Optional[Any]=0.1, **_snake_case  :  List[Any], )   ->Optional[int]:
            snake_case__							:	int   	=	vocab_size
            snake_case__							:	Dict   	=	n_positions
            snake_case__							:	str   	=	n_embd
            snake_case__							:	str   	=	n_layer
            snake_case__							:	List[Any]   	=	n_head
            snake_case__							:	List[Any]   	=	afn
            snake_case__							:	Optional[Any]   	=	resid_pdrop
            snake_case__							:	List[str]   	=	embd_pdrop
            snake_case__							:	List[Any]   	=	attn_pdrop
            snake_case__							:	Optional[int]   	=	layer_norm_epsilon
            snake_case__							:	str   	=	initializer_range
            snake_case__							:	List[str]   	=	summary_type
            snake_case__							:	Optional[int]   	=	summary_use_proj
            snake_case__							:	List[str]   	=	summary_activation
            snake_case__							:	Optional[Any]   	=	summary_first_dropout
            snake_case__							:	int   	=	summary_proj_to_labels
            super().__init__(**_snake_case					)






