


from typing import TYPE_CHECKING

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


UpperCAmelCase    =							{'configuration_deit': ['DEIT_PRETRAINED_CONFIG_ARCHIVE_MAP', 'DeiTConfig', 'DeiTOnnxConfig']}

try:
   if not is_vision_available():
      raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
   pass
else:
   UpperCAmelCase    =							['DeiTFeatureExtractor']
   UpperCAmelCase    =							['DeiTImageProcessor']

try:
   if not is_torch_available():
      raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
   pass
else:
   UpperCAmelCase    =							[
       'DEIT_PRETRAINED_MODEL_ARCHIVE_LIST',
       'DeiTForImageClassification',
       'DeiTForImageClassificationWithTeacher',
       'DeiTForMaskedImageModeling',
       'DeiTModel',
       'DeiTPreTrainedModel',
   ]

try:
   if not is_tf_available():
      raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
   pass
else:
   UpperCAmelCase    =							[
       'TF_DEIT_PRETRAINED_MODEL_ARCHIVE_LIST',
       'TFDeiTForImageClassification',
       'TFDeiTForImageClassificationWithTeacher',
       'TFDeiTForMaskedImageModeling',
       'TFDeiTModel',
       'TFDeiTPreTrainedModel',
   ]


if TYPE_CHECKING:
   from .configuration_deit import DEIT_PRETRAINED_CONFIG_ARCHIVE_MAP, DeiTConfig, DeiTOnnxConfig

   try:
      if not is_vision_available():
         raise OptionalDependencyNotAvailable()
   except OptionalDependencyNotAvailable:
      pass
   else:
      from .feature_extraction_deit import DeiTFeatureExtractor
      from .image_processing_deit import DeiTImageProcessor

   try:
      if not is_torch_available():
         raise OptionalDependencyNotAvailable()
   except OptionalDependencyNotAvailable:
      pass
   else:
      from .modeling_deit import (
          DEIT_PRETRAINED_MODEL_ARCHIVE_LIST,
          DeiTForImageClassification,
          DeiTForImageClassificationWithTeacher,
          DeiTForMaskedImageModeling,
          DeiTModel,
          DeiTPreTrainedModel,
      )

   try:
      if not is_tf_available():
         raise OptionalDependencyNotAvailable()
   except OptionalDependencyNotAvailable:
      pass
   else:
      from .modeling_tf_deit import (
          TF_DEIT_PRETRAINED_MODEL_ARCHIVE_LIST,
          TFDeiTForImageClassification,
          TFDeiTForImageClassificationWithTeacher,
          TFDeiTForMaskedImageModeling,
          TFDeiTModel,
          TFDeiTPreTrainedModel,
      )


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 		UpperCamelCase__  (			self	,   _UpperCAmelCase	,   _UpperCAmelCase	,   _UpperCAmelCase      ):
       snake_case_ =   hf_hub_download(
           repo_id='''nateraw/video-demo'''	,   filename='''archery.mp4'''	,   repo_type='''dataset'''      )
       snake_case_ =   VideoClassificationPipeline(model=_UpperCAmelCase	,   image_processor=_UpperCAmelCase	,   top_k=2      )
       snake_case_ =   [
           example_video_filepath,
           '''https://huggingface.co/datasets/nateraw/video-demo/resolve/main/archery.mp4''',
       ]
       return video_classifier, examples



 def 		UpperCamelCase__  (			self	,   _UpperCAmelCase	,   _UpperCAmelCase      ):
       for example in examples:
             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      ):
       snake_case_ =   '''hf-internal-testing/tiny-random-VideoMAEForVideoClassification'''
       snake_case_ =   VideoMAEFeatureExtractor(
           size={'''shortest_edge''': 10}	,   crop_size={'''height''': 10, '''width''': 10}      )
       snake_case_ =   pipeline(
           '''video-classification'''	,   model=_UpperCAmelCase	,   feature_extractor=_UpperCAmelCase	,   frame_sampling_rate=4      )

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

       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      ):
       pass