"""simple docstring"""




import json
import os
import unittest

from transformers import OpenAIGPTTokenizer, OpenAIGPTTokenizerFast
from transformers.models.openai.tokenization_openai import VOCAB_FILES_NAMES
from transformers.testing_utils import require_ftfy, require_spacy, require_tokenizers

from ...test_tokenization_common import TokenizerTesterMixin
@require_tokenizers
class 			UpperCamelCase__(	__A						,  unittest.TestCase       ):
						lowerCAmelCase__     :  Tuple  							=						OpenAIGPTTokenizer
						lowerCAmelCase__     :  int  							=						OpenAIGPTTokenizerFast
						lowerCAmelCase__     :  Union[str, Any]  							=						True
						lowerCAmelCase__     :  Optional[int]  							=						False





						def  snake_case__		(				self   )    -> Optional[int]:
													super().setUp()

													# Adapted from Sennrich et al. 2015 and https://github.com/rsennrich/subword-nmt
													A__		   =							[
													    'l',
													    'o',
													    'w',
													    'e',
													    'r',
													    's',
													    't',
													    'i',
													    'd',
													    'n',
													    'w</w>',
													    'r</w>',
													    't</w>',
													    'lo',
													    'low',
													    'er</w>',
													    'low</w>',
													    'lowest</w>',
													    'newer</w>',
													    'wider</w>',
													    '<unk>',
													]
													A__		   =							dict(zip(__UpperCAmelCase						,range(len(__UpperCAmelCase   )   )   )   )
													A__		   =							['#version: 0.2', 'l o', 'lo w', 'e r</w>', '']

													A__		   =							os.path.join(self.tmpdirname						,VOCAB_FILES_NAMES['vocab_file']   )
													A__		   =							os.path.join(self.tmpdirname						,VOCAB_FILES_NAMES['merges_file']   )
													with open(self.vocab_file						,'w'   ) as fp:
																				fp.write(json.dumps(__UpperCAmelCase   )   )
													with open(self.merges_file						,'w'   ) as fp:
																				fp.write('\n'.join(__UpperCAmelCase   )   )





						def  snake_case__		(				self						,__UpperCAmelCase   )    -> List[Any]:
													return "lower newer", "lower newer"





						def  snake_case__		(				self   )    -> Union[str, Any]:
													A__		   =							OpenAIGPTTokenizer(self.vocab_file						,self.merges_file   )

													A__		   =							'lower'
													A__		   =							['low', 'er</w>']
													A__		   =							tokenizer.tokenize(__UpperCAmelCase   )
													self.assertListEqual(__UpperCAmelCase						,__UpperCAmelCase   )

													A__		   =							tokens + ['<unk>']
													A__		   =							[14, 15, 20]
													self.assertListEqual(tokenizer.convert_tokens_to_ids(__UpperCAmelCase   )						,__UpperCAmelCase   )





						def  snake_case__		(				self						,__UpperCAmelCase=15   )    -> Dict:
													for tokenizer, pretrained_name, kwargs in self.tokenizers_list:
																				with self.subTest(f'''{tokenizer.__class__.__name__} ({pretrained_name})'''   ):
																											A__		   =							self.rust_tokenizer_class.from_pretrained(__UpperCAmelCase						,**__UpperCAmelCase   )

																											# Simple input
																											A__		   =							'This is a simple input'
																											A__		   =							['This is a simple input 1', 'This is a simple input 2']
																											A__		   =							('This is a simple input', 'This is a pair')
																											A__		   =							[
																											    ('This is a simple input 1', 'This is a simple input 2'),
																											    ('This is a simple pair 1', 'This is a simple pair 2'),
																											]

																											# Simple input tests
																											self.assertRaises(__UpperCAmelCase						,tokenizer_r.encode						,__UpperCAmelCase						,max_length=__UpperCAmelCase						,padding='max_length'   )

																											# Simple input
																											self.assertRaises(__UpperCAmelCase						,tokenizer_r.encode_plus						,__UpperCAmelCase						,max_length=__UpperCAmelCase						,padding='max_length'   )

																											# Simple input
																											self.assertRaises(
																											    __UpperCAmelCase						,tokenizer_r.batch_encode_plus						,__UpperCAmelCase						,max_length=__UpperCAmelCase						,padding='max_length'						,)

																											# Pair input
																											self.assertRaises(__UpperCAmelCase						,tokenizer_r.encode						,__UpperCAmelCase						,max_length=__UpperCAmelCase						,padding='max_length'   )

																											# Pair input
																											self.assertRaises(__UpperCAmelCase						,tokenizer_r.encode_plus						,__UpperCAmelCase						,max_length=__UpperCAmelCase						,padding='max_length'   )

																											# Pair input
																											self.assertRaises(
																											    __UpperCAmelCase						,tokenizer_r.batch_encode_plus						,__UpperCAmelCase						,max_length=__UpperCAmelCase						,padding='max_length'						,)





						def  snake_case__		(				self   )    -> Optional[int]:
													pass






@require_ftfy
@require_spacy
@require_tokenizers
class 			UpperCamelCase__(	__A       ):
						pass






"""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							 =     logging.get_logger(__name__)
@add_end_docstrings(__A       )
class 			UpperCamelCase__(	__A       ):





						def __init__(				self						,*__UpperCAmelCase						,**__UpperCAmelCase   )    -> Tuple:
													super().__init__(*__UpperCAmelCase						,**__UpperCAmelCase   )
													requires_backends(self						,'decord'   )
													self.check_model_type(__UpperCAmelCase   )





						def  snake_case__		(				self						,__UpperCAmelCase=None						,__UpperCAmelCase=None						,__UpperCAmelCase=None   )    -> int:
													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						,__UpperCAmelCase						,**__UpperCAmelCase   )    -> Dict:
													return super().__call__(__UpperCAmelCase						,**__UpperCAmelCase   )





						def  snake_case__		(				self						,__UpperCAmelCase						,__UpperCAmelCase=None						,__UpperCAmelCase=1   )    -> Union[str, Any]:
													if num_frames is None:
																				A__		   =							self.model.config.num_frames

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

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

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

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

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





						def  snake_case__		(				self						,__UpperCAmelCase   )    -> Dict:
													A__		   =							self.model(**__UpperCAmelCase   )
													return model_outputs





						def  snake_case__		(				self						,__UpperCAmelCase						,__UpperCAmelCase=5   )    -> Union[str, Any]:
													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(__UpperCAmelCase   )
													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(__UpperCAmelCase						,__UpperCAmelCase   )]





