

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					:			Tuple  				=			logging.get_logger(__name__)






@add_end_docstrings(lowerCAmelCase_      )
class 	__magic_name__    (			lowerCAmelCase_      ):





			def __init__(		self					,  *__snake_case					,  **__snake_case					)   -> str:




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





			def 		__magic_name__    (		self					,  __snake_case=None					,  __snake_case=None					,  __snake_case=None					)   -> str:




						'''simple docstring'''
						__a        ={}
						if frame_sampling_rate is not None:
									__a        =frame_sampling_rate
						if num_frames is not None:
									__a        =num_frames

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





			def __call__(		self					,  __snake_case					,  **__snake_case					)   -> str:




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





			def 		__magic_name__    (		self					,  __snake_case					,  __snake_case=None					,  __snake_case=1					)   -> int:




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

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

						__a        =VideoReader(__snake_case					)
						videoreader.seek(0					)

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

						__a        =videoreader.get_batch(__snake_case					).asnumpy()
						__a        =list(__snake_case					)

						__a        =self.image_processor(__snake_case					,  return_tensors=self.framework					)
						return model_inputs





			def 		__magic_name__    (		self					,  __snake_case					)   -> int:




						'''simple docstring'''
						__a        =self.model(**__snake_case					)
						return model_outputs





			def 		__magic_name__    (		self					,  __snake_case					,  __snake_case=5					)   -> List[Any]:




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

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

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









import warnings

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


_lowerCAmelCase					:			str  				=			logging.get_logger(__name__)






class 	__magic_name__    (			lowerCAmelCase_      ):





			def __init__(		self					,  *__snake_case					,  **__snake_case					)   -> None:




						'''simple docstring'''
						warnings.warn(
						    'The class CLIPFeatureExtractor is deprecated and will be removed in version 5 of Transformers. Please'
						    ' use CLIPImageProcessor instead.'					,  __snake_case					,  )
						super().__init__(*__snake_case					,  **__snake_case					)






