



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__					:     List[str]    		=   logging.get_logger(__name__)

@add_end_docstrings(_lowercase	)
class   _A   ( _lowercase	):


						'''simple docstring'''





						def __init__(	self	:							Tuple							,      *lowerCamelCase	:							Dict							,      **lowerCamelCase	:							Dict	):






							'''simple docstring'''



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



						def     _snake_case	(	self	:							int							,      lowerCamelCase	:							List[str]=None							,      lowerCamelCase	:							Any=None							,      lowerCamelCase	:							Any=None	):






							'''simple docstring'''



							__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	:							List[str]							,      lowerCamelCase	:							Union[str, List[str]]							,      **lowerCamelCase	:							Any	):






							'''simple docstring'''



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



						def     _snake_case	(	self	:							Any							,      lowerCamelCase	:							int							,      lowerCamelCase	:							Any=None							,      lowerCamelCase	:							Tuple=1	):






							'''simple docstring'''



							if num_frames is None:
								__lowercase		       =			self.model.config.num_frames

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

							__lowercase		       =			VideoReader(lowerCamelCase	)
							videoreader.seek(0	)

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

							__lowercase		       =			videoreader.get_batch(lowerCamelCase	).asnumpy()
							__lowercase		       =			list(lowerCamelCase	)

							__lowercase		       =			self.image_processor(lowerCamelCase							,      return_tensors=self.framework	)
							return model_inputs



						def     _snake_case	(	self	:							int							,      lowerCamelCase	:							str	):






							'''simple docstring'''



							__lowercase		       =			self.model(**lowerCamelCase	)
							return model_outputs



						def     _snake_case	(	self	:							int							,      lowerCamelCase	:							Any							,      lowerCamelCase	:							Any=5	):






							'''simple docstring'''



							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(lowerCamelCase	)
							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(lowerCamelCase							,      lowerCamelCase	)]








from ....utils import logging


snake_case__					:     List[Any]    		=   logging.get_logger(__name__)

class   _A   ( _lowercase	):


						'''simple docstring'''





						def __init__(	self	:							List[str]							,      lowerCamelCase	:							Any							,      lowerCamelCase	:							Dict=None							,      lowerCamelCase	:							Dict=2_048	):






							'''simple docstring'''



							__lowercase		       =			config.__dict__
							__lowercase		       =			modal_hidden_size
							if num_labels:
								__lowercase		       =			num_labels



