




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      snake_case	(						unittest.TestCase				):


   '''simple docstring'''







   UpperCamelCase__						:							Optional[int] 	=   MODEL_FOR_VIDEO_CLASSIFICATION_MAPPING




   def 						UpperCAmelCase							(       self  :						Optional[Any]    ,     lowerCamelCase_  :						Dict    ,     lowerCamelCase_  :						Union[str, Any]    ,     lowerCamelCase_  :						Optional[Any]      )       ->Optional[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  :						List[Any]    ,     lowerCamelCase_  :						List[str]    ,     lowerCamelCase_  :						Dict      )       ->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  :						List[Any]      )       ->Union[str, 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      )       ->Dict:
     '''simple docstring'''







     pass








from typing import TYPE_CHECKING

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


_lowercase							:   int						=						{
    "configuration_roberta_prelayernorm": [
        "ROBERTA_PRELAYERNORM_PRETRAINED_CONFIG_ARCHIVE_MAP",
        "RobertaPreLayerNormConfig",
        "RobertaPreLayerNormOnnxConfig",
    ],
}

try:
				if not is_torch_available():
								raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
				pass
else:
				_lowercase							:   List[Any]						=						[
				    "ROBERTA_PRELAYERNORM_PRETRAINED_MODEL_ARCHIVE_LIST",
				    "RobertaPreLayerNormForCausalLM",
				    "RobertaPreLayerNormForMaskedLM",
				    "RobertaPreLayerNormForMultipleChoice",
				    "RobertaPreLayerNormForQuestionAnswering",
				    "RobertaPreLayerNormForSequenceClassification",
				    "RobertaPreLayerNormForTokenClassification",
				    "RobertaPreLayerNormModel",
				    "RobertaPreLayerNormPreTrainedModel",
				]

try:
				if not is_tf_available():
								raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
				pass
else:
				_lowercase							:   Optional[int]						=						[
				    "TF_ROBERTA_PRELAYERNORM_PRETRAINED_MODEL_ARCHIVE_LIST",
				    "TFRobertaPreLayerNormForCausalLM",
				    "TFRobertaPreLayerNormForMaskedLM",
				    "TFRobertaPreLayerNormForMultipleChoice",
				    "TFRobertaPreLayerNormForQuestionAnswering",
				    "TFRobertaPreLayerNormForSequenceClassification",
				    "TFRobertaPreLayerNormForTokenClassification",
				    "TFRobertaPreLayerNormMainLayer",
				    "TFRobertaPreLayerNormModel",
				    "TFRobertaPreLayerNormPreTrainedModel",
				]

try:
				if not is_flax_available():
								raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
				pass
else:
				_lowercase							:   str						=						[
				    "FlaxRobertaPreLayerNormForCausalLM",
				    "FlaxRobertaPreLayerNormForMaskedLM",
				    "FlaxRobertaPreLayerNormForMultipleChoice",
				    "FlaxRobertaPreLayerNormForQuestionAnswering",
				    "FlaxRobertaPreLayerNormForSequenceClassification",
				    "FlaxRobertaPreLayerNormForTokenClassification",
				    "FlaxRobertaPreLayerNormModel",
				    "FlaxRobertaPreLayerNormPreTrainedModel",
				]


if TYPE_CHECKING:
				from .configuration_roberta_prelayernorm import (
				    ROBERTA_PRELAYERNORM_PRETRAINED_CONFIG_ARCHIVE_MAP,
				    RobertaPreLayerNormConfig,
				    RobertaPreLayerNormOnnxConfig,
				)

				try:
								if not is_torch_available():
												raise OptionalDependencyNotAvailable()
				except OptionalDependencyNotAvailable:
								pass
				else:
								from .modeling_roberta_prelayernorm import (
								    ROBERTA_PRELAYERNORM_PRETRAINED_MODEL_ARCHIVE_LIST,
								    RobertaPreLayerNormForCausalLM,
								    RobertaPreLayerNormForMaskedLM,
								    RobertaPreLayerNormForMultipleChoice,
								    RobertaPreLayerNormForQuestionAnswering,
								    RobertaPreLayerNormForSequenceClassification,
								    RobertaPreLayerNormForTokenClassification,
								    RobertaPreLayerNormModel,
								    RobertaPreLayerNormPreTrainedModel,
								)

				try:
								if not is_tf_available():
												raise OptionalDependencyNotAvailable()
				except OptionalDependencyNotAvailable:
								pass
				else:
								from .modeling_tf_roberta_prelayernorm import (
								    TF_ROBERTA_PRELAYERNORM_PRETRAINED_MODEL_ARCHIVE_LIST,
								    TFRobertaPreLayerNormForCausalLM,
								    TFRobertaPreLayerNormForMaskedLM,
								    TFRobertaPreLayerNormForMultipleChoice,
								    TFRobertaPreLayerNormForQuestionAnswering,
								    TFRobertaPreLayerNormForSequenceClassification,
								    TFRobertaPreLayerNormForTokenClassification,
								    TFRobertaPreLayerNormMainLayer,
								    TFRobertaPreLayerNormModel,
								    TFRobertaPreLayerNormPreTrainedModel,
								)

				try:
								if not is_flax_available():
												raise OptionalDependencyNotAvailable()
				except OptionalDependencyNotAvailable:
								pass
				else:
								from .modeling_flax_roberta_prelayernorm import (
								    FlaxRobertaPreLayerNormForCausalLM,
								    FlaxRobertaPreLayerNormForMaskedLM,
								    FlaxRobertaPreLayerNormForMultipleChoice,
								    FlaxRobertaPreLayerNormForQuestionAnswering,
								    FlaxRobertaPreLayerNormForSequenceClassification,
								    FlaxRobertaPreLayerNormForTokenClassification,
								    FlaxRobertaPreLayerNormModel,
								    FlaxRobertaPreLayerNormPreTrainedModel,
								)

else:
				import sys

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



