login.py 857 B

1234567891011121314151617181920212223242526272829303132333435
  1. # Copyright (c) Alibaba, Inc. and its affiliates.
  2. from argparse import ArgumentParser
  3. from modelscope.cli.base import CLICommand
  4. from modelscope.hub.api import HubApi
  5. def subparser_func(args):
  6. """ Function which will be called for a specific sub parser.
  7. """
  8. return LoginCMD(args)
  9. class LoginCMD(CLICommand):
  10. name = 'login'
  11. def __init__(self, args):
  12. self.args = args
  13. @staticmethod
  14. def define_args(parsers: ArgumentParser):
  15. """ define args for login command.
  16. """
  17. parser = parsers.add_parser(LoginCMD.name)
  18. parser.add_argument(
  19. '--token',
  20. type=str,
  21. required=True,
  22. help='The Access Token for modelscope.')
  23. parser.set_defaults(func=subparser_func)
  24. def execute(self):
  25. api = HubApi()
  26. api.login(self.args.token)