
'''simple docstring'''







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 			lowerCAmelCase (				unittest.TestCase			):
		a							:					Union[str, Any]       =					MODEL_FOR_VIDEO_CLASSIFICATION_MAPPING




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




		def     lowercase       (				self					,						UpperCamelCase					,						UpperCamelCase      ):
								for example in examples:
														_SCREAMING_SNAKE_CASE				= video_classifier(UpperCamelCase      )

														self.assertEqual(
														    UpperCamelCase					,						[
														        {"score": ANY(UpperCamelCase      ), "label": ANY(UpperCamelCase      )},
														        {"score": ANY(UpperCamelCase      ), "label": ANY(UpperCamelCase      )},
														    ]					,						)




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

								_SCREAMING_SNAKE_CASE				= hf_hub_download(repo_id="nateraw/video-demo"					,						filename="archery.mp4"					,						repo_type="dataset"      )
								_SCREAMING_SNAKE_CASE				= video_classifier(UpperCamelCase					,						top_k=2      )
								self.assertEqual(
								    nested_simplify(UpperCamelCase					,						decimals=4      )					,						[{"score": 0.51_99, "label": "LABEL_0"}, {"score": 0.48_01, "label": "LABEL_1"}]					,						)

								_SCREAMING_SNAKE_CASE				= video_classifier(
								    [
								        video_file_path,
								        video_file_path,
								    ]					,						top_k=2					,						)
								self.assertEqual(
								    nested_simplify(UpperCamelCase					,						decimals=4      )					,						[
								        [{"score": 0.51_99, "label": "LABEL_0"}, {"score": 0.48_01, "label": "LABEL_1"}],
								        [{"score": 0.51_99, "label": "LABEL_0"}, {"score": 0.48_01, "label": "LABEL_1"}],
								    ]					,						)




		@require_tf
		def     lowercase       (				self      ):
								pass

'''simple docstring'''







import os
import unittest

from transformers import LayoutLMTokenizer, LayoutLMTokenizerFast
from transformers.models.layoutlm.tokenization_layoutlm import VOCAB_FILES_NAMES
from transformers.testing_utils import require_tokenizers

from ...test_tokenization_common import TokenizerTesterMixin


@require_tokenizers
class 			lowerCAmelCase (				__UpperCAmelCase		,     unittest.TestCase			):
		a							:					int       =					LayoutLMTokenizer
		a							:					Optional[int]       =					LayoutLMTokenizerFast
		a							:					Optional[int]       =					True
		a							:					Any       =					True




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

								_SCREAMING_SNAKE_CASE				= [
								    "[UNK]",
								    "[CLS]",
								    "[SEP]",
								    "want",
								    "##want",
								    "##ed",
								    "wa",
								    "un",
								    "runn",
								    "##ing",
								    ",",
								    "low",
								    "lowest",
								]
								_SCREAMING_SNAKE_CASE				= os.path.join(self.tmpdirname					,						VOCAB_FILES_NAMES["vocab_file"]      )
								with open(self.vocab_file					,						"w"					,						encoding="utf-8"      ) as vocab_writer:
														vocab_writer.write("".join([x + "\n" for x in vocab_tokens]      )      )




		def     lowercase       (				self					,						**UpperCamelCase      ):
								return LayoutLMTokenizer.from_pretrained(self.tmpdirname					,						**UpperCamelCase      )




		def     lowercase       (				self					,						UpperCamelCase      ):
								_SCREAMING_SNAKE_CASE				= "UNwant\u00E9d,running"
								_SCREAMING_SNAKE_CASE				= "unwanted, running"
								return input_text, output_text




		def     lowercase       (				self      ):
								_SCREAMING_SNAKE_CASE				= self.tokenizer_class(self.vocab_file      )

								_SCREAMING_SNAKE_CASE				= tokenizer.tokenize("UNwant\u00E9d,running"      )
								self.assertListEqual(UpperCamelCase					,						["un", "##want", "##ed", ",", "runn", "##ing"]      )
								self.assertListEqual(tokenizer.convert_tokens_to_ids(UpperCamelCase      )					,						[7, 4, 5, 10, 8, 9]      )




		def     lowercase       (				self      ):
								pass