





'''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      UpperCamelCase__					(					unittest.TestCase			):




					"""simple docstring"""
					SCREAMING_SNAKE_CASE__				=	MODEL_FOR_VIDEO_CLASSIFICATION_MAPPING


					def lowerCamelCase_			(						self				:			int      ,						lowerCamelCase_				:			Tuple      ,						lowerCamelCase_				:			str      ,						lowerCamelCase_				:			int						):

							'''simple docstring'''



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


					def lowerCamelCase_			(						self				:			Union[str, Any]      ,						lowerCamelCase_				:			int      ,						lowerCamelCase_				:			Any						):

							'''simple docstring'''



							for example in examples:
									SCREAMING_SNAKE_CASE :				Union[str, Any]		=			video_classifier(lowerCamelCase_						)

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


					@require_torch
					def lowerCamelCase_			(						self				:			List[str]						):

							'''simple docstring'''



							SCREAMING_SNAKE_CASE :				List[str]		=			"""hf-internal-testing/tiny-random-VideoMAEForVideoClassification"""
							SCREAMING_SNAKE_CASE :				str		=			VideoMAEFeatureExtractor(
							    size={"""shortest_edge""": 10}      ,						crop_size={"""height""": 10, """width""": 10}						)
							SCREAMING_SNAKE_CASE :				int		=			pipeline(
							    """video-classification"""      ,						model=lowerCamelCase_      ,						feature_extractor=lowerCamelCase_      ,						frame_sampling_rate=4						)

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

							SCREAMING_SNAKE_CASE :				Any		=			video_classifier(
							    [
							        video_file_path,
							        video_file_path,
							    ]      ,						top_k=2      ,						)
							self.assertEqual(
							    nested_simplify(lowerCamelCase_      ,						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				:			List[Any]						):

							'''simple docstring'''



							pass










'''simple docstring'''




import unittest

from transformers import DonutProcessor


__UpperCAmelCase            =       """naver-clova-ix/donut-base"""




class      UpperCamelCase__					(					unittest.TestCase			):




					"""simple docstring"""


					def lowerCamelCase_			(						self				:			List[str]						):

							'''simple docstring'''



							SCREAMING_SNAKE_CASE :				Any		=			DonutProcessor.from_pretrained(lowerCamelCase_						)



					def lowerCamelCase_			(						self				:			Tuple						):

							'''simple docstring'''



							SCREAMING_SNAKE_CASE :				Optional[int]		=			{
							    """name""": """John Doe""",
							    """age""": """99""",
							    """city""": """Atlanta""",
							    """state""": """GA""",
							    """zip""": """30301""",
							    """phone""": """123-4567""",
							    """nicknames""": [{"""nickname""": """Johnny"""}, {"""nickname""": """JD"""}],
							}

							SCREAMING_SNAKE_CASE :				List[Any]		=			(
							    """<s_name>John Doe</s_name><s_age>99</s_age><s_city>Atlanta</s_city>"""
							    """<s_state>GA</s_state><s_zip>30301</s_zip><s_phone>123-4567</s_phone>"""
							    """<s_nicknames><s_nickname>Johnny</s_nickname>"""
							    """<sep/><s_nickname>JD</s_nickname></s_nicknames>"""
							)
							SCREAMING_SNAKE_CASE :				List[Any]		=			self.processor.tokenajson(lowerCamelCase_						)

							self.assertDictEqual(lowerCamelCase_      ,						lowerCamelCase_						)



