


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






			_UpperCamelCase		:       List[Any] 			=		MODEL_FOR_VIDEO_CLASSIFICATION_MAPPING




			def 					snake_case__					(				self   ,    snake_case   ,    snake_case   ,    snake_case  ):

						'''simple docstring'''


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




			def 					snake_case__					(				self   ,    snake_case   ,    snake_case  ):

						'''simple docstring'''


						for example in examples:
									UpperCamelCase__       =							video_classifier(lowerCAmelCase__  )

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




			@require_torch
			def 					snake_case__					(				self  ):

						'''simple docstring'''


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

						UpperCamelCase__       =							hf_hub_download(repo_id="nateraw/video-demo"   ,    filename="archery.mp4"   ,    repo_type="dataset"  )
						UpperCamelCase__       =							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"}]   ,    )

						UpperCamelCase__       =							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 					snake_case__					(				self  ):

						'''simple docstring'''


						pass






from typing import TYPE_CHECKING

from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_torch_available


lowerCAmelCase__			:      Union[str, Any]								={
    'configuration_blip_2': [
        'BLIP_2_PRETRAINED_CONFIG_ARCHIVE_MAP',
        'Blip2Config',
        'Blip2QFormerConfig',
        'Blip2VisionConfig',
    ],
    'processing_blip_2': ['Blip2Processor'],
}

try:
				if not is_torch_available():
								raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
				pass
else:
				lowerCAmelCase__			:      Dict								=[
				    'BLIP_2_PRETRAINED_MODEL_ARCHIVE_LIST',
				    'Blip2Model',
				    'Blip2QFormerModel',
				    'Blip2PreTrainedModel',
				    'Blip2ForConditionalGeneration',
				    'Blip2VisionModel',
				]

if TYPE_CHECKING:
				from .configuration_blip_a import (
				    BLIP_2_PRETRAINED_CONFIG_ARCHIVE_MAP,
				    BlipaConfig,
				    BlipaQFormerConfig,
				    BlipaVisionConfig,
				)
				from .processing_blip_a import BlipaProcessor

				try:
								if not is_torch_available():
												raise OptionalDependencyNotAvailable()
				except OptionalDependencyNotAvailable:
								pass
				else:
								from .modeling_blip_a import (
								    BLIP_2_PRETRAINED_MODEL_ARCHIVE_LIST,
								    BlipaForConditionalGeneration,
								    BlipaModel,
								    BlipaPreTrainedModel,
								    BlipaQFormerModel,
								    BlipaVisionModel,
								)

else:
				import sys

				lowerCAmelCase__			:      Union[str, Any]								=_LazyModule(__name__, globals()['__file__'], _import_structure, module_spec=__spec__)





