



"""simple docstring"""

from typing import TYPE_CHECKING

from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_tf_available, is_torch_available


lowercase__    :  Optional[Any]							    =	{
    "configuration_transfo_xl": ["TRANSFO_XL_PRETRAINED_CONFIG_ARCHIVE_MAP", "TransfoXLConfig"],
    "tokenization_transfo_xl": ["TransfoXLCorpus", "TransfoXLTokenizer"],
}

try:
     if not is_torch_available():
          raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
     pass
else:
     lowercase__    :  Optional[Any]							    =	[
         "TRANSFO_XL_PRETRAINED_MODEL_ARCHIVE_LIST",
         "AdaptiveEmbedding",
         "TransfoXLForSequenceClassification",
         "TransfoXLLMHeadModel",
         "TransfoXLModel",
         "TransfoXLPreTrainedModel",
         "load_tf_weights_in_transfo_xl",
     ]

try:
     if not is_tf_available():
          raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
     pass
else:
     lowercase__    :  Optional[Any]							    =	[
         "TF_TRANSFO_XL_PRETRAINED_MODEL_ARCHIVE_LIST",
         "TFAdaptiveEmbedding",
         "TFTransfoXLForSequenceClassification",
         "TFTransfoXLLMHeadModel",
         "TFTransfoXLMainLayer",
         "TFTransfoXLModel",
         "TFTransfoXLPreTrainedModel",
     ]


if TYPE_CHECKING:
     from .configuration_transfo_xl import TRANSFO_XL_PRETRAINED_CONFIG_ARCHIVE_MAP, TransfoXLConfig
     from .tokenization_transfo_xl import TransfoXLCorpus, TransfoXLTokenizer

     try:
          if not is_torch_available():
               raise OptionalDependencyNotAvailable()
     except OptionalDependencyNotAvailable:
          pass
     else:
          from .modeling_transfo_xl import (
              TRANSFO_XL_PRETRAINED_MODEL_ARCHIVE_LIST,
              AdaptiveEmbedding,
              TransfoXLForSequenceClassification,
              TransfoXLLMHeadModel,
              TransfoXLModel,
              TransfoXLPreTrainedModel,
              load_tf_weights_in_transfo_xl,
          )

     try:
          if not is_tf_available():
               raise OptionalDependencyNotAvailable()
     except OptionalDependencyNotAvailable:
          pass
     else:
          from .modeling_tf_transfo_xl import (
              TF_TRANSFO_XL_PRETRAINED_MODEL_ARCHIVE_LIST,
              TFAdaptiveEmbedding,
              TFTransfoXLForSequenceClassification,
              TFTransfoXLLMHeadModel,
              TFTransfoXLMainLayer,
              TFTransfoXLModel,
              TFTransfoXLPreTrainedModel,
          )

else:
     import sys

     lowercase__    :  Optional[int]							    =	_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 				lowercase					(		unittest.TestCase   ):
		__lowercase       :       Any	     =				MODEL_FOR_VIDEO_CLASSIFICATION_MAPPING



		def __UpperCamelCase ( self				,      A_				,      A_				,      A_       )  ->					List[Any]:
				"""simple docstring"""
				UpperCamelCase		=     hf_hub_download(
				    repo_id='nateraw/video-demo'				,      filename='archery.mp4'				,      repo_type='dataset'       )
				UpperCamelCase		=     VideoClassificationPipeline(model=A_				,      image_processor=A_				,      top_k=2       )
				UpperCamelCase		=     [
				    example_video_filepath,
				    'https://huggingface.co/datasets/nateraw/video-demo/resolve/main/archery.mp4',
				]
				return video_classifier, examples



		def __UpperCamelCase ( self				,      A_				,      A_       )  ->					Optional[int]:
				"""simple docstring"""
				for example in examples:
						UpperCamelCase		=     video_classifier(A_       )

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



		@require_torch
		def __UpperCamelCase ( self       )  ->					Optional[Any]:
				"""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=A_				,      feature_extractor=A_				,      frame_sampling_rate=4       )

				UpperCamelCase		=     hf_hub_download(repo_id='nateraw/video-demo'				,      filename='archery.mp4'				,      repo_type='dataset'       )
				UpperCamelCase		=     video_classifier(A_				,      top_k=2       )
				self.assertEqual(
				    nested_simplify(A_				,      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(A_				,      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 __UpperCamelCase ( self       )  ->					Tuple:
				"""simple docstring"""
				pass
