

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 					a__						(					unittest.TestCase			):
			"""simple docstring"""







			__lowerCamelCase        =       MODEL_FOR_VIDEO_CLASSIFICATION_MAPPING


			def      UpperCamelCase		(    self      ,      lowercase      ,      lowercase      ,      lowercase       )  ->						List[Any]:
							'''simple docstring'''






							A__        =			hf_hub_download(
							    repo_id="nateraw/video-demo"      ,      filename="archery.mp4"      ,      repo_type="dataset"       )
							A__        =			VideoClassificationPipeline(model=_lowercase      ,      image_processor=_lowercase      ,      top_k=2       )
							A__        =			[
							    example_video_filepath,
							    """https://huggingface.co/datasets/nateraw/video-demo/resolve/main/archery.mp4""",
							]
							return video_classifier, examples


			def      UpperCamelCase		(    self      ,      lowercase      ,      lowercase       )  ->						Dict:
							'''simple docstring'''






							for example in examples:
											A__        =			video_classifier(_lowercase       )

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


			@require_torch
			def      UpperCamelCase		(    self       )  ->						List[str]:
							'''simple docstring'''






							A__        =			"""hf-internal-testing/tiny-random-VideoMAEForVideoClassification"""
							A__        =			VideoMAEFeatureExtractor(
							    size={"shortest_edge": 10}      ,      crop_size={"height": 10, "width": 10}       )
							A__        =			pipeline(
							    "video-classification"      ,      model=_lowercase      ,      feature_extractor=_lowercase      ,      frame_sampling_rate=4       )

							A__        =			hf_hub_download(repo_id="nateraw/video-demo"      ,      filename="archery.mp4"      ,      repo_type="dataset"       )
							A__        =			video_classifier(_lowercase      ,      top_k=2       )
							self.assertEqual(
							    nested_simplify(_lowercase      ,      decimals=4       )      ,      [{"score": 0.5199, "label": "LABEL_0"}, {"score": 0.4801, "label": "LABEL_1"}]      ,      )

							A__        =			video_classifier(
							    [
							        video_file_path,
							        video_file_path,
							    ]      ,      top_k=2      ,      )
							self.assertEqual(
							    nested_simplify(_lowercase      ,      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       )  ->						Any:
							'''simple docstring'''






							pass




import inspect
import re

from transformers.utils import direct_transformers_import


# All paths are set with the intent you should run this script from the root of the repo with the command
# python utils/check_config_docstrings.py
lowerCAmelCase__	   = """src/transformers"""


# This is to make sure the transformers module imported is the one in the repo.
lowerCAmelCase__	   = direct_transformers_import(PATH_TO_TRANSFORMERS)

lowerCAmelCase__	   = transformers.models.auto.configuration_auto.CONFIG_MAPPING

# Regex pattern used to find the checkpoint mentioned in the docstring of `config_class`.
# For example, `[bert-base-uncased](https://huggingface.co/bert-base-uncased)`
lowerCAmelCase__	   = re.compile(R"""\[(.+?)\]\((https://huggingface\.co/.+?)\)""")


lowerCAmelCase__	   = {
    """DecisionTransformerConfig""",
    """EncoderDecoderConfig""",
    """MusicgenConfig""",
    """RagConfig""",
    """SpeechEncoderDecoderConfig""",
    """TimmBackboneConfig""",
    """VisionEncoderDecoderConfig""",
    """VisionTextDualEncoderConfig""",
    """LlamaConfig""",
}



def 					lowerCAmelCase__							(	SCREAMING_SNAKE_CASE_:							Union[str, Any]      )			->      Dict:




				'''simple docstring'''





				A__        =			None

				# source code of `config_class`
				A__        =			inspect.getsource(SCREAMING_SNAKE_CASE_      )
				A__        =			_re_checkpoint.findall(SCREAMING_SNAKE_CASE_      )

				# Each `checkpoint` is a tuple of a checkpoint name and a checkpoint link.
				# For example, `('bert-base-uncased', 'https://huggingface.co/bert-base-uncased')`
				for ckpt_name, ckpt_link in checkpoints:
								# allow the link to end with `/`
								if ckpt_link.endswith("/"      ):
												A__        =			ckpt_link[:-1]

								# verify the checkpoint name corresponds to the checkpoint link
								A__        =			F'https://huggingface.co/{ckpt_name}'
								if ckpt_link == ckpt_link_from_name:
												A__        =			ckpt_name
												break

				return checkpoint



def 					lowerCAmelCase__							(	)			->      List[str]:




				'''simple docstring'''





				A__        =			[]

				for config_class in list(CONFIG_MAPPING.values()      ):
								# Skip deprecated models
								if "models.deprecated" in config_class.__module__:
												continue
								A__        =			get_checkpoint_from_config_class(SCREAMING_SNAKE_CASE_      )

								A__        =			config_class.__name__
								if checkpoint is None and name not in CONFIG_CLASSES_TO_IGNORE_FOR_DOCSTRING_CHECKPOINT_CHECK:
												configs_without_checkpoint.append(SCREAMING_SNAKE_CASE_      )

				if len(SCREAMING_SNAKE_CASE_      ) > 0:
								A__        =			"\n".join(sorted(SCREAMING_SNAKE_CASE_      )      )
								raise ValueError(F'The following configurations don\'t contain any valid checkpoint:\n{message}'      )


if __name__ == "__main__":
	check_config_docstrings_have_checkpoints()

