





from cva import destroyAllWindows, imread, imshow, waitKey



def    __lowercase   (      _SCREAMING_SNAKE_CASE	) ->   int:


      '''simple docstring'''


      SCREAMING_SNAKE_CASE,					SCREAMING_SNAKE_CASE		=						img.shape[0], img.shape[1]

      # converting each pixel's color to its negative
      for i in range(_SCREAMING_SNAKE_CASE	):
            for j in range(_SCREAMING_SNAKE_CASE	):
                  SCREAMING_SNAKE_CASE		=						[2_55, 2_55, 2_55] - img[i][j]

      return img


if __name__ == "__main__":
      # read original image
      SCREAMING_SNAKE_CASE_						   =       imread("""image_data/lena.jpg""", 1)

      # convert to its negative
      SCREAMING_SNAKE_CASE_						   =       convert_to_negative(img)

      # show result image
      imshow("""negative of original image""", img)
      waitKey(0)
      destroyAllWindows()









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

import transformers
import transformers.models.auto
from transformers.models.auto.configuration_auto import CONFIG_MAPPING, AutoConfig
from transformers.models.bert.configuration_bert import BertConfig
from transformers.models.roberta.configuration_roberta import RobertaConfig
from transformers.testing_utils import DUMMY_UNKNOWN_IDENTIFIER, get_tests_dir


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

from test_module.custom_configuration import CustomConfig  # noqa E402


SCREAMING_SNAKE_CASE_						   =       get_tests_dir("""fixtures/dummy-config.json""")

class 		UpperCamelCase__ (      unittest.TestCase   ):



     '''simple docstring'''

     def 				SCREAMING_SNAKE_CASE__  (							self						:    Optional[Any]       )     ->		Optional[Any]:




           '''simple docstring'''


           SCREAMING_SNAKE_CASE		=						0






     def 				SCREAMING_SNAKE_CASE__  (							self						:    Any       )     ->		str:




           '''simple docstring'''


           self.assertIsNotNone(transformers.models.auto.__spec__       )
           self.assertIsNotNone(importlib.util.find_spec("""transformers.models.auto"""       )       )






     def 				SCREAMING_SNAKE_CASE__  (							self						:    Union[str, Any]       )     ->		List[Any]:




           '''simple docstring'''


           SCREAMING_SNAKE_CASE		=						AutoConfig.from_pretrained("""bert-base-uncased"""       )
           self.assertIsInstance(lowerCamelCase__						,lowerCamelCase__       )






     def 				SCREAMING_SNAKE_CASE__  (							self						:    int       )     ->		Optional[Any]:




           '''simple docstring'''


           SCREAMING_SNAKE_CASE		=						AutoConfig.from_pretrained(lowerCamelCase__       )
           self.assertIsInstance(lowerCamelCase__						,lowerCamelCase__       )






     def 				SCREAMING_SNAKE_CASE__  (							self						:    Union[str, Any]       )     ->		List[Any]:




           '''simple docstring'''


           SCREAMING_SNAKE_CASE		=						AutoConfig.from_pretrained(lowerCamelCase__       )
           self.assertIsInstance(lowerCamelCase__						,lowerCamelCase__       )






     def 				SCREAMING_SNAKE_CASE__  (							self						:    Tuple       )     ->		Optional[int]:




           '''simple docstring'''


           SCREAMING_SNAKE_CASE		=						AutoConfig.for_model("""roberta"""       )
           self.assertIsInstance(lowerCamelCase__						,lowerCamelCase__       )






     def 				SCREAMING_SNAKE_CASE__  (							self						:    int       )     ->		int:




           '''simple docstring'''


           with tempfile.TemporaryDirectory() as tmp_dir:
                 # This model name contains bert and roberta, but roberta ends up being picked.
                 SCREAMING_SNAKE_CASE		=						os.path.join(lowerCamelCase__						,"""fake-roberta"""       )
                 os.makedirs(lowerCamelCase__						,exist_ok=lowerCamelCase__       )
                 with open(os.path.join(lowerCamelCase__						,"""config.json"""       )						,"""w"""       ) as f:
                       f.write(json.dumps({}       )       )
                 SCREAMING_SNAKE_CASE		=						AutoConfig.from_pretrained(lowerCamelCase__       )
                 self.assertEqual(type(lowerCamelCase__       )						,lowerCamelCase__       )






     def 				SCREAMING_SNAKE_CASE__  (							self						:    Dict       )     ->		str:




           '''simple docstring'''


           try:
                 AutoConfig.register("""custom"""						,lowerCamelCase__       )
                 # Wrong model type will raise an error
                 with self.assertRaises(lowerCamelCase__       ):
                       AutoConfig.register("""model"""						,lowerCamelCase__       )
                 # Trying to register something existing in the Transformers library will raise an error
                 with self.assertRaises(lowerCamelCase__       ):
                       AutoConfig.register("""bert"""						,lowerCamelCase__       )

                 # Now that the config is registered, it can be used as any other config with the auto-API
                 SCREAMING_SNAKE_CASE		=						CustomConfig()
                 with tempfile.TemporaryDirectory() as tmp_dir:
                       config.save_pretrained(lowerCamelCase__       )
                       SCREAMING_SNAKE_CASE		=						AutoConfig.from_pretrained(lowerCamelCase__       )
                       self.assertIsInstance(lowerCamelCase__						,lowerCamelCase__       )

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






     def 				SCREAMING_SNAKE_CASE__  (							self						:    str       )     ->		Dict:




           '''simple docstring'''


           with self.assertRaisesRegex(
               lowerCamelCase__						,"""bert-base is not a local folder and is not a valid model identifier"""       ):
                 SCREAMING_SNAKE_CASE		=						AutoConfig.from_pretrained("""bert-base"""       )






     def 				SCREAMING_SNAKE_CASE__  (							self						:    Dict       )     ->		str:




           '''simple docstring'''


           with self.assertRaisesRegex(
               lowerCamelCase__						,R"""aaaaaa is not a valid git identifier \(branch name, tag name or commit id\)"""       ):
                 SCREAMING_SNAKE_CASE		=						AutoConfig.from_pretrained(lowerCamelCase__						,revision="""aaaaaa"""       )






     def 				SCREAMING_SNAKE_CASE__  (							self						:    Tuple       )     ->		List[Any]:




           '''simple docstring'''


           with self.assertRaisesRegex(
               lowerCamelCase__						,"""hf-internal-testing/no-config-test-repo does not appear to have a file named config.json."""						,):
                 SCREAMING_SNAKE_CASE		=						AutoConfig.from_pretrained("""hf-internal-testing/no-config-test-repo"""       )






     def 				SCREAMING_SNAKE_CASE__  (							self						:    Optional[int]       )     ->		Union[str, Any]:




           '''simple docstring'''


           with self.assertRaises(lowerCamelCase__       ):
                 SCREAMING_SNAKE_CASE		=						AutoConfig.from_pretrained("""hf-internal-testing/test_dynamic_model"""       )
           # If remote code is disabled, we can't load this config.
           with self.assertRaises(lowerCamelCase__       ):
                 SCREAMING_SNAKE_CASE		=						AutoConfig.from_pretrained("""hf-internal-testing/test_dynamic_model"""						,trust_remote_code=lowerCamelCase__       )

           SCREAMING_SNAKE_CASE		=						AutoConfig.from_pretrained("""hf-internal-testing/test_dynamic_model"""						,trust_remote_code=lowerCamelCase__       )
           self.assertEqual(config.__class__.__name__						,"""NewModelConfig"""       )

           # Test config can be reloaded.
           with tempfile.TemporaryDirectory() as tmp_dir:
                 config.save_pretrained(lowerCamelCase__       )
                 SCREAMING_SNAKE_CASE		=						AutoConfig.from_pretrained(lowerCamelCase__						,trust_remote_code=lowerCamelCase__       )
           self.assertEqual(reloaded_config.__class__.__name__						,"""NewModelConfig"""       )






     def 				SCREAMING_SNAKE_CASE__  (							self						:    Dict       )     ->		Union[str, Any]:




           '''simple docstring'''


           class 		UpperCamelCase__ (      lowerCAmelCase_   ):



                '''simple docstring'''

                __snake_case    :	Union[str, Any]			=			"new-model"

           try:
                 AutoConfig.register("""new-model"""						,lowerCamelCase__       )
                 # If remote code is not set, the default is to use local
                 SCREAMING_SNAKE_CASE		=						AutoConfig.from_pretrained("""hf-internal-testing/test_dynamic_model"""       )
                 self.assertEqual(config.__class__.__name__						,"""NewModelConfigLocal"""       )

                 # If remote code is disabled, we load the local one.
                 SCREAMING_SNAKE_CASE		=						AutoConfig.from_pretrained("""hf-internal-testing/test_dynamic_model"""						,trust_remote_code=lowerCamelCase__       )
                 self.assertEqual(config.__class__.__name__						,"""NewModelConfigLocal"""       )

                 # If remote is enabled, we load from the Hub
                 SCREAMING_SNAKE_CASE		=						AutoConfig.from_pretrained("""hf-internal-testing/test_dynamic_model"""						,trust_remote_code=lowerCamelCase__       )
                 self.assertEqual(config.__class__.__name__						,"""NewModelConfig"""       )

           finally:
                 if "new-model" in CONFIG_MAPPING._extra_content:
                       del CONFIG_MAPPING._extra_content["new-model"]


