






"""simple docstring"""





import json
import sys
import tempfile
import unittest
from pathlib import Path

import transformers
from transformers import (
    CONFIG_MAPPING,
    IMAGE_PROCESSOR_MAPPING,
    AutoConfig,
    AutoImageProcessor,
    CLIPConfig,
    CLIPImageProcessor,
)
from transformers.testing_utils import DUMMY_UNKNOWN_IDENTIFIER


sys.path.append(str(Path(__file__).parent.parent.parent.parent / """utils"""))

from test_module.custom_configuration import CustomConfig  # noqa E402
from test_module.custom_image_processing import CustomImageProcessor  # noqa E402


class      _lowercase (     unittest.TestCase						):


      def _UpperCamelCase						(    self				:	Union[str, Any]						):





            """simple docstring"""







            __snake_case      :    List[Any]  			=0


      def _UpperCamelCase						(    self				:	Union[str, Any]						):





            """simple docstring"""







            __snake_case      :    Tuple  			=AutoImageProcessor.from_pretrained('''openai/clip-vit-base-patch32'''						)
            self.assertIsInstance(a							,   a						)


      def _UpperCamelCase						(    self				:	Union[str, Any]						):





            """simple docstring"""







            with tempfile.TemporaryDirectory() as tmpdirname:
                  __snake_case      :    str  			=Path(a						) / '''preprocessor_config.json'''
                  __snake_case      :    Tuple  			=Path(a						) / '''config.json'''
                  json.dump(
                      {'''image_processor_type''': '''CLIPImageProcessor''', '''processor_class''': '''CLIPProcessor'''}							,   open(a							,   '''w'''						)							,   )
                  json.dump({'''model_type''': '''clip'''}							,   open(a							,   '''w'''						)						)

                  __snake_case      :    Dict  			=AutoImageProcessor.from_pretrained(a						)
                  self.assertIsInstance(a							,   a						)


      def _UpperCamelCase						(    self				:	List[str]						):





            """simple docstring"""







            with tempfile.TemporaryDirectory() as tmpdirname:
                  __snake_case      :    Optional[int]  			=Path(a						) / '''preprocessor_config.json'''
                  __snake_case      :    str  			=Path(a						) / '''config.json'''
                  json.dump(
                      {'''feature_extractor_type''': '''CLIPFeatureExtractor''', '''processor_class''': '''CLIPProcessor'''}							,   open(a							,   '''w'''						)							,   )
                  json.dump({'''model_type''': '''clip'''}							,   open(a							,   '''w'''						)						)

                  __snake_case      :    Any  			=AutoImageProcessor.from_pretrained(a						)
                  self.assertIsInstance(a							,   a						)


      def _UpperCamelCase						(    self				:	List[Any]						):





            """simple docstring"""







            with tempfile.TemporaryDirectory() as tmpdirname:
                  __snake_case      :    Any  			=CLIPConfig()

                  # Create a dummy config file with image_proceesor_type
                  __snake_case      :    Dict  			=Path(a						) / '''preprocessor_config.json'''
                  __snake_case      :    Tuple  			=Path(a						) / '''config.json'''
                  json.dump(
                      {'''image_processor_type''': '''CLIPImageProcessor''', '''processor_class''': '''CLIPProcessor'''}							,   open(a							,   '''w'''						)							,   )
                  json.dump({'''model_type''': '''clip'''}							,   open(a							,   '''w'''						)						)

                  # remove image_processor_type to make sure config.json alone is enough to load image processor locally
                  __snake_case      :    List[Any]  			=AutoImageProcessor.from_pretrained(a						).to_dict()

                  config_dict.pop('''image_processor_type'''						)
                  __snake_case      :    List[Any]  			=CLIPImageProcessor(**a						)

                  # save in new folder
                  model_config.save_pretrained(a						)
                  config.save_pretrained(a						)

                  __snake_case      :    List[str]  			=AutoImageProcessor.from_pretrained(a						)

                  # make sure private variable is not incorrectly saved
                  __snake_case      :    List[str]  			=json.loads(config.to_json_string()						)
                  self.assertTrue('''_processor_class''' not in dict_as_saved						)

            self.assertIsInstance(a							,   a						)


      def _UpperCamelCase						(    self				:	Dict						):





            """simple docstring"""







            with tempfile.TemporaryDirectory() as tmpdirname:
                  __snake_case      :    Tuple  			=Path(a						) / '''preprocessor_config.json'''
                  json.dump(
                      {'''image_processor_type''': '''CLIPImageProcessor''', '''processor_class''': '''CLIPProcessor'''}							,   open(a							,   '''w'''						)							,   )

                  __snake_case      :    Optional[Any]  			=AutoImageProcessor.from_pretrained(a						)
                  self.assertIsInstance(a							,   a						)


      def _UpperCamelCase						(    self				:	Tuple						):





            """simple docstring"""







            with self.assertRaisesRegex(
                a							,   '''clip-base is not a local folder and is not a valid model identifier'''						):
                  __snake_case      :    int  			=AutoImageProcessor.from_pretrained('''clip-base'''						)


      def _UpperCamelCase						(    self				:	Tuple						):





            """simple docstring"""







            with self.assertRaisesRegex(
                a							,   R'''aaaaaa is not a valid git identifier \(branch name, tag name or commit id\)'''						):
                  __snake_case      :    Dict  			=AutoImageProcessor.from_pretrained(a							,   revision='''aaaaaa'''						)


      def _UpperCamelCase						(    self				:	Optional[int]						):





            """simple docstring"""







            with self.assertRaisesRegex(
                a							,   '''hf-internal-testing/config-no-model does not appear to have a file named preprocessor_config.json.'''							,   ):
                  __snake_case      :    Tuple  			=AutoImageProcessor.from_pretrained('''hf-internal-testing/config-no-model'''						)


      def _UpperCamelCase						(    self				:	List[Any]						):





            """simple docstring"""







            with self.assertRaises(a						):
                  __snake_case      :    Tuple  			=AutoImageProcessor.from_pretrained('''hf-internal-testing/test_dynamic_image_processor'''						)
            # If remote code is disabled, we can't load this config.
            with self.assertRaises(a						):
                  __snake_case      :    Optional[Any]  			=AutoImageProcessor.from_pretrained(
                      '''hf-internal-testing/test_dynamic_image_processor'''							,   trust_remote_code=a						)

            __snake_case      :    Optional[Any]  			=AutoImageProcessor.from_pretrained(
                '''hf-internal-testing/test_dynamic_image_processor'''							,   trust_remote_code=a						)
            self.assertEqual(image_processor.__class__.__name__							,   '''NewImageProcessor'''						)

            # Test image processor can be reloaded.
            with tempfile.TemporaryDirectory() as tmp_dir:
                  image_processor.save_pretrained(a						)
                  __snake_case      :    Optional[Any]  			=AutoImageProcessor.from_pretrained(a							,   trust_remote_code=a						)
            self.assertEqual(reloaded_image_processor.__class__.__name__							,   '''NewImageProcessor'''						)


      def _UpperCamelCase						(    self				:	Any						):





            """simple docstring"""







            try:
                  AutoConfig.register('''custom'''							,   a						)
                  AutoImageProcessor.register(a							,   a						)
                  # Trying to register something existing in the Transformers library will raise an error
                  with self.assertRaises(a						):
                        AutoImageProcessor.register(a							,   a						)

                  with tempfile.TemporaryDirectory() as tmpdirname:
                        __snake_case      :    Optional[Any]  			=Path(a						) / '''preprocessor_config.json'''
                        __snake_case      :    Union[str, Any]  			=Path(a						) / '''config.json'''
                        json.dump(
                            {'''feature_extractor_type''': '''CLIPFeatureExtractor''', '''processor_class''': '''CLIPProcessor'''}							,   open(a							,   '''w'''						)							,   )
                        json.dump({'''model_type''': '''clip'''}							,   open(a							,   '''w'''						)						)

                        __snake_case      :    List[str]  			=CustomImageProcessor.from_pretrained(a						)

                  # Now that the config is registered, it can be used as any other config with the auto-API
                  with tempfile.TemporaryDirectory() as tmp_dir:
                        image_processor.save_pretrained(a						)
                        __snake_case      :    str  			=AutoImageProcessor.from_pretrained(a						)
                        self.assertIsInstance(a							,   a						)

            finally:
                  if "custom" in CONFIG_MAPPING._extra_content:
                        del CONFIG_MAPPING._extra_content["custom"]
                  if CustomConfig in IMAGE_PROCESSOR_MAPPING._extra_content:
                        del IMAGE_PROCESSOR_MAPPING._extra_content[CustomConfig]







      def _UpperCamelCase						(    self				:	int						):





            """simple docstring"""







            class      _lowercase (     lowerCAmelCase						):
                  _a   :     Union[str, Any]								=   True

            try:
                  AutoConfig.register('''custom'''							,   a						)
                  AutoImageProcessor.register(a							,   a						)
                  # If remote code is not set, the default is to use local
                  __snake_case      :    Any  			=AutoImageProcessor.from_pretrained('''hf-internal-testing/test_dynamic_image_processor'''						)
                  self.assertEqual(image_processor.__class__.__name__							,   '''NewImageProcessor'''						)
                  self.assertTrue(image_processor.is_local						)

                  # If remote code is disabled, we load the local one.
                  __snake_case      :    Tuple  			=AutoImageProcessor.from_pretrained(
                      '''hf-internal-testing/test_dynamic_image_processor'''							,   trust_remote_code=a						)
                  self.assertEqual(image_processor.__class__.__name__							,   '''NewImageProcessor'''						)
                  self.assertTrue(image_processor.is_local						)

                  # If remote is enabled, we load from the Hub
                  __snake_case      :    Tuple  			=AutoImageProcessor.from_pretrained(
                      '''hf-internal-testing/test_dynamic_image_processor'''							,   trust_remote_code=a						)
                  self.assertEqual(image_processor.__class__.__name__							,   '''NewImageProcessor'''						)
                  self.assertTrue(not hasattr(a							,   '''is_local'''						)						)

            finally:
                  if "custom" in CONFIG_MAPPING._extra_content:
                        del CONFIG_MAPPING._extra_content["custom"]
                  if CustomConfig in IMAGE_PROCESSOR_MAPPING._extra_content:
                        del IMAGE_PROCESSOR_MAPPING._extra_content[CustomConfig]










"""simple docstring"""





def     __lowercase					(    a :				int       ,		a :				int )					->					int:
      return x if y == 0 else greatest_common_divisor(a       ,		x % y )



def     __lowercase					(    a :				int       ,		a :				int )					->					int:
      return (x * y) // greatest_common_divisor(a       ,		a )



def     __lowercase					(    a :				int = 20 )					->					int:
      __snake_case      :    Optional[Any]  			=1
      for i in range(1       ,		n + 1 ):
            __snake_case      :    Optional[int]  			=lcm(a       ,		a )
      return g


if __name__ == "__main__":
    print(F'''{solution() = }''')


