"""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 			_snake_case  (       unittest.TestCase		):
						snake_case__      	=      MODEL_FOR_VIDEO_CLASSIFICATION_MAPPING






						def    lowerCamelCase__  (							self   :      List[str]				,       UpperCAmelCase   :      List[str]				,       UpperCAmelCase   :      Dict				,       UpperCAmelCase   :      Tuple     ):
													__lowerCamelCase       :		List[Any]		 =  hf_hub_download(
													    repo_id="nateraw/video-demo"				,       filename="archery.mp4"				,       repo_type="dataset"     )
													__lowerCamelCase       :		Any		 =  VideoClassificationPipeline(model=_UpperCAmelCase				,       image_processor=_UpperCAmelCase				,       top_k=2     )
													__lowerCamelCase       :		Optional[int]		 =  [
													    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     ):


													for example in examples:
																				__lowerCamelCase       :		Optional[int]		 =  video_classifier(_UpperCAmelCase     )

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






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

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

													__lowerCamelCase       :		Dict		 =  video_classifier(
													    [
													        video_file_path,
													        video_file_path,
													    ]				,       top_k=2				,       )
													self.assertEqual(
													    nested_simplify(_UpperCAmelCase				,       decimals=4     )				,       [
													        [{"score": 0.5_1_9_9, "label": "LABEL_0"}, {"score": 0.4_8_0_1, "label": "LABEL_1"}],
													        [{"score": 0.5_1_9_9, "label": "LABEL_0"}, {"score": 0.4_8_0_1, "label": "LABEL_1"}],
													    ]				,       )







						@require_tf
						def    lowerCamelCase__  (							self   :      Any     ):
													pass



from typing import Optional

from .. import Features, NamedSplit
from ..packaged_modules.text.text import Text
from ..utils.typing import NestedDataStructureLike, PathLike
from .abc import AbstractDatasetReader



class 				A       (			UpperCAmelCase__				):
					'''simple docstring'''






					def __init__(self       :		Any ,   _UpperCAmelCase       :		NestedDataStructureLike[PathLike] ,   _UpperCAmelCase       :		Optional[NamedSplit] = None ,   _UpperCAmelCase       :		Optional[Features] = None ,   _UpperCAmelCase       :		str = None ,   _UpperCAmelCase       :		bool = False ,   _UpperCAmelCase       :		bool = False ,   _UpperCAmelCase       :		Optional[int] = None ,   **_UpperCAmelCase       :		Optional[int] ,   )		->  List[str]:




							"""simple docstring"""


							super().__init__(
							    _UpperCAmelCase ,   split=_UpperCAmelCase ,   features=_UpperCAmelCase ,   cache_dir=_UpperCAmelCase ,   keep_in_memory=_UpperCAmelCase ,   streaming=_UpperCAmelCase ,   num_proc=_UpperCAmelCase ,   **_UpperCAmelCase ,   )
							lowercase__	     =						path_or_paths if isinstance(_UpperCAmelCase ,   _UpperCAmelCase						) else {self.split: path_or_paths}
							lowercase__	     =						Text(
							    cache_dir=_UpperCAmelCase ,   data_files=_UpperCAmelCase ,   features=_UpperCAmelCase ,   **_UpperCAmelCase ,   )


					def     lowerCamelCase__	(self       :		Tuple						)		->  Any:




							"""simple docstring"""


							if self.streaming:
									lowercase__	     =						self.builder.as_streaming_dataset(split=self.split						)
							# Build regular (map-style) dataset
							else:
									lowercase__	     =						None
									lowercase__	     =						None
									lowercase__	     =						None
									lowercase__	     =						None

									self.builder.download_and_prepare(
									    download_config=_UpperCAmelCase ,   download_mode=_UpperCAmelCase ,   verification_mode=_UpperCAmelCase ,   base_path=_UpperCAmelCase ,   num_proc=self.num_proc ,   )
									lowercase__	     =						self.builder.as_dataset(
									    split=self.split ,   verification_mode=_UpperCAmelCase ,   in_memory=self.keep_in_memory						)
							return dataset

