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




import platform
from argparse import ArgumentParser

import huggingface_hub

from .. import __version__ as version
from ..utils import is_accelerate_available, is_torch_available, is_transformers_available, is_xformers_available
from . import BaseDiffusersCLICommand



def 	lowerCAmelCase       (						lowerCAmelCase_       )->       Union[str, Any]:
				return EnvironmentCommand()







class  snake_case__(							UpperCAmelCase__							):







						'''simple docstring'''




						@staticmethod
						def   lowercase_       ( __lowercase							)    ->			List[Any]:
										lowerCAmelCase_       :					List[str]			 = parser.add_parser('''env'''							)
										download_parser.set_defaults(func=__lowercase							)




						def   lowercase_       ( self							)    ->			int:
										lowerCAmelCase_       :					Optional[Any]			 = huggingface_hub.__version__

										lowerCAmelCase_       :					str			 = '''not installed'''
										lowerCAmelCase_       :					str			 = '''NA'''
										if is_torch_available():
														import torch

														lowerCAmelCase_       :					Any			 = torch.__version__
														lowerCAmelCase_       :					str			 = torch.cuda.is_available()

										lowerCAmelCase_       :					List[str]			 = '''not installed'''
										if is_transformers_available():
														import transformers

														lowerCAmelCase_       :					Any			 = transformers.__version__

										lowerCAmelCase_       :					Optional[Any]			 = '''not installed'''
										if is_accelerate_available():
														import accelerate

														lowerCAmelCase_       :					List[Any]			 = accelerate.__version__

										lowerCAmelCase_       :					List[str]			 = '''not installed'''
										if is_xformers_available():
														import xformers

														lowerCAmelCase_       :					Optional[Any]			 = xformers.__version__

										lowerCAmelCase_       :					int			 = {
										    '''`diffusers` version''': version,
										    '''Platform''': platform.platform(),
										    '''Python version''': platform.python_version(),
										    '''PyTorch version (GPU?)''': f"""{pt_version} ({pt_cuda_available})""",
										    '''Huggingface_hub version''': hub_version,
										    '''Transformers version''': transformers_version,
										    '''Accelerate version''': accelerate_version,
										    '''xFormers version''': xformers_version,
										    '''Using GPU in script?''': '''<fill in>''',
										    '''Using distributed or parallel set-up in script?''': '''<fill in>''',
										}

										print('''\nCopy-and-paste the text below in your GitHub issue and FILL OUT the two last points.\n'''							)
										print(self.format_dict(__lowercase							)							)

										return info




						@staticmethod
						def   lowercase_       ( __lowercase							)    ->			str:
										return "\n".join([f"""- {prop}: {val}""" for prop, val in d.items()]							) + "\n"