


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

import transformers
from transformers import (
    CONFIG_MAPPING,
    FEATURE_EXTRACTOR_MAPPING,
    AutoConfig,
    AutoFeatureExtractor,
    WavaVecaConfig,
    WavaVecaFeatureExtractor,
)
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
from test_module.custom_feature_extraction import CustomFeatureExtractor  # noqa E402


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







class lowerCAmelCase_						(			unittest.TestCase	):

 '''simple docstring'''

 def 						UpperCamelCase__					(     self ):
       snake_case_	=				0



 def 						UpperCamelCase__					(     self ):
       snake_case_	=				AutoFeatureExtractor.from_pretrained('''facebook/wav2vec2-base-960h''' )
       self.assertIsInstance(_UpperCAmelCase		,				_UpperCAmelCase )



 def 						UpperCamelCase__					(     self ):
       snake_case_	=				AutoFeatureExtractor.from_pretrained(_UpperCAmelCase )
       self.assertIsInstance(_UpperCAmelCase		,				_UpperCAmelCase )



 def 						UpperCamelCase__					(     self ):
       with tempfile.TemporaryDirectory() as tmpdirname:
             snake_case_	=				WavaVecaConfig()

             # remove feature_extractor_type to make sure config.json alone is enough to load feature processor locally
             snake_case_	=				AutoFeatureExtractor.from_pretrained(_UpperCAmelCase ).to_dict()

             config_dict.pop('''feature_extractor_type''' )
             snake_case_	=				WavaVecaFeatureExtractor(**_UpperCAmelCase )

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

             snake_case_	=				AutoFeatureExtractor.from_pretrained(_UpperCAmelCase )

             # make sure private variable is not incorrectly saved
             snake_case_	=				json.loads(config.to_json_string() )
             self.assertTrue('''_processor_class''' not in dict_as_saved )

       self.assertIsInstance(_UpperCAmelCase		,				_UpperCAmelCase )



 def 						UpperCamelCase__					(     self ):
       snake_case_	=				AutoFeatureExtractor.from_pretrained(_UpperCAmelCase )
       self.assertIsInstance(_UpperCAmelCase		,				_UpperCAmelCase )



 def 						UpperCamelCase__					(     self ):
       with self.assertRaisesRegex(
           _UpperCAmelCase		,				'''bert-base is not a local folder and is not a valid model identifier''' ):
             snake_case_	=				AutoFeatureExtractor.from_pretrained('''bert-base''' )



 def 						UpperCamelCase__					(     self ):
       with self.assertRaisesRegex(
           _UpperCAmelCase		,				R'''aaaaaa is not a valid git identifier \(branch name, tag name or commit id\)''' ):
             snake_case_	=				AutoFeatureExtractor.from_pretrained(_UpperCAmelCase		,				revision='''aaaaaa''' )



 def 						UpperCamelCase__					(     self ):
       with self.assertRaisesRegex(
           _UpperCAmelCase		,				'''hf-internal-testing/config-no-model does not appear to have a file named preprocessor_config.json.'''		,				):
             snake_case_	=				AutoFeatureExtractor.from_pretrained('''hf-internal-testing/config-no-model''' )



 def 						UpperCamelCase__					(     self ):
       # If remote code is not set, we will time out when asking whether to load the model.
       with self.assertRaises(_UpperCAmelCase ):
             snake_case_	=				AutoFeatureExtractor.from_pretrained(
                 '''hf-internal-testing/test_dynamic_feature_extractor''' )
       # If remote code is disabled, we can't load this config.
       with self.assertRaises(_UpperCAmelCase ):
             snake_case_	=				AutoFeatureExtractor.from_pretrained(
                 '''hf-internal-testing/test_dynamic_feature_extractor'''		,				trust_remote_code=_UpperCAmelCase )

       snake_case_	=				AutoFeatureExtractor.from_pretrained(
           '''hf-internal-testing/test_dynamic_feature_extractor'''		,				trust_remote_code=_UpperCAmelCase )
       self.assertEqual(feature_extractor.__class__.__name__		,				'''NewFeatureExtractor''' )

       # Test feature extractor can be reloaded.
       with tempfile.TemporaryDirectory() as tmp_dir:
             feature_extractor.save_pretrained(_UpperCAmelCase )
             snake_case_	=				AutoFeatureExtractor.from_pretrained(_UpperCAmelCase		,				trust_remote_code=_UpperCAmelCase )
       self.assertEqual(reloaded_feature_extractor.__class__.__name__		,				'''NewFeatureExtractor''' )



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

             # Now that the config is registered, it can be used as any other config with the auto-API
             snake_case_	=				CustomFeatureExtractor.from_pretrained(_UpperCAmelCase )
             with tempfile.TemporaryDirectory() as tmp_dir:
                   feature_extractor.save_pretrained(_UpperCAmelCase )
                   snake_case_	=				AutoFeatureExtractor.from_pretrained(_UpperCAmelCase )
                   self.assertIsInstance(_UpperCAmelCase		,				_UpperCAmelCase )

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





 def 						UpperCamelCase__					(     self ):







       class lowerCAmelCase_						(			lowerCamelCase__	):

        '''simple docstring'''

        __snake_case												=  True

       try:
             AutoConfig.register('''custom'''		,				_UpperCAmelCase )
             AutoFeatureExtractor.register(_UpperCAmelCase		,				_UpperCAmelCase )
             # If remote code is not set, the default is to use local
             snake_case_	=				AutoFeatureExtractor.from_pretrained(
                 '''hf-internal-testing/test_dynamic_feature_extractor''' )
             self.assertEqual(feature_extractor.__class__.__name__		,				'''NewFeatureExtractor''' )
             self.assertTrue(feature_extractor.is_local )

             # If remote code is disabled, we load the local one.
             snake_case_	=				AutoFeatureExtractor.from_pretrained(
                 '''hf-internal-testing/test_dynamic_feature_extractor'''		,				trust_remote_code=_UpperCAmelCase )
             self.assertEqual(feature_extractor.__class__.__name__		,				'''NewFeatureExtractor''' )
             self.assertTrue(feature_extractor.is_local )

             # If remote is enabled, we load from the Hub
             snake_case_	=				AutoFeatureExtractor.from_pretrained(
                 '''hf-internal-testing/test_dynamic_feature_extractor'''		,				trust_remote_code=_UpperCAmelCase )
             self.assertEqual(feature_extractor.__class__.__name__		,				'''NewFeatureExtractor''' )
             self.assertTrue(not hasattr(_UpperCAmelCase		,				'''is_local''' ) )

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



# Function to print upper half of diamond (pyramid)






def 	__lowerCAmelCase   (SCREAMING_SNAKE_CASE )->  Dict:




      """simple docstring"""

      for i in range(0 , SCREAMING_SNAKE_CASE ):
            for _ in range(0 , n - i - 1 ):  # printing spaces
                  print(''' ''' , end='''''' )
            for _ in range(0 , i + 1 ):  # printing stars
                  print('''* ''' , end='''''' )
            print()






def 	__lowerCAmelCase   (SCREAMING_SNAKE_CASE )->  Dict:




      """simple docstring"""

      for i in range(SCREAMING_SNAKE_CASE , 0 , -1 ):
            for _ in range(SCREAMING_SNAKE_CASE , 0 , -1 ):  # printing stars
                  print('''* ''' , end='''''' )
            print()
            for _ in range(n - i + 1 , 0 , -1 ):  # printing spaces
                  print(''' ''' , end='''''' )






def 	__lowerCAmelCase   (SCREAMING_SNAKE_CASE )->  Any:




      """simple docstring"""

      if n <= 0:
            print('''       ...       ....        nothing printing :(''' )
            return
      floyd(SCREAMING_SNAKE_CASE )  # upper half
      reverse_floyd(SCREAMING_SNAKE_CASE )  # lower half


if __name__ == "__main__":
   print(r"""| /\ | |- |  |-  |--| |\  /| |-""")
   print(r"""|/  \| |- |_ |_  |__| | \/ | |_""")
   UpperCAmelCase      =   1
   while K:
      UpperCAmelCase      =   int(input("""enter the number and , and see the magic : """))
      print()
      pretty_print(user_number)
      UpperCAmelCase      =   int(input("""press 0 to exit... and 1 to continue..."""))

   print("""Good Bye...""")