





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

__A							:       Optional[Any]         =  logging.get_logger(__name__)

@add_end_docstrings(a_     )
class       A_			(a_     ):
	def __init__(       self				,   *_A				,   **_A						):






				'''simple docstring'''







				super().__init__(*lowerCamelCase__				,   **lowerCamelCase__						)
				requires_backends(self				,   '''decord'''						)
				self.check_model_type(lowerCamelCase__						)
	def 	_lowercase							(       self				,   _A=None				,   _A=None				,   _A=None						):






				'''simple docstring'''







				UpperCAmelCase  						=							{}
				if frame_sampling_rate is not None:
							UpperCAmelCase  						=							frame_sampling_rate
				if num_frames is not None:
							UpperCAmelCase  						=							num_frames

				UpperCAmelCase  						=							{}
				if top_k is not None:
							UpperCAmelCase  						=							top_k
				return preprocess_params, {}, postprocess_params
	def __call__(       self				,   _A				,   **_A						):






				'''simple docstring'''







				return super().__call__(lowerCamelCase__				,   **lowerCamelCase__						)
	def 	_lowercase							(       self				,   _A				,   _A=None				,   _A=1						):






				'''simple docstring'''







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

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

				UpperCAmelCase  						=							VideoReader(lowerCamelCase__						)
				videoreader.seek(0						)

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

				UpperCAmelCase  						=							videoreader.get_batch(lowerCamelCase__						).asnumpy()
				UpperCAmelCase  						=							list(lowerCamelCase__						)

				UpperCAmelCase  						=							self.image_processor(lowerCamelCase__				,   return_tensors=self.framework						)
				return model_inputs
	def 	_lowercase							(       self				,   _A						):






				'''simple docstring'''







				UpperCAmelCase  						=							self.model(**lowerCamelCase__						)
				return model_outputs







	def 	_lowercase							(       self				,   _A				,   _A=5						):






				'''simple docstring'''







				if top_k > self.model.config.num_labels:
							UpperCAmelCase  						=							self.model.config.num_labels

				if self.framework == "pt":
							UpperCAmelCase  						=							model_outputs.logits.softmax(-1						)[0]
							UpperCAmelCase						,     UpperCAmelCase  						=							probs.topk(lowerCamelCase__						)
				else:
							raise ValueError(F"""Unsupported framework: {self.framework}"""						)

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









from collections import OrderedDict
from typing import Mapping

from ...configuration_utils import PretrainedConfig
from ...onnx import OnnxConfig
from ...utils import logging


__A								=       logging.get_logger(__name__)

__A								=       {
    "facebook/xlm-roberta-xl": "https://huggingface.co/facebook/xlm-roberta-xl/resolve/main/config.json",
    "facebook/xlm-roberta-xxl": "https://huggingface.co/facebook/xlm-roberta-xxl/resolve/main/config.json",
    # See all XLM-RoBERTa-XL models at https://huggingface.co/models?filter=xlm-roberta-xl
}







class        __lowerCAmelCase					(			__magic_name__					):

			"""simple docstring"""







			snake_case_  						=			'''xlm-roberta-xl'''


			def __init__( self     ,		lowerCamelCase__=250_880     ,		lowerCamelCase__=2_560     ,		lowerCamelCase__=36     ,		lowerCamelCase__=32     ,		lowerCamelCase__=10_240     ,		lowerCamelCase__="gelu"     ,		lowerCamelCase__=0.1     ,		lowerCamelCase__=0.1     ,		lowerCamelCase__=514     ,		lowerCamelCase__=1     ,		lowerCamelCase__=0.02     ,		lowerCamelCase__=1e-05     ,		lowerCamelCase__=1     ,		lowerCamelCase__=0     ,		lowerCamelCase__=2     ,		lowerCamelCase__="absolute"     ,		lowerCamelCase__=True     ,		lowerCamelCase__=None     ,		**lowerCamelCase__     ,		)       -> str:



							'''simple docstring'''
							super().__init__(pad_token_id=lowerCamelCase__     ,		bos_token_id=lowerCamelCase__     ,		eos_token_id=lowerCamelCase__     ,		**lowerCamelCase__				)
							__lowerCamelCase									=       vocab_size
							__lowerCamelCase									=       hidden_size
							__lowerCamelCase									=       num_hidden_layers
							__lowerCamelCase									=       num_attention_heads
							__lowerCamelCase									=       hidden_act
							__lowerCamelCase									=       intermediate_size
							__lowerCamelCase									=       hidden_dropout_prob
							__lowerCamelCase									=       attention_probs_dropout_prob
							__lowerCamelCase									=       max_position_embeddings
							__lowerCamelCase									=       type_vocab_size
							__lowerCamelCase									=       initializer_range
							__lowerCamelCase									=       layer_norm_eps
							__lowerCamelCase									=       position_embedding_type
							__lowerCamelCase									=       use_cache
							__lowerCamelCase									=       classifier_dropout







class        __lowerCAmelCase					(			__magic_name__					):

			"""simple docstring"""







			@property
			def  lowercase_       ( self				)       -> Mapping[str, Mapping[int, str]]:



							'''simple docstring'''
							if self.task == "multiple-choice":
											__lowerCamelCase									=       {0: 'batch', 1: 'choice', 2: 'sequence'}
							else:
											__lowerCamelCase									=       {0: 'batch', 1: 'sequence'}
							return OrderedDict(
							    [
							        ('input_ids', dynamic_axis),
							        ('attention_mask', dynamic_axis),
							    ]				)


