"""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 		_lowercase (						__a      ):



						"""simple docstring"""




						@staticmethod
						def   UpperCAmelCase_ (				UpperCamelCase__							:    ArgumentParser				)				->				int:
													'''simple docstring'''



													__UpperCamelCase							=parser.add_parser('''login'''     , help='''Log in using the same credentials as on huggingface.co'''				)
													login_parser.set_defaults(func=lambda UpperCamelCase__				: LoginCommand(UpperCamelCase__				)				)
													__UpperCamelCase							=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__				)				)
													__UpperCamelCase							=parser.add_parser('''logout'''     , help='''Log out'''				)
													logout_parser.set_defaults(func=lambda UpperCamelCase__				: LogoutCommand(UpperCamelCase__				)				)

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



						"""simple docstring"""




						lowercase__       =  '''\u001b[1m'''
						lowercase__       =  '''\u001b[31m'''
						lowercase__       =  '''\u001b[90m'''
						lowercase__       =  '''\u001b[0m'''





						@classmethod
						def   UpperCAmelCase_ (				cls							:    Optional[int]     , UpperCamelCase__							:    Union[str, Any]				)				->				List[str]:
													'''simple docstring'''



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





						@classmethod
						def   UpperCAmelCase_ (				cls							:    Any     , UpperCamelCase__							:    Dict				)				->				Union[str, Any]:
													'''simple docstring'''



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





						@classmethod
						def   UpperCAmelCase_ (				cls							:    Any     , UpperCamelCase__							:    Tuple				)				->				Optional[int]:
													'''simple docstring'''



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






def    lowerCAmelCase			(__UpperCamelCase							:    List[List[Union[str, int]]]							,					__UpperCamelCase							:    List[str]			):
							"""simple docstring"""


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






class 		_lowercase :



						"""simple docstring"""




						def __init__(				self							:    int     , UpperCamelCase__							:    Dict				)				->				int:
													'''simple docstring'''



													__UpperCamelCase							=args






class 		_lowercase (						__a      ):



						"""simple docstring"""




						def   UpperCAmelCase_ (				self							:    Optional[int]				)				->				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 		_lowercase (						__a      ):



						"""simple docstring"""




						def   UpperCAmelCase_ (				self							:    Union[str, Any]				)				->				Union[str, Any]:
													'''simple docstring'''



													print(
													    ANSI.red(
													        '''WARNING! `transformers-cli whoami` is deprecated and will be removed in v5. Please use '''
													        '''`huggingface-cli whoami` instead.'''				)				)
													__UpperCamelCase							=HfFolder.get_token()
													if token is None:
																				print('''Not logged in'''				)
																				exit()
													try:
																				__UpperCamelCase	,      __UpperCamelCase							=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 		_lowercase (						__a      ):



						"""simple docstring"""




						def   UpperCAmelCase_ (				self							:    Optional[Any]				)				->				Any:
													'''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 		_lowercase (						__a      ):



						"""simple docstring"""




						def   UpperCAmelCase_ (				self							:    Optional[Any]				)				->				Dict:
													'''simple docstring'''



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

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

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

from typing import TYPE_CHECKING

from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_torch_available, is_vision_available


__lowercase    =				{
    '''configuration_videomae''': ['''VIDEOMAE_PRETRAINED_CONFIG_ARCHIVE_MAP''', '''VideoMAEConfig'''],
}

try:
				if not is_torch_available():
								raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
				pass
else:
				__lowercase    =				[
				    '''VIDEOMAE_PRETRAINED_MODEL_ARCHIVE_LIST''',
				    '''VideoMAEForPreTraining''',
				    '''VideoMAEModel''',
				    '''VideoMAEPreTrainedModel''',
				    '''VideoMAEForVideoClassification''',
				]

try:
				if not is_vision_available():
								raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
				pass
else:
				__lowercase    =				['''VideoMAEFeatureExtractor''']
				__lowercase    =				['''VideoMAEImageProcessor''']

if TYPE_CHECKING:
				from .configuration_videomae import VIDEOMAE_PRETRAINED_CONFIG_ARCHIVE_MAP, VideoMAEConfig

				try:
								if not is_torch_available():
												raise OptionalDependencyNotAvailable()
				except OptionalDependencyNotAvailable:
								pass
				else:
								from .modeling_videomae import (
								    VIDEOMAE_PRETRAINED_MODEL_ARCHIVE_LIST,
								    VideoMAEForPreTraining,
								    VideoMAEForVideoClassification,
								    VideoMAEModel,
								    VideoMAEPreTrainedModel,
								)

				try:
								if not is_vision_available():
												raise OptionalDependencyNotAvailable()
				except OptionalDependencyNotAvailable:
								pass
				else:
								from .feature_extraction_videomae import VideoMAEFeatureExtractor
								from .image_processing_videomae import VideoMAEImageProcessor

else:
				import sys

				__lowercase    =				_LazyModule(__name__, globals()['''__file__'''], _import_structure, module_spec=__spec__)



