


'''simple docstring'''


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        __magic_name__  (					lowerCAmelCase__   ):

     """simple docstring"""






     @staticmethod
     def lowerCAmelCase__     (      lowerCamelCase		):


          '''simple docstring'''





          __A  :					List[Any]						     =       parser.add_parser("login" ,    help="Log in using the same credentials as on huggingface.co"		)
          login_parser.set_defaults(func=lambda lowerCamelCase		: LoginCommand(lowerCAmelCase_		)		)
          __A  :					Union[str, Any]						     =       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_		)		)
          __A  :					List[Any]						     =       parser.add_parser("logout" ,    help="Log out"		)
          logout_parser.set_defaults(func=lambda lowerCamelCase		: LogoutCommand(lowerCAmelCase_		)		)

          # new system: git-based repo system
          __A  :					int						     =       parser.add_parser(
              "repo" ,    help="Deprecated: use `huggingface-cli` instead. Commands to interact with your huggingface.co repos." ,    )
          __A  :					Optional[Any]						     =       repo_parser.add_subparsers(
              help="Deprecated: use `huggingface-cli` instead. huggingface.co repos related commands"		)
          __A  :					int						     =       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        __magic_name__  :

     """simple docstring"""






     lowerCamelCase__						=							"""\u001b[1m"""
     lowerCamelCase__						=							"""\u001b[31m"""
     lowerCamelCase__						=							"""\u001b[90m"""
     lowerCamelCase__						=							"""\u001b[0m"""


     @classmethod
     def lowerCAmelCase__     (      cls ,    lowerCamelCase		):


          '''simple docstring'''





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


     @classmethod
     def lowerCAmelCase__     (      cls ,    lowerCamelCase		):


          '''simple docstring'''





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


     @classmethod
     def lowerCAmelCase__     (      cls ,    lowerCamelCase		):


          '''simple docstring'''





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


def 		_lowercase   (SCREAMING_SNAKE_CASE					,				SCREAMING_SNAKE_CASE       ):




     '''simple docstring'''





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







class        __magic_name__  :

     """simple docstring"""






     def __init__(      self ,    lowerCamelCase		):


          '''simple docstring'''





          __A  :					Optional[Any]						     =       args







class        __magic_name__  (					lowerCAmelCase__   ):

     """simple docstring"""






     def lowerCAmelCase__     (      self		):


          '''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        __magic_name__  (					lowerCAmelCase__   ):

     """simple docstring"""






     def lowerCAmelCase__     (      self		):


          '''simple docstring'''





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

     """simple docstring"""






     def lowerCAmelCase__     (      self		):


          '''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        __magic_name__  (					lowerCAmelCase__   ):

     """simple docstring"""






     def lowerCAmelCase__     (      self		):


          '''simple docstring'''





          print(
              ANSI.red(
                  "WARNING! Managing repositories through transformers-cli is deprecated. "
                  "Please use `huggingface-cli` instead."		)		)
          __A  :					int						     =       HfFolder.get_token()
          if token is None:
               print("Not logged in"		)
               exit(1		)
          try:
               __A  :					Optional[Any]						     =       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:
               __A  :					str						     =       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(""		)

          __A     ,__A  :					Optional[int]						     =       whoami(lowerCAmelCase_		)
          __A  :					Union[str, Any]						     =       self.args.organization if self.args.organization is not None else user
          __A  :					Optional[int]						     =       f"{namespace}/{self.args.name}"
          print(f"You are about to create {ANSI.bold(lowerCAmelCase_		)}"		)

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





'''simple docstring'''


from sklearn.metrics import accuracy_score

import datasets


_UpperCamelCase          =     """
Accuracy is the proportion of correct predictions among the total number of cases processed. It can be computed with:
Accuracy = (TP + TN) / (TP + TN + FP + FN)
 Where:
TP: True positive
TN: True negative
FP: False positive
FN: False negative
"""


_UpperCamelCase          =     """
Args:
    predictions (`list` of `int`): Predicted labels.
    references (`list` of `int`): Ground truth labels.
    normalize (`boolean`): If set to False, returns the number of correctly classified samples. Otherwise, returns the fraction of correctly classified samples. Defaults to True.
    sample_weight (`list` of `float`): Sample weights Defaults to None.

Returns:
    accuracy (`float` or `int`): Accuracy score. Minimum possible value is 0. Maximum possible value is 1.0, or the number of examples input, if `normalize` is set to `True`.. A higher score means higher accuracy.

Examples:

    Example 1-A simple example
        >>> accuracy_metric = datasets.load_metric(\"accuracy\")
        >>> results = accuracy_metric.compute(references=[0, 1, 2, 0, 1, 2], predictions=[0, 1, 1, 2, 1, 0])
        >>> print(results)
        {'accuracy': 0.5}

    Example 2-The same as Example 1, except with `normalize` set to `False`.
        >>> accuracy_metric = datasets.load_metric(\"accuracy\")
        >>> results = accuracy_metric.compute(references=[0, 1, 2, 0, 1, 2], predictions=[0, 1, 1, 2, 1, 0], normalize=False)
        >>> print(results)
        {'accuracy': 3.0}

    Example 3-The same as Example 1, except with `sample_weight` set.
        >>> accuracy_metric = datasets.load_metric(\"accuracy\")
        >>> results = accuracy_metric.compute(references=[0, 1, 2, 0, 1, 2], predictions=[0, 1, 1, 2, 1, 0], sample_weight=[0.5, 2, 0.7, 0.5, 9, 0.4])
        >>> print(results)
        {'accuracy': 0.8778625954198473}
"""


_UpperCamelCase          =     """
@article{scikit-learn,
  title={Scikit-learn: Machine Learning in {P}ython},
  author={Pedregosa, F. and Varoquaux, G. and Gramfort, A. and Michel, V.
         and Thirion, B. and Grisel, O. and Blondel, M. and Prettenhofer, P.
         and Weiss, R. and Dubourg, V. and Vanderplas, J. and Passos, A. and
         Cournapeau, D. and Brucher, M. and Perrot, M. and Duchesnay, E.},
  journal={Journal of Machine Learning Research},
  volume={12},
  pages={2825--2830},
  year={2011}
}
"""







@datasets.utils.file_utils.add_start_docstrings(_DESCRIPTION						,		_KWARGS_DESCRIPTION   )
class        __magic_name__  (					datasets.Metric   ):

     """simple docstring"""






     def lowerCAmelCase__     (      self		):


          '''simple docstring'''





          return datasets.MetricInfo(
              description=_DESCRIPTION ,    citation=_CITATION ,    inputs_description=_KWARGS_DESCRIPTION ,    features=datasets.Features(
                  {
                      "predictions": datasets.Sequence(datasets.Value("int32"		)		),
                      "references": datasets.Sequence(datasets.Value("int32"		)		),
                  }
                  if self.config_name == "multilabel"
                  else {
                      "predictions": datasets.Value("int32"		),
                      "references": datasets.Value("int32"		),
                  }		) ,    reference_urls=["https://scikit-learn.org/stable/modules/generated/sklearn.metrics.accuracy_score.html"] ,    )


     def lowerCAmelCase__     (      self ,    lowerCamelCase ,    lowerCamelCase ,    lowerCamelCase=True ,    lowerCamelCase=None		):


          '''simple docstring'''





          return {
              "accuracy": float(
                  accuracy_score(lowerCamelCase ,    lowerCamelCase ,    normalize=lowerCamelCase ,    sample_weight=lowerCamelCase		)		)
          }

