

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     a__    (				UpperCAmelCase    ):







  """simple docstring"""




  @staticmethod
  def 	_lowercase (     UpperCAmelCase__      :	ArgumentParser						)   ->Dict:
        """simple docstring"""







        SCREAMING_SNAKE_CASE	: str					       =				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	: Dict					       =				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	: str					       =				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	: Dict					       =				parser.add_parser(
            """repo"""			,			help="""Deprecated: use `huggingface-cli` instead. Commands to interact with your huggingface.co repos."""			,			)
        SCREAMING_SNAKE_CASE	: Union[str, Any]					       =				repo_parser.add_subparsers(
            help="""Deprecated: use `huggingface-cli` instead. huggingface.co repos related commands"""						)
        SCREAMING_SNAKE_CASE	: Union[str, 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     a__    :







  """simple docstring"""




  UpperCAmelCase__ :	Tuple         ="""\u001b[1m"""
  UpperCAmelCase__ :	Tuple         ="""\u001b[31m"""
  UpperCAmelCase__ :	str         ="""\u001b[90m"""
  UpperCAmelCase__ :	List[str]         ="""\u001b[0m"""


  @classmethod
  def 	_lowercase (     cls      :	str			,			UpperCAmelCase__      :	List[Any]						)   ->List[str]:
        """simple docstring"""







        return f"{cls._bold}{s}{cls._reset}"


  @classmethod
  def 	_lowercase (     cls      :	Optional[int]			,			UpperCAmelCase__      :	List[Any]						)   ->int:
        """simple docstring"""







        return f"{cls._bold}{cls._red}{s}{cls._reset}"




  @classmethod
  def 	_lowercase (     cls      :	List[Any]			,			UpperCAmelCase__      :	Union[str, Any]						)   ->int:
        """simple docstring"""







        return f"{cls._gray}{s}{cls._reset}"






def    __lowercase (       _A  ,      _A     )       ->  str:
      SCREAMING_SNAKE_CASE	: int					       =				[max(len(str(_A     )     ) for x in col     ) for col in zip(*_A  ,      _A     )]
      SCREAMING_SNAKE_CASE	: Optional[Any]					       =				("""{{:{}}} """ * len(_A     )).format(*_A     )
      SCREAMING_SNAKE_CASE	: Optional[int]					       =				[]
      lines.append(row_format.format(*_A     )     )
      lines.append(row_format.format(*["""-""" * w for w in col_widths]     )     )
      for row in rows:
            lines.append(row_format.format(*_A     )     )
      return "\n".join(_A     )







class     a__    :







  """simple docstring"""




  def __init__(     self      :	List[Any]			,			UpperCAmelCase__      :	Union[str, Any]						)   ->Union[str, Any]:
        """simple docstring"""







        SCREAMING_SNAKE_CASE	: Tuple					       =				args







class     a__    (				UpperCAmelCase    ):







  """simple docstring"""




  def 	_lowercase (     self      :	Any						)   ->int:
        """simple docstring"""







        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     a__    (				UpperCAmelCase    ):







  """simple docstring"""




  def 	_lowercase (     self      :	Tuple						)   ->List[Any]:
        """simple docstring"""







        print(
            ANSI.red(
                """WARNING! `transformers-cli whoami` is deprecated and will be removed in v5. Please use """
                """`huggingface-cli whoami` instead."""						)						)
        SCREAMING_SNAKE_CASE	: Any					       =				HfFolder.get_token()
        if token is None:
              print("""Not logged in"""						)
              exit()
        try:
              SCREAMING_SNAKE_CASE	: List[Any]					       =				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     a__    (				UpperCAmelCase    ):







  """simple docstring"""




  def 	_lowercase (     self      :	List[str]						)   ->Dict:
        """simple docstring"""







        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     a__    (				UpperCAmelCase    ):







  """simple docstring"""




  def 	_lowercase (     self      :	Dict						)   ->List[Any]:
        """simple docstring"""







        print(
            ANSI.red(
                """WARNING! Managing repositories through transformers-cli is deprecated. """
                """Please use `huggingface-cli` instead."""						)						)
        SCREAMING_SNAKE_CASE	: int					       =				HfFolder.get_token()
        if token is None:
              print("""Not logged in"""						)
              exit(1						)
        try:
              SCREAMING_SNAKE_CASE	: int					       =				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	: Optional[int]					       =				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	: Tuple					       =				whoami(UpperCAmelCase__						)
        SCREAMING_SNAKE_CASE	: Optional[int]					       =				self.args.organization if self.args.organization is not None else user
        SCREAMING_SNAKE_CASE	: Optional[int]					       =				f"{namespace}/{self.args.name}"
        print(f"You are about to create {ANSI.bold(UpperCAmelCase__						)}"						)

        if not self.args.yes:
              SCREAMING_SNAKE_CASE	: List[str]					       =				input("""Proceed? [Y/n] """						).lower()
              if not (choice == "" or choice == "y" or choice == "yes"):
                    print("""Abort"""						)
                    exit()
        try:
              SCREAMING_SNAKE_CASE	: List[Any]					       =				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(""""""						)







from typing import TYPE_CHECKING

from ...utils import (
    OptionalDependencyNotAvailable,
    _LazyModule,
    is_sentencepiece_available,
    is_speech_available,
    is_torch_available,
)


UpperCAmelCase__	:       int			      =      {
    """configuration_speech_to_text_2""": ["""SPEECH_TO_TEXT_2_PRETRAINED_CONFIG_ARCHIVE_MAP""", """Speech2Text2Config"""],
    """processing_speech_to_text_2""": ["""Speech2Text2Processor"""],
    """tokenization_speech_to_text_2""": ["""Speech2Text2Tokenizer"""],
}


try:
  if not is_torch_available():
    raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
  pass
else:
  UpperCAmelCase__	:       int			      =      [
      """SPEECH_TO_TEXT_2_PRETRAINED_MODEL_ARCHIVE_LIST""",
      """Speech2Text2ForCausalLM""",
      """Speech2Text2PreTrainedModel""",
  ]


if TYPE_CHECKING:
  from .configuration_speech_to_text_a import SPEECH_TO_TEXT_2_PRETRAINED_CONFIG_ARCHIVE_MAP, SpeechaTextaConfig
  from .processing_speech_to_text_a import SpeechaTextaProcessor
  from .tokenization_speech_to_text_a import SpeechaTextaTokenizer

  try:
    if not is_torch_available():
      raise OptionalDependencyNotAvailable()
  except OptionalDependencyNotAvailable:
    pass
  else:
    from .modeling_speech_to_text_a import (
        SPEECH_TO_TEXT_2_PRETRAINED_MODEL_ARCHIVE_LIST,
        SpeechaTextaForCausalLM,
        SpeechaTextaPreTrainedModel,
    )

else:
  import sys

  UpperCAmelCase__	:       int			      =      _LazyModule(__name__, globals()["""__file__"""], _import_structure, module_spec=__spec__)




