


"""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    :     Union[str, Any]   						=		logging.get_logger(__name__)





@add_end_docstrings(A				)
class      lowerCamelCase__   (     A				):







					"""simple docstring"""


					def __init__(       self    : Tuple ,       *UpperCamelCase    : List[str] ,       **UpperCamelCase    : Union[str, Any]  ):
												'''simple docstring'''






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






					def lowerCamelCase__							(       self    : Dict ,       UpperCamelCase    : Optional[int]=None ,       UpperCamelCase    : List[Any]=None ,       UpperCamelCase    : Union[str, Any]=None  ):
												'''simple docstring'''






												__UpperCAmelCase   :						Tuple      							=					{}
												if frame_sampling_rate is not None:
																			__UpperCAmelCase   :						Dict      							=					frame_sampling_rate
												if num_frames is not None:
																			__UpperCAmelCase   :						Union[str, Any]      							=					num_frames

												__UpperCAmelCase   :						int      							=					{}
												if top_k is not None:
																			__UpperCAmelCase   :						Union[str, Any]      							=					top_k
												return preprocess_params, {}, postprocess_params






					def __call__(       self    : Tuple ,       UpperCamelCase    : Union[str, List[str]] ,       **UpperCamelCase    : Dict  ):
												'''simple docstring'''






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






					def lowerCamelCase__							(       self    : str ,       UpperCamelCase    : str ,       UpperCamelCase    : Any=None ,       UpperCamelCase    : Optional[Any]=1  ):
												'''simple docstring'''






												if num_frames is None:
																			__UpperCAmelCase   :						str      							=					self.model.config.num_frames

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

												__UpperCAmelCase   :						List[str]      							=					VideoReader(UpperCamelCase  )
												videoreader.seek(0  )

												__UpperCAmelCase   :						Dict      							=					0
												__UpperCAmelCase   :						Optional[Any]      							=					num_frames * frame_sampling_rate - 1
												__UpperCAmelCase   :						str      							=					np.linspace(UpperCamelCase ,       UpperCamelCase ,       num=UpperCamelCase ,       dtype=np.intaa  )

												__UpperCAmelCase   :						str      							=					videoreader.get_batch(UpperCamelCase  ).asnumpy()
												__UpperCAmelCase   :						List[Any]      							=					list(UpperCamelCase  )

												__UpperCAmelCase   :						Tuple      							=					self.image_processor(UpperCamelCase ,       return_tensors=self.framework  )
												return model_inputs






					def lowerCamelCase__							(       self    : Optional[Any] ,       UpperCamelCase    : Any  ):
												'''simple docstring'''






												__UpperCAmelCase   :						List[str]      							=					self.model(**UpperCamelCase  )
												return model_outputs






					def lowerCamelCase__							(       self    : Any ,       UpperCamelCase    : Union[str, Any] ,       UpperCamelCase    : Any=5  ):
												'''simple docstring'''






												if top_k > self.model.config.num_labels:
																			__UpperCAmelCase   :						Optional[int]      							=					self.model.config.num_labels

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

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




"""simple docstring"""






from typing import TYPE_CHECKING

from ...utils import (
    OptionalDependencyNotAvailable,
    _LazyModule,
    is_flax_available,
    is_tf_available,
    is_tokenizers_available,
    is_torch_available,
)


UpperCAmelCase    :     Any   						=		{
    'configuration_blenderbot': [
        'BLENDERBOT_PRETRAINED_CONFIG_ARCHIVE_MAP',
        'BlenderbotConfig',
        'BlenderbotOnnxConfig',
    ],
    'tokenization_blenderbot': ['BlenderbotTokenizer'],
}

try:
							if not is_tokenizers_available():
														raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
							pass
else:
							UpperCAmelCase    :     Optional[int]   						=		['BlenderbotTokenizerFast']

try:
							if not is_torch_available():
														raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
							pass
else:
							UpperCAmelCase    :     Optional[Any]   						=		[
							    'BLENDERBOT_PRETRAINED_MODEL_ARCHIVE_LIST',
							    'BlenderbotForCausalLM',
							    'BlenderbotForConditionalGeneration',
							    'BlenderbotModel',
							    'BlenderbotPreTrainedModel',
							]


try:
							if not is_tf_available():
														raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
							pass
else:
							UpperCAmelCase    :     Optional[int]   						=		[
							    'TFBlenderbotForConditionalGeneration',
							    'TFBlenderbotModel',
							    'TFBlenderbotPreTrainedModel',
							]


try:
							if not is_flax_available():
														raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
							pass
else:
							UpperCAmelCase    :     Optional[int]   						=		[
							    'FlaxBlenderbotForConditionalGeneration',
							    'FlaxBlenderbotModel',
							    'FlaxBlenderbotPreTrainedModel',
							]


if TYPE_CHECKING:
							from .configuration_blenderbot import (
							    BLENDERBOT_PRETRAINED_CONFIG_ARCHIVE_MAP,
							    BlenderbotConfig,
							    BlenderbotOnnxConfig,
							)
							from .tokenization_blenderbot import BlenderbotTokenizer

							try:
														if not is_tokenizers_available():
																					raise OptionalDependencyNotAvailable()
							except OptionalDependencyNotAvailable:
														pass
							else:
														from .tokenization_blenderbot_fast import BlenderbotTokenizerFast

							try:
														if not is_torch_available():
																					raise OptionalDependencyNotAvailable()
							except OptionalDependencyNotAvailable:
														pass
							else:
														from .modeling_blenderbot import (
														    BLENDERBOT_PRETRAINED_MODEL_ARCHIVE_LIST,
														    BlenderbotForCausalLM,
														    BlenderbotForConditionalGeneration,
														    BlenderbotModel,
														    BlenderbotPreTrainedModel,
														)

							try:
														if not is_tf_available():
																					raise OptionalDependencyNotAvailable()
							except OptionalDependencyNotAvailable:
														pass
							else:
														from .modeling_tf_blenderbot import (
														    TFBlenderbotForConditionalGeneration,
														    TFBlenderbotModel,
														    TFBlenderbotPreTrainedModel,
														)

							try:
														if not is_flax_available():
																					raise OptionalDependencyNotAvailable()
							except OptionalDependencyNotAvailable:
														pass
							else:
														from .modeling_flax_blenderbot import (
														    FlaxBlenderbotForConditionalGeneration,
														    FlaxBlenderbotModel,
														    FlaxBlenderbotPreTrainedModel,
														)

else:
							import sys

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