





import json
import os
import unittest

from transformers.models.ctrl.tokenization_ctrl import VOCAB_FILES_NAMES, CTRLTokenizer

from ...test_tokenization_common import TokenizerTesterMixin




class        SCREAMING_SNAKE_CASE__					(		UpperCamelCase__							,   unittest.TestCase ):
 __SCREAMING_SNAKE_CASE							=      CTRLTokenizer
 __SCREAMING_SNAKE_CASE							=      False
 __SCREAMING_SNAKE_CASE							=      False



 def 							UpperCamelCase     (				self					):
        super().setUp()

        # Adapted from Sennrich et al. 2015 and https://github.com/rsennrich/subword-nmt
        A__		   =		['''adapt''', '''re@@''', '''a@@''', '''apt''', '''c@@''', '''t''', '''<unk>''']
        A__		   =		dict(zip(__lowerCamelCase,range(len(__lowerCamelCase					)					)					)					)
        A__		   =		['''#version: 0.2''', '''a p''', '''ap t</w>''', '''r e''', '''a d''', '''ad apt</w>''', '''''']
        A__		   =		{'''unk_token''': '''<unk>'''}

        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''',encoding='''utf-8'''					) as fp:
               fp.write(json.dumps(__lowerCamelCase					) + '''\n'''					)
        with open(self.merges_file,'''w''',encoding='''utf-8'''					) as fp:
               fp.write('''\n'''.join(__lowerCamelCase					)					)



 def 							UpperCamelCase     (				self,**__lowerCamelCase					):
        kwargs.update(self.special_tokens_map					)
        return CTRLTokenizer.from_pretrained(self.tmpdirname,**__lowerCamelCase					)



 def 							UpperCamelCase     (				self,__lowerCamelCase					):
        A__		   =		'''adapt react readapt apt'''
        A__		   =		'''adapt react readapt apt'''
        return input_text, output_text




 def 							UpperCamelCase     (				self					):
        A__		   =		CTRLTokenizer(self.vocab_file,self.merges_file,**self.special_tokens_map					)
        A__		   =		'''adapt react readapt apt'''
        A__		   =		'''adapt re@@ a@@ c@@ t re@@ adapt apt'''.split()
        A__		   =		tokenizer.tokenize(__lowerCamelCase					)
        self.assertListEqual(__lowerCamelCase,__lowerCamelCase					)

        A__		   =		tokens + [tokenizer.unk_token]

        A__		   =		[0, 1, 2, 4, 5, 1, 0, 3, 6]
        self.assertListEqual(tokenizer.convert_tokens_to_ids(__lowerCamelCase					),__lowerCamelCase					)












import unittest

from huggingface_hub import hf_hub_download

from transformers import MODEL_FOR_VIDEO_CLASSIFICATION_MAPPING, VideoMAEFeatureExtractor
from transformers.pipelines import VideoClassificationPipeline, pipeline
from transformers.testing_utils import (
    is_pipeline_test,
    nested_simplify,
    require_decord,
    require_tf,
    require_torch,
    require_torch_or_tf,
    require_vision,
)

from .test_pipelines_common import ANY




@is_pipeline_test
@require_torch_or_tf
@require_vision
@require_decord
class        SCREAMING_SNAKE_CASE__					(		unittest.TestCase ):
 __SCREAMING_SNAKE_CASE							=      MODEL_FOR_VIDEO_CLASSIFICATION_MAPPING



 def 							UpperCamelCase     (				self,__lowerCamelCase,__lowerCamelCase,__lowerCamelCase					):
        A__		   =		hf_hub_download(
            repo_id='''nateraw/video-demo''',filename='''archery.mp4''',repo_type='''dataset'''					)
        A__		   =		VideoClassificationPipeline(model=__lowerCamelCase,image_processor=__lowerCamelCase,top_k=2					)
        A__		   =		[
            example_video_filepath,
            '''https://huggingface.co/datasets/nateraw/video-demo/resolve/main/archery.mp4''',
        ]
        return video_classifier, examples



 def 							UpperCamelCase     (				self,__lowerCamelCase,__lowerCamelCase					):
        for example in examples:
               A__		   =		video_classifier(__lowerCamelCase					)

               self.assertEqual(
                   __lowerCamelCase,[
                       {'''score''': ANY(__lowerCamelCase					), '''label''': ANY(__lowerCamelCase					)},
                       {'''score''': ANY(__lowerCamelCase					), '''label''': ANY(__lowerCamelCase					)},
                   ],)



 @require_torch
 def 							UpperCamelCase     (				self					):
        A__		   =		'''hf-internal-testing/tiny-random-VideoMAEForVideoClassification'''
        A__		   =		VideoMAEFeatureExtractor(
            size={'''shortest_edge''': 10},crop_size={'''height''': 10, '''width''': 10}					)
        A__		   =		pipeline(
            '''video-classification''',model=__lowerCamelCase,feature_extractor=__lowerCamelCase,frame_sampling_rate=4					)

        A__		   =		hf_hub_download(repo_id='''nateraw/video-demo''',filename='''archery.mp4''',repo_type='''dataset'''					)
        A__		   =		video_classifier(__lowerCamelCase,top_k=2					)
        self.assertEqual(
            nested_simplify(__lowerCamelCase,decimals=4					),[{'''score''': 0.5199, '''label''': '''LABEL_0'''}, {'''score''': 0.4801, '''label''': '''LABEL_1'''}],)

        A__		   =		video_classifier(
            [
                video_file_path,
                video_file_path,
            ],top_k=2,)
        self.assertEqual(
            nested_simplify(__lowerCamelCase,decimals=4					),[
                [{'''score''': 0.5199, '''label''': '''LABEL_0'''}, {'''score''': 0.4801, '''label''': '''LABEL_1'''}],
                [{'''score''': 0.5199, '''label''': '''LABEL_0'''}, {'''score''': 0.4801, '''label''': '''LABEL_1'''}],
            ],)




 @require_tf
 def 							UpperCamelCase     (				self					):
        pass





