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

_lowercase    =		logging.get_logger(__name__)




@add_end_docstrings(_SCREAMING_SNAKE_CASE			)
class   UpperCAmelCase_					(		_SCREAMING_SNAKE_CASE			):






						'''simple docstring'''






						def __init__( self   ,       *_lowercase   ,       **_lowercase				):

												"""simple docstring"""



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




						def  _lowercase     ( self   ,       _lowercase=None   ,       _lowercase=None   ,       _lowercase=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   ,       _lowercase   ,       **_lowercase				):

												"""simple docstring"""



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




						def  _lowercase     ( self   ,       _lowercase   ,       _lowercase=None   ,       _lowercase=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(_lowercase				).content				)

												_lowerCAmelCase  						=			VideoReader(_lowercase				)
												videoreader.seek(0				)

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

												_lowerCAmelCase  						=			videoreader.get_batch(_lowercase				).asnumpy()
												_lowerCAmelCase  						=			list(_lowercase				)

												_lowerCAmelCase  						=			self.image_processor(_lowercase   ,       return_tensors=self.framework				)
												return model_inputs




						def  _lowercase     ( self   ,       _lowercase				):

												"""simple docstring"""



												_lowerCAmelCase  						=			self.model(**_lowercase				)
												return model_outputs




						def  _lowercase     ( self   ,       _lowercase   ,       _lowercase=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(_lowercase				)
												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(_lowercase   ,       _lowercase				)]


'''simple docstring'''



import logging

from transformers import PretrainedConfig


_lowercase    =		logging.getLogger(__name__)


_lowercase    =		{
    """bertabs-finetuned-cnndm""": """https://huggingface.co/remi/bertabs-finetuned-cnndm-extractive-abstractive-summarization/resolve/main/config.json""",
}




class   UpperCAmelCase_					(		_SCREAMING_SNAKE_CASE			):






						'''simple docstring'''






						_lowercase		:				Optional[Any]									=       '''bertabs'''




						def __init__( self   ,       _lowercase=30_522   ,       _lowercase=512   ,       _lowercase=6   ,       _lowercase=512   ,       _lowercase=8   ,       _lowercase=512   ,       _lowercase=0.2   ,       _lowercase=6   ,       _lowercase=768   ,       _lowercase=8   ,       _lowercase=2_048   ,       _lowercase=0.2   ,       **_lowercase   ,       ):

												"""simple docstring"""



												super().__init__(**_lowercase				)

												_lowerCAmelCase  						=			vocab_size
												_lowerCAmelCase  						=			max_pos

												_lowerCAmelCase  						=			enc_layers
												_lowerCAmelCase  						=			enc_hidden_size
												_lowerCAmelCase  						=			enc_heads
												_lowerCAmelCase  						=			enc_ff_size
												_lowerCAmelCase  						=			enc_dropout

												_lowerCAmelCase  						=			dec_layers
												_lowerCAmelCase  						=			dec_hidden_size
												_lowerCAmelCase  						=			dec_heads
												_lowerCAmelCase  						=			dec_ff_size
												_lowerCAmelCase  						=			dec_dropout
