


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





	snake_case__				:  List[str]    					=			MODEL_FOR_VIDEO_CLASSIFICATION_MAPPING




	def   UpperCAmelCase_      ( self			:				Any			,			UpperCAmelCase__			:				Dict			,			UpperCAmelCase__			:				str			,			UpperCAmelCase__			:				Dict   )       ->	str:
						__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   UpperCAmelCase_      ( self			:				Optional[int]			,			UpperCAmelCase__			:				List[Any]			,			UpperCAmelCase__			:				Any   )       ->	Optional[int]:
						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   UpperCAmelCase_      ( self			:				Tuple   )       ->	Tuple:
						__SCREAMING_SNAKE_CASE						   =				"hf-internal-testing/tiny-random-VideoMAEForVideoClassification"
						__SCREAMING_SNAKE_CASE						   =				VideoMAEFeatureExtractor(
						    size={"shortest_edge": 1_0}			,			crop_size={"height": 1_0, "width": 1_0}   )
						__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.5_199, "label": "LABEL_0"}, {"score": 0.4_801, "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.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   UpperCAmelCase_      ( self			:				List[str]   )       ->	List[str]:
						pass




"""simple docstring"""







from __future__ import annotations




def    UpperCAmelCase__       (lowerCAmelCase_  ,						lowerCAmelCase_ = None  ,						lowerCAmelCase_ = None   ):




					'''simple docstring'''


					if start is None:
										__SCREAMING_SNAKE_CASE						   =				0

					if end is None:
										__SCREAMING_SNAKE_CASE						   =				len(lowerCAmelCase_   ) - 1

					if start >= end:
										return

					__SCREAMING_SNAKE_CASE						   =				(start + end) // 2

					slowsort(lowerCAmelCase_  ,						lowerCAmelCase_  ,						lowerCAmelCase_   )
					slowsort(lowerCAmelCase_  ,						mid + 1  ,						lowerCAmelCase_   )

					if sequence[end] < sequence[mid]:
										__SCREAMING_SNAKE_CASE   ,  __SCREAMING_SNAKE_CASE						   =				sequence[mid], sequence[end]

					slowsort(lowerCAmelCase_  ,						lowerCAmelCase_  ,						end - 1   )


if __name__ == "__main__":
		from doctest import testmod

		testmod()
