



import subprocess
from argparse import ArgumentParser
from typing import List, Union

from huggingface_hub.hf_api import HfFolder, create_repo, whoami
from requests.exceptions import HTTPError

from . import BaseTransformersCLICommand

class    _SCREAMING_SNAKE_CASE						(UpperCamelCase			):





     @staticmethod
     def 						__snake_case     (							UpperCamelCase			:				ArgumentParser					)->str:
      __SCREAMING_SNAKE_CASE							:     int							=						parser.add_parser("login"  ,	help="Log in using the same credentials as on huggingface.co"					)
      login_parser.set_defaults(func=lambda UpperCamelCase					: LoginCommand(UpperCamelCase					)					)
      __SCREAMING_SNAKE_CASE							:     str							=						parser.add_parser("whoami"  ,	help="Find out which huggingface.co account you are logged in as."					)
      whoami_parser.set_defaults(func=lambda UpperCamelCase					: WhoamiCommand(UpperCamelCase					)					)
      __SCREAMING_SNAKE_CASE							:     int							=						parser.add_parser("logout"  ,	help="Log out"					)
      logout_parser.set_defaults(func=lambda UpperCamelCase					: LogoutCommand(UpperCamelCase					)					)

      # new system: git-based repo system
      __SCREAMING_SNAKE_CASE							:     Any							=						parser.add_parser(
          "repo"  ,	help="Deprecated: use `huggingface-cli` instead. Commands to interact with your huggingface.co repos."  ,	)
      __SCREAMING_SNAKE_CASE							:     Optional[int]							=						repo_parser.add_subparsers(
          help="Deprecated: use `huggingface-cli` instead. huggingface.co repos related commands"					)
      __SCREAMING_SNAKE_CASE							:     Any							=						repo_subparsers.add_parser(
          "create"  ,	help="Deprecated: use `huggingface-cli` instead. Create a new repo on huggingface.co"					)
      repo_create_parser.add_argument(
          "name"  ,	type=UpperCamelCase  ,	help="Name for your model's repo. Will be namespaced under your username to build the model id."  ,	)
      repo_create_parser.add_argument("--organization"  ,	type=UpperCamelCase  ,	help="Optional: organization namespace."					)
      repo_create_parser.add_argument("-y"  ,	"--yes"  ,	action="store_true"  ,	help="Optional: answer Yes to the prompt"					)
      repo_create_parser.set_defaults(func=lambda UpperCamelCase					: RepoCreateCommand(UpperCamelCase					)					)






class    _SCREAMING_SNAKE_CASE						:
     lowerCAmelCase       =      """\u001b[1m"""
     lowerCAmelCase       =      """\u001b[31m"""
     lowerCAmelCase       =      """\u001b[90m"""
     lowerCAmelCase       =      """\u001b[0m"""





     @classmethod
     def 						__snake_case     (							cls			:				List[str]  ,	UpperCamelCase			:				str					)->Dict:
      return F"""{cls._bold}{s}{cls._reset}"""





     @classmethod
     def 						__snake_case     (							cls			:				Union[str, Any]  ,	UpperCamelCase			:				Union[str, Any]					)->List[str]:
      return F"""{cls._bold}{cls._red}{s}{cls._reset}"""






     @classmethod
     def 						__snake_case     (							cls			:				Optional[Any]  ,	UpperCamelCase			:				str					)->Optional[int]:
      return F"""{cls._gray}{s}{cls._reset}"""






def 						_lowerCAmelCase    (					__lowerCamelCase :  List[List[Union[str, int]]]		,						__lowerCamelCase :  List[str]  ):



 """simple docstring"""





 __SCREAMING_SNAKE_CASE							:     List[Any]							=						[max(len(str(__lowerCamelCase  )  ) for x in col  ) for col in zip(*__lowerCamelCase		,						__lowerCamelCase  )]
 __SCREAMING_SNAKE_CASE							:     int							=						("{{:{}}} " * len(__lowerCamelCase  )).format(*__lowerCamelCase  )
 __SCREAMING_SNAKE_CASE							:     Tuple							=						[]
 lines.append(row_format.format(*__lowerCamelCase  )  )
 lines.append(row_format.format(*["-" * w for w in col_widths]  )  )
 for row in rows:
  lines.append(row_format.format(*__lowerCamelCase  )  )
 return "\n".join(__lowerCamelCase  )

class    _SCREAMING_SNAKE_CASE						:





     def __init__(							self			:				int  ,	UpperCamelCase			:				int					)->Tuple:
      __SCREAMING_SNAKE_CASE							:     Union[str, Any]							=						args






class    _SCREAMING_SNAKE_CASE						(UpperCamelCase			):





     def 						__snake_case     (							self			:				Optional[int]					)->Optional[Any]:
      print(
          ANSI.red(
              "ERROR! `huggingface-cli login` uses an outdated login mechanism "
              "that is not compatible with the Hugging Face Hub backend anymore. "
              "Please use `huggingface-cli login instead."					)					)






class    _SCREAMING_SNAKE_CASE						(UpperCamelCase			):





     def 						__snake_case     (							self			:				Optional[int]					)->Dict:
      print(
          ANSI.red(
              "WARNING! `transformers-cli whoami` is deprecated and will be removed in v5. Please use "
              "`huggingface-cli whoami` instead."					)					)
      __SCREAMING_SNAKE_CASE							:     Dict							=						HfFolder.get_token()
      if token is None:
       print("Not logged in"					)
       exit()
      try:
       __SCREAMING_SNAKE_CASE,		__SCREAMING_SNAKE_CASE							:     Optional[int]							=						whoami(UpperCamelCase					)
       print(UpperCamelCase					)
       if orgs:
        print(ANSI.bold("orgs: "					)  ,	",".join(UpperCamelCase					)					)
      except HTTPError as e:
       print(UpperCamelCase					)
       print(ANSI.red(e.response.text					)					)
       exit(1					)






class    _SCREAMING_SNAKE_CASE						(UpperCamelCase			):





     def 						__snake_case     (							self			:				Any					)->Optional[Any]:
      print(
          ANSI.red(
              "ERROR! `transformers-cli logout` uses an outdated logout mechanism "
              "that is not compatible with the Hugging Face Hub backend anymore. "
              "Please use `huggingface-cli logout instead."					)					)






class    _SCREAMING_SNAKE_CASE						(UpperCamelCase			):





     def 						__snake_case     (							self			:				Dict					)->int:
      print(
          ANSI.red(
              "WARNING! Managing repositories through transformers-cli is deprecated. "
              "Please use `huggingface-cli` instead."					)					)
      __SCREAMING_SNAKE_CASE							:     Union[str, Any]							=						HfFolder.get_token()
      if token is None:
       print("Not logged in"					)
       exit(1					)
      try:
       __SCREAMING_SNAKE_CASE							:     Tuple							=						subprocess.check_output(["git", "--version"]					).decode("utf-8"					)
       print(ANSI.gray(stdout.strip()					)					)
      except FileNotFoundError:
       print("Looks like you do not have git installed, please install."					)

      try:
       __SCREAMING_SNAKE_CASE							:     Tuple							=						subprocess.check_output(["git-lfs", "--version"]					).decode("utf-8"					)
       print(ANSI.gray(stdout.strip()					)					)
      except FileNotFoundError:
       print(
           ANSI.red(
               "Looks like you do not have git-lfs installed, please install."
               " You can install from https://git-lfs.github.com/."
               " Then run `git lfs install` (you only have to do this once)."					)					)
      print(""					)

      __SCREAMING_SNAKE_CASE,		__SCREAMING_SNAKE_CASE							:     Optional[int]							=						whoami(UpperCamelCase					)
      __SCREAMING_SNAKE_CASE							:     int							=						self.args.organization if self.args.organization is not None else user
      __SCREAMING_SNAKE_CASE							:     List[Any]							=						F"""{namespace}/{self.args.name}"""
      print(F"""You are about to create {ANSI.bold(UpperCamelCase					)}"""					)

      if not self.args.yes:
       __SCREAMING_SNAKE_CASE							:     List[Any]							=						input("Proceed? [Y/n] "					).lower()
       if not (choice == "" or choice == "y" or choice == "yes"):
        print("Abort"					)
        exit()
      try:
       __SCREAMING_SNAKE_CASE							:     List[str]							=						create_repo(UpperCamelCase  ,	name=self.args.name  ,	organization=self.args.organization					)
      except HTTPError as e:
       print(UpperCamelCase					)
       print(ANSI.red(e.response.text					)					)
       exit(1					)
      print("\nYour repo now lives at:"					)
      print(F"""  {ANSI.bold(UpperCamelCase					)}"""					)
      print("\nYou can clone it locally with the command below, and commit/push as usual."					)
      print(F"""\n  git clone {url}"""					)
      print(""					)








'''simple docstring'''







import json
import os
import unittest

from transformers.models.gpt_neox_japanese.tokenization_gpt_neox_japanese import (
    VOCAB_FILES_NAMES,
    GPTNeoXJapaneseTokenizer,
)
from transformers.testing_utils import require_tokenizers, slow

from ...test_tokenization_common import TokenizerTesterMixin
@require_tokenizers
class  SCREAMING_SNAKE_CASE__       (  __UpperCamelCase			,					unittest.TestCase   ):
	lowercase__	    =							GPTNeoXJapaneseTokenizer
	lowercase__	    =							False
	lowercase__	    =							{"do_clean_text": False, "add_prefix_space": False}
	def __lowerCamelCase    (				self			):



					'''simple docstring'''






					super().setUp()

					__a       :     Optional[int]								=	[
					    """こん""",
					    """こんに""",
					    """にちは""",
					    """ばんは""",
					    """世界,㔺界""",
					    """、""",
					    """。""",
					    """<BR>""",
					    """<SP>""",
					    """<TAB>""",
					    """<URL>""",
					    """<EMAIL>""",
					    """<TEL>""",
					    """<DATE>""",
					    """<PRICE>""",
					    """<BLOCK>""",
					    """<KIGOU>""",
					    """<U2000U2BFF>""",
					    """<|emoji1|>""",
					    """<unk>""",
					    """<|startoftext|>""",
					    """<|endoftext|>""",
					]
					__a       :     Any								=	{"""emoji""": {"""\ud83d\ude00""": """<|emoji1|>"""}, """emoji_inv""": {"""<|emoji1|>""": """\ud83d\ude00"""}}  # 😀
					__a       :     List[str]								=	{"""unk_token""": """<unk>"""}

					__a       :     Any								=	os.path.join(self.tmpdirname  ,    VOCAB_FILES_NAMES["""vocab_file"""]			)
					__a       :     Tuple								=	os.path.join(self.tmpdirname  ,    VOCAB_FILES_NAMES["""emoji_file"""]			)
					with open(self.vocab_file  ,    """w"""  ,    encoding="""utf-8"""			) as vocab_writer:
									vocab_writer.write("""""".join([x + """\n""" for x in vocab_tokens]			)			)
					with open(self.emoji_file  ,    """w"""			) as emoji_writer:
									emoji_writer.write(json.dumps(__UpperCamelCase			)			)
	def __lowerCamelCase    (				self  ,    **__UpperCamelCase			):



					'''simple docstring'''






					kwargs.update(self.special_tokens_map			)
					return GPTNeoXJapaneseTokenizer.from_pretrained(self.tmpdirname  ,    **__UpperCamelCase			)
	def __lowerCamelCase    (				self  ,    __UpperCamelCase			):



					'''simple docstring'''






					__a       :     Any								=	"""こんにちは、世界。 \nこんばんは、㔺界。😀"""
					__a       :     Optional[int]								=	"""こんにちは、世界。 \nこんばんは、世界。😀"""
					return input_text, output_text
	def __lowerCamelCase    (				self  ,    __UpperCamelCase			):



					'''simple docstring'''






					__a							,	__a       :     List[str]								=	self.get_input_output_texts(__UpperCamelCase			)
					__a       :     List[str]								=	tokenizer.encode(__UpperCamelCase  ,    add_special_tokens=__UpperCamelCase			)
					__a       :     str								=	tokenizer.decode(__UpperCamelCase  ,    clean_up_tokenization_spaces=__UpperCamelCase			)
					return text, ids
	def __lowerCamelCase    (				self			):



					'''simple docstring'''






					pass  # TODO add if relevant
	def __lowerCamelCase    (				self			):



					'''simple docstring'''






					pass  # TODO add if relevant
	def __lowerCamelCase    (				self			):



					'''simple docstring'''






					pass  # TODO add if relevant
	def __lowerCamelCase    (				self			):



					'''simple docstring'''






					__a       :     List[Any]								=	self.get_tokenizer()

					# Testing tokenization
					__a       :     Dict								=	"""こんにちは、世界。　こんばんは、㔺界。"""
					__a       :     Optional[int]								=	["""こん""", """にちは""", """、""", """世界""", """。""", """<SP>""", """こん""", """ばんは""", """、""", """㔺界""", """。"""]
					__a       :     str								=	tokenizer.tokenize(__UpperCamelCase			)
					self.assertListEqual(__UpperCamelCase  ,    __UpperCamelCase			)

					# Testing conversion to ids without special tokens
					__a       :     Optional[Any]								=	[0, 2, 5, 4, 6, 8, 0, 3, 5, 4, 6]
					__a       :     Optional[int]								=	tokenizer.convert_tokens_to_ids(__UpperCamelCase			)
					self.assertListEqual(__UpperCamelCase  ,    __UpperCamelCase			)

					# Testing conversion to ids with special tokens
					__a       :     List[str]								=	tokens + [tokenizer.unk_token]
					__a       :     Dict								=	[0, 2, 5, 4, 6, 8, 0, 3, 5, 4, 6, 19]
					__a       :     Any								=	tokenizer.convert_tokens_to_ids(__UpperCamelCase			)
					self.assertListEqual(__UpperCamelCase  ,    __UpperCamelCase			)
	@slow
	def __lowerCamelCase    (				self			):



					'''simple docstring'''






					__a       :     int								=	self.tokenizer_class.from_pretrained("""abeja/gpt-neox-japanese-2.7b"""			)

					__a       :     Union[str, Any]								=	tokenizer.encode("""ありがとう。"""  ,    add_special_tokens=__UpperCamelCase			)
					__a       :     Dict								=	tokenizer.encode("""どういたしまして。"""  ,    add_special_tokens=__UpperCamelCase			)

					__a       :     Optional[Any]								=	tokenizer.build_inputs_with_special_tokens(__UpperCamelCase			)
					__a       :     int								=	tokenizer.build_inputs_with_special_tokens(__UpperCamelCase  ,    __UpperCamelCase			)

					assert encoded_sentence == ids_a
					assert encoded_pair == ids_a + ids_a
	def __lowerCamelCase    (				self			):



					'''simple docstring'''






					pass

	def __lowerCamelCase    (				self			):



					'''simple docstring'''






					pass