




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__		(__lowerCamelCase ):
     @staticmethod
     def 					A__			(	__lowerCamelCase  :		ArgumentParser	):



       """simple docstring"""
       lowerCAmelCase__								=			parser.add_parser('''login'''					,	help='''Log in using the same credentials as on huggingface.co'''	)
       login_parser.set_defaults(func=lambda __lowerCamelCase	: LoginCommand(__lowerCamelCase	)	)
       lowerCAmelCase__								=			parser.add_parser('''whoami'''					,	help='''Find out which huggingface.co account you are logged in as.'''	)
       whoami_parser.set_defaults(func=lambda __lowerCamelCase	: WhoamiCommand(__lowerCamelCase	)	)
       lowerCAmelCase__								=			parser.add_parser('''logout'''					,	help='''Log out'''	)
       logout_parser.set_defaults(func=lambda __lowerCamelCase	: LogoutCommand(__lowerCamelCase	)	)

       # new system: git-based repo system
       lowerCAmelCase__								=			parser.add_parser(
           '''repo'''					,	help='''Deprecated: use `huggingface-cli` instead. Commands to interact with your huggingface.co repos.'''					,	)
       lowerCAmelCase__								=			repo_parser.add_subparsers(
           help='''Deprecated: use `huggingface-cli` instead. huggingface.co repos related commands'''	)
       lowerCAmelCase__								=			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=__lowerCamelCase					,	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=__lowerCamelCase					,	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 __lowerCamelCase	: RepoCreateCommand(__lowerCamelCase	)	)





class 						SCREAMING_SNAKE_CASE__		:
     lowercase_   :			List[str]   =   '\u001b[1m'
     lowercase_   :			Union[str, Any]   =   '\u001b[31m'
     lowercase_   :			Any   =   '\u001b[90m'
     lowercase_   :			List[str]   =   '\u001b[0m'
     @classmethod
     def 					A__			(	cls  :		List[Any]					,	__lowerCamelCase  :		Any	):



       """simple docstring"""
       return F"""{cls._bold}{s}{cls._reset}"""
     @classmethod
     def 					A__			(	cls  :		Optional[Any]					,	__lowerCamelCase  :		str	):



       """simple docstring"""
       return F"""{cls._bold}{cls._red}{s}{cls._reset}"""



     @classmethod
     def 					A__			(	cls  :		List[str]					,	__lowerCamelCase  :		Any	):



       """simple docstring"""
       return F"""{cls._gray}{s}{cls._reset}"""



def 		a_       (   __lowerCAmelCase      ,   __lowerCAmelCase							):
  lowerCAmelCase__								=			[max(len(str(__lowerCAmelCase							)							) for x in col							) for col in zip(*__lowerCAmelCase      ,   __lowerCAmelCase							)]
  lowerCAmelCase__								=			('''{{:{}}} ''' * len(__lowerCAmelCase							)).format(*__lowerCAmelCase							)
  lowerCAmelCase__								=			[]
  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  :		List[str]					,	__lowerCamelCase  :		Optional[Any]	):



       """simple docstring"""
       lowerCAmelCase__								=			args





class 						SCREAMING_SNAKE_CASE__		(__lowerCamelCase ):
     def 					A__			(	self  :		List[str]	):



       """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 						SCREAMING_SNAKE_CASE__		(__lowerCamelCase ):
     def 					A__			(	self  :		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.'''	)	)
       lowerCAmelCase__								=			HfFolder.get_token()
       if token is None:
         print('''Not logged in'''	)
         exit()
       try:
         lowerCAmelCase__							,			lowerCAmelCase__								=			whoami(__lowerCamelCase	)
         print(__lowerCamelCase	)
         if orgs:
           print(ANSI.bold('''orgs: '''	)					,	''','''.join(__lowerCamelCase	)	)
       except HTTPError as e:
         print(__lowerCamelCase	)
         print(ANSI.red(e.response.text	)	)
         exit(1	)





class 						SCREAMING_SNAKE_CASE__		(__lowerCamelCase ):
     def 					A__			(	self  :		str	):



       """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 						SCREAMING_SNAKE_CASE__		(__lowerCamelCase ):
     def 					A__			(	self  :		int	):



       """simple docstring"""
       print(
           ANSI.red(
               '''WARNING! Managing repositories through transformers-cli is deprecated. '''
               '''Please use `huggingface-cli` instead.'''	)	)
       lowerCAmelCase__								=			HfFolder.get_token()
       if token is None:
         print('''Not logged in'''	)
         exit(1	)
       try:
         lowerCAmelCase__								=			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:
         lowerCAmelCase__								=			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(''''''	)

       lowerCAmelCase__							,			lowerCAmelCase__								=			whoami(__lowerCamelCase	)
       lowerCAmelCase__								=			self.args.organization if self.args.organization is not None else user
       lowerCAmelCase__								=			F"""{namespace}/{self.args.name}"""
       print(F"""You are about to create {ANSI.bold(__lowerCamelCase	)}"""	)

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







import os

from ...utils import logging
from .utils import DataProcessor, InputExample


__magic_name__     :     str  							=					logging.get_logger(__name__)





class 						SCREAMING_SNAKE_CASE__		(_a ):
     def __init__(	self  :		Any					,	__lowerCamelCase  :		Any					,	__lowerCamelCase  :		Optional[int]=None	):



       """simple docstring"""
       lowerCAmelCase__								=			language
       lowerCAmelCase__								=			train_language
     def 					A__			(	self  :		str					,	__lowerCamelCase  :		List[str]	):



       """simple docstring"""
       lowerCAmelCase__								=			self.language if self.train_language is None else self.train_language
       lowerCAmelCase__								=			self._read_tsv(os.path.join(__lowerCamelCase					,	F"""XNLI-MT-1.0/multinli/multinli.train.{lg}.tsv"""	)	)
       lowerCAmelCase__								=			[]
       for i, line in enumerate(__lowerCamelCase	):
         if i == 0:
           continue
         lowerCAmelCase__								=			F"""train-{i}"""
         lowerCAmelCase__								=			line[0]
         lowerCAmelCase__								=			line[1]
         lowerCAmelCase__								=			'''contradiction''' if line[2] == '''contradictory''' else line[2]
         if not isinstance(__lowerCamelCase					,	__lowerCamelCase	):
           raise ValueError(F"""Training input {text_a} is not a string"""	)
         if not isinstance(__lowerCamelCase					,	__lowerCamelCase	):
           raise ValueError(F"""Training input {text_b} is not a string"""	)
         if not isinstance(__lowerCamelCase					,	__lowerCamelCase	):
           raise ValueError(F"""Training label {label} is not a string"""	)
         examples.append(InputExample(guid=__lowerCamelCase					,	text_a=__lowerCamelCase					,	text_b=__lowerCamelCase					,	label=__lowerCamelCase	)	)
       return examples
     def 					A__			(	self  :		Dict					,	__lowerCamelCase  :		Union[str, Any]	):



       """simple docstring"""
       lowerCAmelCase__								=			self._read_tsv(os.path.join(__lowerCamelCase					,	'''XNLI-1.0/xnli.test.tsv'''	)	)
       lowerCAmelCase__								=			[]
       for i, line in enumerate(__lowerCamelCase	):
         if i == 0:
           continue
         lowerCAmelCase__								=			line[0]
         if language != self.language:
           continue
         lowerCAmelCase__								=			F"""test-{i}"""
         lowerCAmelCase__								=			line[6]
         lowerCAmelCase__								=			line[7]
         lowerCAmelCase__								=			line[1]
         if not isinstance(__lowerCamelCase					,	__lowerCamelCase	):
           raise ValueError(F"""Training input {text_a} is not a string"""	)
         if not isinstance(__lowerCamelCase					,	__lowerCamelCase	):
           raise ValueError(F"""Training input {text_b} is not a string"""	)
         if not isinstance(__lowerCamelCase					,	__lowerCamelCase	):
           raise ValueError(F"""Training label {label} is not a string"""	)
         examples.append(InputExample(guid=__lowerCamelCase					,	text_a=__lowerCamelCase					,	text_b=__lowerCamelCase					,	label=__lowerCamelCase	)	)
       return examples



     def 					A__			(	self  :		List[str]	):



       """simple docstring"""
       return ["contradiction", "entailment", "neutral"]



__magic_name__     :     Tuple  							=					{
    """xnli""": XnliProcessor,
}

__magic_name__     :     List[Any]  							=					{
    """xnli""": """classification""",
}

__magic_name__     :     str  							=					{
    """xnli""": 3,
}

