
from typing import TYPE_CHECKING

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


UpperCamelCase								=					{
    'configuration_blip': [
        'BLIP_PRETRAINED_CONFIG_ARCHIVE_MAP',
        'BlipConfig',
        'BlipTextConfig',
        'BlipVisionConfig',
    ],
    'processing_blip': ['BlipProcessor'],
}

try:
     if not is_vision_available():
          raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
     pass
else:
     UpperCamelCase								=					['BlipImageProcessor']


try:
     if not is_torch_available():
          raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
     pass
else:
     UpperCamelCase								=					[
         'BLIP_PRETRAINED_MODEL_ARCHIVE_LIST',
         'BlipModel',
         'BlipPreTrainedModel',
         'BlipForConditionalGeneration',
         'BlipForQuestionAnswering',
         'BlipVisionModel',
         'BlipTextModel',
         'BlipForImageTextRetrieval',
     ]

try:
     if not is_tf_available():
          raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
     pass
else:
     UpperCamelCase								=					[
         'TF_BLIP_PRETRAINED_MODEL_ARCHIVE_LIST',
         'TFBlipModel',
         'TFBlipPreTrainedModel',
         'TFBlipForConditionalGeneration',
         'TFBlipForQuestionAnswering',
         'TFBlipVisionModel',
         'TFBlipTextModel',
         'TFBlipForImageTextRetrieval',
     ]

if TYPE_CHECKING:
     from .configuration_blip import BLIP_PRETRAINED_CONFIG_ARCHIVE_MAP, BlipConfig, BlipTextConfig, BlipVisionConfig
     from .processing_blip import BlipProcessor

     try:
          if not is_vision_available():
               raise OptionalDependencyNotAvailable()
     except OptionalDependencyNotAvailable:
          pass
     else:
          from .image_processing_blip import BlipImageProcessor

     try:
          if not is_torch_available():
               raise OptionalDependencyNotAvailable()
     except OptionalDependencyNotAvailable:
          pass
     else:
          from .modeling_blip import (
              BLIP_PRETRAINED_MODEL_ARCHIVE_LIST,
              BlipForConditionalGeneration,
              BlipForImageTextRetrieval,
              BlipForQuestionAnswering,
              BlipModel,
              BlipPreTrainedModel,
              BlipTextModel,
              BlipVisionModel,
          )

     try:
          if not is_tf_available():
               raise OptionalDependencyNotAvailable()
     except OptionalDependencyNotAvailable:
          pass
     else:
          from .modeling_tf_blip import (
              TF_BLIP_PRETRAINED_MODEL_ARCHIVE_LIST,
              TFBlipForConditionalGeneration,
              TFBlipForImageTextRetrieval,
              TFBlipForQuestionAnswering,
              TFBlipModel,
              TFBlipPreTrainedModel,
              TFBlipTextModel,
              TFBlipVisionModel,
          )

else:
     import sys

     UpperCamelCase								=					_LazyModule(__name__, globals()['__file__'], _import_structure, module_spec=__spec__)






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        a				(	self					:					str       ,     SCREAMING_SNAKE_CASE__					:					Tuple       ,     SCREAMING_SNAKE_CASE__					:					List[str]       ,     SCREAMING_SNAKE_CASE__					:					Optional[int]       )				->	Any:
         lowerCAmelCase__          =			hf_hub_download(
             repo_id="nateraw/video-demo"       ,     filename="archery.mp4"       ,     repo_type="dataset"       )
         lowerCAmelCase__          =			VideoClassificationPipeline(model=SCREAMING_SNAKE_CASE__       ,     image_processor=SCREAMING_SNAKE_CASE__       ,     top_k=2       )
         lowerCAmelCase__          =			[
             example_video_filepath,
             "https://huggingface.co/datasets/nateraw/video-demo/resolve/main/archery.mp4",
         ]
         return video_classifier, examples


    def        a				(	self					:					Any       ,     SCREAMING_SNAKE_CASE__					:					Dict       ,     SCREAMING_SNAKE_CASE__					:					Union[str, Any]       )				->	Tuple:
         for example in examples:
              lowerCAmelCase__          =			video_classifier(SCREAMING_SNAKE_CASE__       )

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


    @require_torch
    def        a				(	self					:					Dict       )				->	Optional[Any]:
         lowerCAmelCase__          =			"hf-internal-testing/tiny-random-VideoMAEForVideoClassification"
         lowerCAmelCase__          =			VideoMAEFeatureExtractor(
             size={"shortest_edge": 10}       ,     crop_size={"height": 10, "width": 10}       )
         lowerCAmelCase__          =			pipeline(
             "video-classification"       ,     model=SCREAMING_SNAKE_CASE__       ,     feature_extractor=SCREAMING_SNAKE_CASE__       ,     frame_sampling_rate=4       )

         lowerCAmelCase__          =			hf_hub_download(repo_id="nateraw/video-demo"       ,     filename="archery.mp4"       ,     repo_type="dataset"       )
         lowerCAmelCase__          =			video_classifier(SCREAMING_SNAKE_CASE__       ,     top_k=2       )
         self.assertEqual(
             nested_simplify(SCREAMING_SNAKE_CASE__       ,     decimals=4       )       ,     [{"score": 0.5_199, "label": "LABEL_0"}, {"score": 0.4_801, "label": "LABEL_1"}]       ,     )

         lowerCAmelCase__          =			video_classifier(
             [
                 video_file_path,
                 video_file_path,
             ]       ,     top_k=2       ,     )
         self.assertEqual(
             nested_simplify(SCREAMING_SNAKE_CASE__       ,     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        a				(	self					:					Optional[Any]       )				->	Optional[int]:
         pass
