





'''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  ):
      _lowercase:     Union[str, Any]			=  MODEL_FOR_VIDEO_CLASSIFICATION_MAPPING




      def 							lowercase__       (     self     :					Union[str, Any]     ,     __snake_case     :					Tuple     ,     __snake_case     :					Optional[Any]     ,     __snake_case     :					int    )							-> str:
            _lowerCAmelCase					=				hf_hub_download(
                repo_id="""nateraw/video-demo"""     ,     filename="""archery.mp4"""     ,     repo_type="""dataset"""    )
            _lowerCAmelCase					=				VideoClassificationPipeline(model=__snake_case     ,     image_processor=__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 							lowercase__       (     self     :					Tuple     ,     __snake_case     :					Optional[Any]     ,     __snake_case     :					Union[str, Any]    )							-> Dict:
            for example in examples:
                  _lowerCAmelCase					=				video_classifier(__snake_case    )

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




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

            _lowerCAmelCase					=				hf_hub_download(repo_id="""nateraw/video-demo"""     ,     filename="""archery.mp4"""     ,     repo_type="""dataset"""    )
            _lowerCAmelCase					=				video_classifier(__snake_case     ,     top_k=2    )
            self.assertEqual(
                nested_simplify(__snake_case     ,     decimals=4    )     ,     [{"""score""": 0.51_99, """label""": """LABEL_0"""}, {"""score""": 0.48_01, """label""": """LABEL_1"""}]     ,     )

            _lowerCAmelCase					=				video_classifier(
                [
                    video_file_path,
                    video_file_path,
                ]     ,     top_k=2     ,     )
            self.assertEqual(
                nested_simplify(__snake_case     ,     decimals=4    )     ,     [
                    [{"""score""": 0.51_99, """label""": """LABEL_0"""}, {"""score""": 0.48_01, """label""": """LABEL_1"""}],
                    [{"""score""": 0.51_99, """label""": """LABEL_0"""}, {"""score""": 0.48_01, """label""": """LABEL_1"""}],
                ]     ,     )




      @require_tf
      def 							lowercase__       (     self     :					Union[str, Any]    )							-> Dict:
            pass













'''simple docstring'''






# Copyright 2023 The HuggingFace Team. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from typing import TYPE_CHECKING

from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_torch_available


A__							:  int    ={
    '''configuration_xmod''': [
        '''XMOD_PRETRAINED_CONFIG_ARCHIVE_MAP''',
        '''XmodConfig''',
        '''XmodOnnxConfig''',
    ],
}

try:
      if not is_torch_available():
            raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
      pass
else:
      A__							:  List[str]    =[
          '''XMOD_PRETRAINED_MODEL_ARCHIVE_LIST''',
          '''XmodForCausalLM''',
          '''XmodForMaskedLM''',
          '''XmodForMultipleChoice''',
          '''XmodForQuestionAnswering''',
          '''XmodForSequenceClassification''',
          '''XmodForTokenClassification''',
          '''XmodModel''',
          '''XmodPreTrainedModel''',
      ]

if TYPE_CHECKING:
      from .configuration_xmod import XMOD_PRETRAINED_CONFIG_ARCHIVE_MAP, XmodConfig, XmodOnnxConfig

      try:
            if not is_torch_available():
                  raise OptionalDependencyNotAvailable()
      except OptionalDependencyNotAvailable:
            pass
      else:
            from .modeling_xmod import (
                XMOD_PRETRAINED_MODEL_ARCHIVE_LIST,
                XmodForCausalLM,
                XmodForMaskedLM,
                XmodForMultipleChoice,
                XmodForQuestionAnswering,
                XmodForSequenceClassification,
                XmodForTokenClassification,
                XmodModel,
                XmodPreTrainedModel,
            )

else:
      import sys

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






