





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

__lowerCamelCase : Dict											=			logging.get_logger(__name__)

@add_end_docstrings(_lowercase  )
class       UpperCAmelCase (						_lowercase  ):




		def __init__(self      :	Optional[Any]							,			*A__      :	str							,			**A__      :	Optional[Any]				)					-> int:
						super().__init__(*A__							,			**A__				)
						requires_backends(self							,			"decord"				)
						self.check_model_type(A__				)




		def 				UpperCAmelCase__   (self      :	List[Any]							,			A__      :	List[Any]=None							,			A__      :	Tuple=None							,			A__      :	List[Any]=None				)					-> Dict:
						lowercase         = {}
						if frame_sampling_rate is not None:
										lowercase         = frame_sampling_rate
						if num_frames is not None:
										lowercase         = num_frames

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




		def __call__(self      :	Optional[int]							,			A__      :	Union[str, List[str]]							,			**A__      :	Dict				)					-> int:
						return super().__call__(A__							,			**A__				)




		def 				UpperCAmelCase__   (self      :	int							,			A__      :	Tuple							,			A__      :	str=None							,			A__      :	Dict=1				)					-> str:
						if num_frames is None:
										lowercase         = self.model.config.num_frames

						if video.startswith("http://"				) or video.startswith("https://"				):
										lowercase         = BytesIO(requests.get(A__				).content				)

						lowercase         = VideoReader(A__				)
						videoreader.seek(0				)

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

						lowercase         = videoreader.get_batch(A__				).asnumpy()
						lowercase         = list(A__				)

						lowercase         = self.image_processor(A__							,			return_tensors=self.framework				)
						return model_inputs




		def 				UpperCAmelCase__   (self      :	Union[str, Any]							,			A__      :	Union[str, Any]				)					-> Any:
						lowercase         = self.model(**A__				)
						return model_outputs





		def 				UpperCAmelCase__   (self      :	Optional[int]							,			A__      :	Dict							,			A__      :	Union[str, Any]=5				)					-> Tuple:
						if top_k > self.model.config.num_labels:
										lowercase         = self.model.config.num_labels

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

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











'''simple docstring'''

import warnings

from ...utils import logging
from .image_processing_clip import CLIPImageProcessor


__lowerCamelCase : Union[str, Any]											=			logging.get_logger(__name__)

class       UpperCAmelCase (						_lowercase  ):




		def __init__(self      :	Tuple							,			*A__      :	Union[str, Any]							,			**A__      :	Optional[Any]				)					-> None:
						warnings.warn(
						    "The class CLIPFeatureExtractor is deprecated and will be removed in version 5 of Transformers. Please"
						    " use CLIPImageProcessor instead."							,			A__							,			)
						super().__init__(*A__							,			**A__				)




