




import argparse
import os
import re

import packaging.version


UpperCamelCase								=					'examples/'
UpperCamelCase								=					{
    'examples': (re.compile(R'^check_min_version\("[^"]+"\)\s*$', re.MULTILINE), 'check_min_version("VERSION")\n'),
    'init': (re.compile(R'^__version__\s+=\s+"([^"]+)"\s*$', re.MULTILINE), '__version__ = "VERSION"\n'),
    'setup': (re.compile(R'^(\s*)version\s*=\s*"[^"]+",', re.MULTILINE), R'\1version="VERSION",'),
    'doc': (re.compile(R'^(\s*)release\s*=\s*"[^"]+"$', re.MULTILINE), 'release = "VERSION"\n'),
}
UpperCamelCase								=					{
    'init': 'src/diffusers/__init__.py',
    'setup': 'setup.py',
}
UpperCamelCase								=					'README.md'



def 							_A       (						lowerCAmelCase_					: Optional[int]       ,    lowerCAmelCase_					: Dict       ,    lowerCAmelCase_					: Any      ):
     """simple docstring"""

     with open(lowerCAmelCase_       ,    "r"       ,    encoding="utf-8"       ,    newline="\n"      ) as f:
          lowerCAmelCase__          =			f.read()
     lowerCAmelCase__     ,		lowerCAmelCase__          =			REPLACE_PATTERNS[pattern]
     lowerCAmelCase__          =			replace.replace("VERSION"       ,    lowerCAmelCase_      )
     lowerCAmelCase__          =			re_pattern.sub(lowerCAmelCase_       ,    lowerCAmelCase_      )
     with open(lowerCAmelCase_       ,    "w"       ,    encoding="utf-8"       ,    newline="\n"      ) as f:
          f.write(lowerCAmelCase_      )



def 							_A       (						lowerCAmelCase_					: Any      ):
     """simple docstring"""

     for folder, directories, fnames in os.walk(lowerCAmelCase_      ):
          # Removing some of the folders with non-actively maintained examples from the walk
          if "research_projects" in directories:
               directories.remove("research_projects"      )
          if "legacy" in directories:
               directories.remove("legacy"      )
          for fname in fnames:
               if fname.endswith(".py"      ):
                    update_version_in_file(os.path.join(lowerCAmelCase_       ,    lowerCAmelCase_      )       ,    lowerCAmelCase_       ,    pattern="examples"      )



def 							_A       (						lowerCAmelCase_					: Any       ,    lowerCAmelCase_					: List[Any]=False      ):
     """simple docstring"""

     for pattern, fname in REPLACE_FILES.items():
          update_version_in_file(lowerCAmelCase_       ,    lowerCAmelCase_       ,    lowerCAmelCase_      )
     if not patch:
          update_version_in_examples(lowerCAmelCase_      )



def 							_A       (						):
     """simple docstring"""

     lowerCAmelCase__          =			"🤗 Transformers currently provides the following architectures"
     lowerCAmelCase__          =			"1. Want to contribute a new model?"
     with open(lowerCAmelCase_       ,    "r"       ,    encoding="utf-8"       ,    newline="\n"      ) as f:
          lowerCAmelCase__          =			f.readlines()

     # Find the start of the list.
     lowerCAmelCase__          =			0
     while not lines[start_index].startswith(_start_prompt      ):
          start_index += 1
     start_index += 1

     lowerCAmelCase__          =			start_index
     # Update the lines in the model list.
     while not lines[index].startswith(_end_prompt      ):
          if lines[index].startswith("1."      ):
               lowerCAmelCase__          =			lines[index].replace(
                   "https://huggingface.co/docs/diffusers/main/model_doc"       ,    "https://huggingface.co/docs/diffusers/model_doc"       ,    )
          index += 1

     with open(lowerCAmelCase_       ,    "w"       ,    encoding="utf-8"       ,    newline="\n"      ) as f:
          f.writelines(lowerCAmelCase_      )



def 							_A       (						):
     """simple docstring"""

     with open(REPLACE_FILES["init"]       ,    "r"      ) as f:
          lowerCAmelCase__          =			f.read()
     lowerCAmelCase__          =			REPLACE_PATTERNS["init"][0].search(lowerCAmelCase_      ).groups()[0]
     return packaging.version.parse(lowerCAmelCase_      )



def 							_A       (						lowerCAmelCase_					: Tuple=False      ):
     """simple docstring"""

     lowerCAmelCase__          =			get_version()
     if patch and default_version.is_devrelease:
          raise ValueError("Can't create a patch version from the dev branch, checkout a released version!"      )
     if default_version.is_devrelease:
          lowerCAmelCase__          =			default_version.base_version
     elif patch:
          lowerCAmelCase__          =			F'{default_version.major}.{default_version.minor}.{default_version.micro + 1}'
     else:
          lowerCAmelCase__          =			F'{default_version.major}.{default_version.minor + 1}.0'

     # Now let's ask nicely if that's the right one.
     lowerCAmelCase__          =			input(F'Which version are you releasing? [{default_version}]'      )
     if len(lowerCAmelCase_      ) == 0:
          lowerCAmelCase__          =			default_version

     print(F'Updating version to {version}.'      )
     global_version_update(lowerCAmelCase_       ,    patch=lowerCAmelCase_      )



def 							_A       (						):
     """simple docstring"""

     lowerCAmelCase__          =			get_version()
     lowerCAmelCase__          =			F'{current_version.major}.{current_version.minor + 1}.0.dev0'
     lowerCAmelCase__          =			current_version.base_version

     # Check with the user we got that right.
     lowerCAmelCase__          =			input(F'Which version are we developing now? [{dev_version}]'      )
     if len(lowerCAmelCase_      ) == 0:
          lowerCAmelCase__          =			dev_version

     print(F'Updating version to {version}.'      )
     global_version_update(lowerCAmelCase_      )


#    print("Cleaning main README, don't forget to run `make fix-copies`.")
#    clean_main_ref_in_model_list()


if __name__ == "__main__":
     UpperCamelCase								=					argparse.ArgumentParser()
     parser.add_argument('--post_release', action='store_true', help='Whether this is pre or post release.')
     parser.add_argument('--patch', action='store_true', help='Whether or not this is a patch release.')
     UpperCamelCase								=					parser.parse_args()
     if not args.post_release:
          pre_release_work(patch=args.patch)
     elif args.patch:
          print('Nothing to do after a patch :-)')
     else:
          post_release_work()






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

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


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

         lowerCAmelCase__          =			hf_hub_download(repo_id="nateraw/video-demo"       ,     filename="archery.mp4"       ,     repo_type="dataset"       )
         lowerCAmelCase__          =			video_classifier(SCREAMING_SNAKE_CASE__       ,     top_k=2       )
         self.assertEqual(
             nested_simplify(SCREAMING_SNAKE_CASE__       ,     decimals=4       )       ,     [{"score": 0.5_199, "label": "LABEL_0"}, {"score": 0.4_801, "label": "LABEL_1"}]       ,     )

         lowerCAmelCase__          =			video_classifier(
             [
                 video_file_path,
                 video_file_path,
             ]       ,     top_k=2       ,     )
         self.assertEqual(
             nested_simplify(SCREAMING_SNAKE_CASE__       ,     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        a				(	self					:					Optional[Any]       )				->	Optional[int]:
         pass
