


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






    lowerCamelCase  :					Tuple							     =			MODEL_FOR_VIDEO_CLASSIFICATION_MAPPING







    def       lowercase_				(							self			,     SCREAMING_SNAKE_CASE_			,     SCREAMING_SNAKE_CASE_			,     SCREAMING_SNAKE_CASE_	)				->     List[Any]:
         __lowerCamelCase   :	Dict								=		hf_hub_download(
             repo_id='nateraw/video-demo'			,     filename='archery.mp4'			,     repo_type='dataset'	)
         __lowerCamelCase   :	int								=		VideoClassificationPipeline(model=SCREAMING_SNAKE_CASE_			,     image_processor=SCREAMING_SNAKE_CASE_			,     top_k=2	)
         __lowerCamelCase   :	Union[str, Any]								=		[
             example_video_filepath,
             'https://huggingface.co/datasets/nateraw/video-demo/resolve/main/archery.mp4',
         ]
         return video_classifier, examples







    def       lowercase_				(							self			,     SCREAMING_SNAKE_CASE_			,     SCREAMING_SNAKE_CASE_	)				->     Dict:
         for example in examples:
              __lowerCamelCase   :	Tuple								=		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       lowercase_				(							self	)				->     Optional[int]:
         __lowerCamelCase   :	Optional[Any]								=		'hf-internal-testing/tiny-random-VideoMAEForVideoClassification'
         __lowerCamelCase   :	Optional[int]								=		VideoMAEFeatureExtractor(
             size={'shortest_edge': 10}			,     crop_size={'height': 10, 'width': 10}	)
         __lowerCamelCase   :	str								=		pipeline(
             'video-classification'			,     model=SCREAMING_SNAKE_CASE_			,     feature_extractor=SCREAMING_SNAKE_CASE_			,     frame_sampling_rate=4	)

         __lowerCamelCase   :	Tuple								=		hf_hub_download(repo_id='nateraw/video-demo'			,     filename='archery.mp4'			,     repo_type='dataset'	)
         __lowerCamelCase   :	int								=		video_classifier(SCREAMING_SNAKE_CASE_			,     top_k=2	)
         self.assertEqual(
             nested_simplify(SCREAMING_SNAKE_CASE_			,     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(SCREAMING_SNAKE_CASE_			,     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       lowercase_				(							self	)				->     int:
         pass










'''simple docstring'''



from typing import TYPE_CHECKING

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


A__		:					List[str]												=  {"""configuration_beit""": ["""BEIT_PRETRAINED_CONFIG_ARCHIVE_MAP""", """BeitConfig""", """BeitOnnxConfig"""]}

try:
      if not is_vision_available():
            raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
      pass
else:
      A__		:					str												=  ["""BeitFeatureExtractor"""]
      A__		:					List[str]												=  ["""BeitImageProcessor"""]

try:
      if not is_torch_available():
            raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
      pass
else:
      A__		:					Optional[int]												=  [
          """BEIT_PRETRAINED_MODEL_ARCHIVE_LIST""",
          """BeitForImageClassification""",
          """BeitForMaskedImageModeling""",
          """BeitForSemanticSegmentation""",
          """BeitModel""",
          """BeitPreTrainedModel""",
      ]


try:
      if not is_flax_available():
            raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
      pass
else:
      A__		:					Any												=  [
          """FlaxBeitForImageClassification""",
          """FlaxBeitForMaskedImageModeling""",
          """FlaxBeitModel""",
          """FlaxBeitPreTrainedModel""",
      ]

if TYPE_CHECKING:
      from .configuration_beit import BEIT_PRETRAINED_CONFIG_ARCHIVE_MAP, BeitConfig, BeitOnnxConfig

      try:
            if not is_vision_available():
                  raise OptionalDependencyNotAvailable()
      except OptionalDependencyNotAvailable:
            pass
      else:
            from .feature_extraction_beit import BeitFeatureExtractor
            from .image_processing_beit import BeitImageProcessor

      try:
            if not is_torch_available():
                  raise OptionalDependencyNotAvailable()
      except OptionalDependencyNotAvailable:
            pass
      else:
            from .modeling_beit import (
                BEIT_PRETRAINED_MODEL_ARCHIVE_LIST,
                BeitForImageClassification,
                BeitForMaskedImageModeling,
                BeitForSemanticSegmentation,
                BeitModel,
                BeitPreTrainedModel,
            )

      try:
            if not is_flax_available():
                  raise OptionalDependencyNotAvailable()
      except OptionalDependencyNotAvailable:
            pass
      else:
            from .modeling_flax_beit import (
                FlaxBeitForImageClassification,
                FlaxBeitForMaskedImageModeling,
                FlaxBeitModel,
                FlaxBeitPreTrainedModel,
            )


else:
      import sys

      A__		:					Optional[Any]												=  _LazyModule(__name__, globals()["""__file__"""], _import_structure, module_spec=__spec__)






