


import json
import os
import unittest

from transformers import MgpstrTokenizer
from transformers.models.mgp_str.tokenization_mgp_str import VOCAB_FILES_NAMES
from transformers.testing_utils import require_tokenizers

from ...test_tokenization_common import TokenizerTesterMixin



@require_tokenizers
class 				A       (			UpperCAmelCase__					,    unittest.TestCase				):
					'''simple docstring'''






					A__     =					MgpstrTokenizer
					A__     =					False
					A__     =					{}
					A__     =					False

					def     lowerCamelCase__	(self       :		Union[str, Any]						)		->  Optional[Any]:




							"""simple docstring"""


							super().setUp()

							# fmt: off
							lowercase__	     =						["""[GO]""", """[s]""", """0""", """1""", """2""", """3""", """4""", """5""", """6""", """7""", """8""", """9""", """a""", """b""", """c""", """d""", """e""", """f""", """g""", """h""", """i""", """j""", """k""", """l""", """m""", """n""", """o""", """p""", """q""", """r""", """s""", """t""", """u""", """v""", """w""", """x""", """y""", """z"""]
							# fmt: on
							lowercase__	     =						dict(zip(_UpperCAmelCase ,   range(len(_UpperCAmelCase						)						)						)						)

							lowercase__	     =						os.path.join(self.tmpdirname ,   VOCAB_FILES_NAMES["""vocab_file"""]						)
							with open(self.vocab_file ,   """w""" ,   encoding="""utf-8"""						) as fp:
									fp.write(json.dumps(_UpperCAmelCase						) + """\n"""						)

					def     lowerCamelCase__	(self       :		Dict ,   **_UpperCAmelCase       :		int						)		->  Dict:




							"""simple docstring"""


							return MgpstrTokenizer.from_pretrained(self.tmpdirname ,   **_UpperCAmelCase						)

					def     lowerCamelCase__	(self       :		Optional[int] ,   _UpperCAmelCase       :		Any						)		->  str:




							"""simple docstring"""


							lowercase__	     =						"""tester"""
							lowercase__	     =						"""tester"""
							return input_text, output_text

					@unittest.skip("""MGP-STR always lower cases letters."""						)
					def     lowerCamelCase__	(self       :		Union[str, Any]						)		->  Tuple:




							"""simple docstring"""


							pass

					def     lowerCamelCase__	(self       :		List[str]						)		->  Optional[int]:




							"""simple docstring"""


							lowercase__	     =						self.get_tokenizers(do_lower_case=_UpperCAmelCase						)
							for tokenizer in tokenizers:
									with self.subTest(f'''{tokenizer.__class__.__name__}'''						):
											lowercase__	     =						"""[SPECIAL_TOKEN]"""

											tokenizer.add_special_tokens({"""cls_token""": special_token}						)
											lowercase__	     =						tokenizer.encode([special_token] ,   add_special_tokens=_UpperCAmelCase						)
											self.assertEqual(len(_UpperCAmelCase						) ,   1						)

											lowercase__	     =						tokenizer.decode(_UpperCAmelCase ,   skip_special_tokens=_UpperCAmelCase						)
											self.assertTrue(special_token not in decoded						)

					def     lowerCamelCase__	(self       :		Any						)		->  List[str]:




							"""simple docstring"""


							lowercase__	     =						self.get_tokenizers()
							for tokenizer in tokenizers:
									with self.subTest(f'''{tokenizer.__class__.__name__}'''						):
											lowercase__     ,      lowercase__	     =						self.get_input_output_texts(_UpperCAmelCase						)

											lowercase__	     =						tokenizer.tokenize(_UpperCAmelCase						)
											lowercase__	     =						tokenizer.convert_tokens_to_ids(_UpperCAmelCase						)
											lowercase__	     =						tokenizer.encode(_UpperCAmelCase ,   add_special_tokens=_UpperCAmelCase						)
											self.assertListEqual(_UpperCAmelCase ,   _UpperCAmelCase						)

											lowercase__	     =						tokenizer.convert_ids_to_tokens(_UpperCAmelCase						)
											self.assertNotEqual(len(_UpperCAmelCase						) ,   0						)
											lowercase__	     =						tokenizer.decode(_UpperCAmelCase						)
											self.assertIsInstance(_UpperCAmelCase ,   _UpperCAmelCase						)

											self.assertEqual(text_a.replace(""" """ ,   """"""						) ,   _UpperCAmelCase						)

					@unittest.skip("""MGP-STR tokenizer only handles one sequence."""						)
					def     lowerCamelCase__	(self       :		int						)		->  Any:




							"""simple docstring"""


							pass


					@unittest.skip("""inputs cannot be pretokenized in MgpstrTokenizer"""						)
					def     lowerCamelCase__	(self       :		Optional[Any]						)		->  str:




							"""simple docstring"""


							pass





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 				A       (			unittest.TestCase				):
					'''simple docstring'''






					A__     =					MODEL_FOR_VIDEO_CLASSIFICATION_MAPPING

					def     lowerCamelCase__	(self       :		List[str] ,   _UpperCAmelCase       :		List[str] ,   _UpperCAmelCase       :		Dict ,   _UpperCAmelCase       :		Tuple						)		->  Tuple:




							"""simple docstring"""


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

					def     lowerCamelCase__	(self       :		List[str] ,   _UpperCAmelCase       :		Union[str, Any] ,   _UpperCAmelCase       :		Tuple						)		->  List[Any]:




							"""simple docstring"""


							for example in examples:
									lowercase__	     =						video_classifier(_UpperCAmelCase						)

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

					@require_torch
					def     lowerCamelCase__	(self       :		str						)		->  List[Any]:




							"""simple docstring"""


							lowercase__	     =						"""hf-internal-testing/tiny-random-VideoMAEForVideoClassification"""
							lowercase__	     =						VideoMAEFeatureExtractor(
							    size={"""shortest_edge""": 10} ,   crop_size={"""height""": 10, """width""": 10}						)
							lowercase__	     =						pipeline(
							    """video-classification""" ,   model=_UpperCAmelCase ,   feature_extractor=_UpperCAmelCase ,   frame_sampling_rate=4						)

							lowercase__	     =						hf_hub_download(repo_id="""nateraw/video-demo""" ,   filename="""archery.mp4""" ,   repo_type="""dataset"""						)
							lowercase__	     =						video_classifier(_UpperCAmelCase ,   top_k=2						)
							self.assertEqual(
							    nested_simplify(_UpperCAmelCase ,   decimals=4						) ,   [{"""score""": 0.5_199, """label""": """LABEL_0"""}, {"""score""": 0.4_801, """label""": """LABEL_1"""}] ,   )

							lowercase__	     =						video_classifier(
							    [
							        video_file_path,
							        video_file_path,
							    ] ,   top_k=2 ,   )
							self.assertEqual(
							    nested_simplify(_UpperCAmelCase ,   decimals=4						) ,   [
							        [{"""score""": 0.5_199, """label""": """LABEL_0"""}, {"""score""": 0.4_801, """label""": """LABEL_1"""}],
							        [{"""score""": 0.5_199, """label""": """LABEL_0"""}, {"""score""": 0.4_801, """label""": """LABEL_1"""}],
							    ] ,   )


					@require_tf
					def     lowerCamelCase__	(self       :		Any						)		->  Union[str, Any]:




							"""simple docstring"""


							pass

