



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

snake_case_			:     int  	=  logging.get_logger(__name__)






@add_end_docstrings(lowercase       )
class 							lowercase__     (							lowercase       ):





 def __init__(			self :    str			,*lowerCamelCase__ :    Any			,**lowerCamelCase__ :    Union[str, Any]			):







       '''simple docstring'''
       super().__init__(*lowerCamelCase__			,**lowerCamelCase__			)
       requires_backends(self			,'decord'			)
       self.check_model_type(lowerCamelCase__			)





 def      UpperCamelCase_  (			self :    Any			,lowerCamelCase__ :    Any=None			,lowerCamelCase__ :    List[Any]=None			,lowerCamelCase__ :    Dict=None			):







       '''simple docstring'''
       _UpperCamelCase :		int			    =       {}
       if frame_sampling_rate is not None:
             _UpperCamelCase :		Dict			    =       frame_sampling_rate
       if num_frames is not None:
             _UpperCamelCase :		int			    =       num_frames

       _UpperCamelCase :		Any			    =       {}
       if top_k is not None:
             _UpperCamelCase :		Tuple			    =       top_k
       return preprocess_params, {}, postprocess_params





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







       '''simple docstring'''
       return super().__call__(lowerCamelCase__			,**lowerCamelCase__			)





 def      UpperCamelCase_  (			self :    Any			,lowerCamelCase__ :    List[str]			,lowerCamelCase__ :    Tuple=None			,lowerCamelCase__ :    str=1			):







       '''simple docstring'''
       if num_frames is None:
             _UpperCamelCase :		str			    =       self.model.config.num_frames

       if video.startswith('http://'			) or video.startswith('https://'			):
             _UpperCamelCase :		Optional[Any]			    =       BytesIO(requests.get(lowerCamelCase__			).content			)

       _UpperCamelCase :		Union[str, Any]			    =       VideoReader(lowerCamelCase__			)
       videoreader.seek(0			)

       _UpperCamelCase :		str			    =       0
       _UpperCamelCase :		Tuple			    =       num_frames * frame_sampling_rate - 1
       _UpperCamelCase :		Union[str, Any]			    =       np.linspace(lowerCamelCase__			,lowerCamelCase__			,num=lowerCamelCase__			,dtype=np.intaa			)

       _UpperCamelCase :		str			    =       videoreader.get_batch(lowerCamelCase__			).asnumpy()
       _UpperCamelCase :		Tuple			    =       list(lowerCamelCase__			)

       _UpperCamelCase :		Tuple			    =       self.image_processor(lowerCamelCase__			,return_tensors=self.framework			)
       return model_inputs





 def      UpperCamelCase_  (			self :    Any			,lowerCamelCase__ :    Dict			):







       '''simple docstring'''
       _UpperCamelCase :		str			    =       self.model(**lowerCamelCase__			)
       return model_outputs





 def      UpperCamelCase_  (			self :    Tuple			,lowerCamelCase__ :    Tuple			,lowerCamelCase__ :    Tuple=5			):







       '''simple docstring'''
       if top_k > self.model.config.num_labels:
             _UpperCamelCase :		Any			    =       self.model.config.num_labels

       if self.framework == "pt":
             _UpperCamelCase :		Union[str, Any]			    =       model_outputs.logits.softmax(-1			)[0]
             _UpperCamelCase :		Optional[Any]			    =       probs.topk(lowerCamelCase__			)
       else:
             raise ValueError(F'Unsupported framework: {self.framework}'			)

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







'''simple docstring'''
from typing import TYPE_CHECKING

from ...file_utils import _LazyModule, is_torch_available
from ...utils import OptionalDependencyNotAvailable


snake_case_			:     Any  	=  {
    'configuration_gpt_neox_japanese': ['GPT_NEOX_JAPANESE_PRETRAINED_CONFIG_ARCHIVE_MAP', 'GPTNeoXJapaneseConfig'],
    'tokenization_gpt_neox_japanese': ['GPTNeoXJapaneseTokenizer'],
}

try:
					if not is_torch_available():
										raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
					pass
else:
					snake_case_			:     Optional[int]  	=  [
					    'GPT_NEOX_JAPANESE_PRETRAINED_MODEL_ARCHIVE_LIST',
					    'GPTNeoXJapaneseForCausalLM',
					    'GPTNeoXJapaneseLayer',
					    'GPTNeoXJapaneseModel',
					    'GPTNeoXJapanesePreTrainedModel',
					]


if TYPE_CHECKING:
					from .configuration_gpt_neox_japanese import GPT_NEOX_JAPANESE_PRETRAINED_CONFIG_ARCHIVE_MAP, GPTNeoXJapaneseConfig
					from .tokenization_gpt_neox_japanese import GPTNeoXJapaneseTokenizer

					try:
										if not is_torch_available():
															raise OptionalDependencyNotAvailable()
					except OptionalDependencyNotAvailable:
										pass
					else:
										from .modeling_gpt_neox_japanese import (
										    GPT_NEOX_JAPANESE_PRETRAINED_MODEL_ARCHIVE_LIST,
										    GPTNeoXJapaneseForCausalLM,
										    GPTNeoXJapaneseLayer,
										    GPTNeoXJapaneseModel,
										    GPTNeoXJapanesePreTrainedModel,
										)


else:
					import sys

					snake_case_			:     Any  	=  _LazyModule(__name__, globals()['__file__'], _import_structure, module_spec=__spec__)


