


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"""







				lowerCAmelCase					=			MODEL_FOR_VIDEO_CLASSIFICATION_MAPPING

				def   _UpperCAmelCase       (    self					, a__					, a__					, a__ )						->					Optional[Any]:
					A             =					hf_hub_download(
					    repo_id="""nateraw/video-demo"""					, filename="""archery.mp4"""					, repo_type="""dataset""" )
					A             =					VideoClassificationPipeline(model=a__					, image_processor=a__					, 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					, a__					, a__ )						->					Optional[int]:
					for example in examples:
						A             =					video_classifier(a__ )

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

				@require_torch
				def   _UpperCAmelCase       (    self )						->					Union[str, Any]:
					A             =					"""hf-internal-testing/tiny-random-VideoMAEForVideoClassification"""
					A             =					VideoMAEFeatureExtractor(
					    size={"""shortest_edge""": 10}					, crop_size={"""height""": 10, """width""": 10} )
					A             =					pipeline(
					    """video-classification"""					, model=a__					, feature_extractor=a__					, frame_sampling_rate=4 )

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

					A             =					video_classifier(
					    [
					        video_file_path,
					        video_file_path,
					    ]					, top_k=2					, )
					self.assertEqual(
					    nested_simplify(a__					, 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   _UpperCAmelCase       (    self )						->					Dict:
					pass







_lowercase							:   Dict						=						"0.21.0"

from .accelerator import Accelerator
from .big_modeling import (
    cpu_offload,
    cpu_offload_with_hook,
    disk_offload,
    dispatch_model,
    init_empty_weights,
    init_on_device,
    load_checkpoint_and_dispatch,
)
from .data_loader import skip_first_batches
from .launchers import debug_launcher, notebook_launcher
from .state import PartialState
from .utils import (
    DeepSpeedPlugin,
    DistributedDataParallelKwargs,
    DistributedType,
    FullyShardedDataParallelPlugin,
    GradScalerKwargs,
    InitProcessGroupKwargs,
    find_executable_batch_size,
    infer_auto_device_map,
    is_rich_available,
    load_checkpoint_in_model,
    synchronize_rng_states,
)


if is_rich_available():
				from .utils import rich



