



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




		'''simple docstring'''



		snake_case_     =MODEL_FOR_VIDEO_CLASSIFICATION_MAPPING



		def 		lowerCAmelCase__				(self		,__lowerCamelCase		,__lowerCamelCase		,__lowerCamelCase			)					->      List[Any]:

						"""simple docstring"""






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



		def 		lowerCAmelCase__				(self		,__lowerCamelCase		,__lowerCamelCase			)					->      List[Any]:

						"""simple docstring"""






						for example in examples:
										lowerCAmelCase__					:    str												=					video_classifier(__lowerCamelCase			)

										self.assertEqual(
										    __lowerCamelCase		,[
										        {'''score''': ANY(__lowerCamelCase			), '''label''': ANY(__lowerCamelCase			)},
										        {'''score''': ANY(__lowerCamelCase			), '''label''': ANY(__lowerCamelCase			)},
										    ]		,)



		@require_torch
		def 		lowerCAmelCase__				(self			)					->      Union[str, Any]:

						"""simple docstring"""






						lowerCAmelCase__					:    Tuple												=					"""hf-internal-testing/tiny-random-VideoMAEForVideoClassification"""
						lowerCAmelCase__					:    Dict												=					VideoMAEFeatureExtractor(
						    size={'''shortest_edge''': 10}		,crop_size={'''height''': 10, '''width''': 10}			)
						lowerCAmelCase__					:    int												=					pipeline(
						    '''video-classification'''		,model=__lowerCamelCase		,feature_extractor=__lowerCamelCase		,frame_sampling_rate=4			)

						lowerCAmelCase__					:    Any												=					hf_hub_download(repo_id='''nateraw/video-demo'''		,filename='''archery.mp4'''		,repo_type='''dataset'''			)
						lowerCAmelCase__					:    List[str]												=					video_classifier(__lowerCamelCase		,top_k=2			)
						self.assertEqual(
						    nested_simplify(__lowerCamelCase		,decimals=4			)		,[{'''score''': 0.5199, '''label''': '''LABEL_0'''}, {'''score''': 0.4801, '''label''': '''LABEL_1'''}]		,)

						lowerCAmelCase__					:    Union[str, Any]												=					video_classifier(
						    [
						        video_file_path,
						        video_file_path,
						    ]		,top_k=2		,)
						self.assertEqual(
						    nested_simplify(__lowerCamelCase		,decimals=4			)		,[
						        [{'''score''': 0.5199, '''label''': '''LABEL_0'''}, {'''score''': 0.4801, '''label''': '''LABEL_1'''}],
						        [{'''score''': 0.5199, '''label''': '''LABEL_0'''}, {'''score''': 0.4801, '''label''': '''LABEL_1'''}],
						    ]		,)



		@require_tf
		def 		lowerCAmelCase__				(self			)					->      Any:

						"""simple docstring"""






						pass






from typing import TYPE_CHECKING

from ...utils import (
    OptionalDependencyNotAvailable,
    _LazyModule,
    is_flax_available,
    is_tf_available,
    is_torch_available,
)


__snake_case    :		Optional[int]  ={
    'configuration_vision_text_dual_encoder': ['VisionTextDualEncoderConfig'],
    'processing_vision_text_dual_encoder': ['VisionTextDualEncoderProcessor'],
}


try:
							if not is_torch_available():
														raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
							pass
else:
							__snake_case    :		int  =['VisionTextDualEncoderModel']


try:
							if not is_flax_available():
														raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
							pass
else:
							__snake_case    :		List[str]  =['FlaxVisionTextDualEncoderModel']

try:
							if not is_tf_available():
														raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
							pass
else:
							__snake_case    :		Tuple  =['TFVisionTextDualEncoderModel']


if TYPE_CHECKING:
							from .configuration_vision_text_dual_encoder import VisionTextDualEncoderConfig
							from .processing_vision_text_dual_encoder import VisionTextDualEncoderProcessor

							try:
														if not is_torch_available():
																					raise OptionalDependencyNotAvailable()
							except OptionalDependencyNotAvailable:
														pass
							else:
														from .modeling_vision_text_dual_encoder import VisionTextDualEncoderModel

							try:
														if not is_flax_available():
																					raise OptionalDependencyNotAvailable()
							except OptionalDependencyNotAvailable:
														pass
							else:
														from .modeling_flax_vision_text_dual_encoder import FlaxVisionTextDualEncoderModel

							try:
														if not is_tf_available():
																					raise OptionalDependencyNotAvailable()
							except OptionalDependencyNotAvailable:
														pass
							else:
														from .modeling_tf_vision_text_dual_encoder import TFVisionTextDualEncoderModel


else:
							import sys

							__snake_case    :		str  =_LazyModule(__name__, globals()['__file__'], _import_structure)

