


'''simple docstring'''



import inspect
import re
from hashlib import shaaaa
from typing import Dict, List

from .arrow import arrow
from .audiofolder import audiofolder
from .csv import csv
from .imagefolder import imagefolder
from .json import json
from .pandas import pandas
from .parquet import parquet
from .sql import sql  # noqa F401
from .text import text


def    lowerCamelCase__   ( A     :    List[str]  ):




						'''simple docstring'''






						UpperCAmelCase         =			[]
						for line in lines:
												UpperCAmelCase         =			re.sub(R'''#.*'''   ,     ''''''   ,     A  )  # remove comments
												if line:
																		filtered_lines.append(A  )
						UpperCAmelCase         =			'''\n'''.join(A  )

						# Make a hash from all this code
						UpperCAmelCase         =			full_str.encode('''utf-8'''  )
						return shaaaa(A  ).hexdigest()


# get importable module names and hash for caching
_lowercase    :    Union[str, Any]			 =  {
    """csv""": (csv.__name__, _hash_python_lines(inspect.getsource(csv).splitlines())),
    """json""": (json.__name__, _hash_python_lines(inspect.getsource(json).splitlines())),
    """pandas""": (pandas.__name__, _hash_python_lines(inspect.getsource(pandas).splitlines())),
    """parquet""": (parquet.__name__, _hash_python_lines(inspect.getsource(parquet).splitlines())),
    """arrow""": (arrow.__name__, _hash_python_lines(inspect.getsource(arrow).splitlines())),
    """text""": (text.__name__, _hash_python_lines(inspect.getsource(text).splitlines())),
    """imagefolder""": (imagefolder.__name__, _hash_python_lines(inspect.getsource(imagefolder).splitlines())),
    """audiofolder""": (audiofolder.__name__, _hash_python_lines(inspect.getsource(audiofolder).splitlines())),
}

# Used to infer the module to use based on the data files extensions
_lowercase    :    str			 =  {
    """.csv""": ("""csv""", {}),
    """.tsv""": ("""csv""", {"""sep""": """\t"""}),
    """.json""": ("""json""", {}),
    """.jsonl""": ("""json""", {}),
    """.parquet""": ("""parquet""", {}),
    """.arrow""": ("""arrow""", {}),
    """.txt""": ("""text""", {}),
}
_EXTENSION_TO_MODULE.update({ext: ("""imagefolder""", {}) for ext in imagefolder.ImageFolder.EXTENSIONS})
_EXTENSION_TO_MODULE.update({ext.upper(): ("""imagefolder""", {}) for ext in imagefolder.ImageFolder.EXTENSIONS})
_EXTENSION_TO_MODULE.update({ext: ("""audiofolder""", {}) for ext in audiofolder.AudioFolder.EXTENSIONS})
_EXTENSION_TO_MODULE.update({ext.upper(): ("""audiofolder""", {}) for ext in audiofolder.AudioFolder.EXTENSIONS})
_lowercase    :    Dict			 =  {"""imagefolder""", """audiofolder"""}

# Used to filter data files based on extensions given a module name
_lowercase    :    Dict[str, List[str]]			 =  {}
for _ext, (_module, _) in _EXTENSION_TO_MODULE.items():
	_MODULE_TO_EXTENSIONS.setdefault(_module, []).append(_ext)

_MODULE_TO_EXTENSIONS["imagefolder"].append(""".zip""")




_MODULE_TO_EXTENSIONS["audiofolder"].append(""".zip""")









'''simple docstring'''



from argparse import ArgumentParser

from . import BaseTransformersCLICommand


def    lowerCamelCase__   ( A     :    List[Any]  ):




						'''simple docstring'''






						return DownloadCommand(args.model   ,     args.cache_dir   ,     args.force   ,     args.trust_remote_code  )






class  UpperCamelCase__(     lowerCAmelCase ):




				@staticmethod
				def   a__(	lowerCAmelCase    :				ArgumentParser   )->  Optional[Any]:

										"""simple docstring"""




										UpperCAmelCase         =			parser.add_parser('''download'''   )
										download_parser.add_argument(
										    '''--cache-dir'''   ,					type=lowerCAmelCase   ,					default=lowerCAmelCase   ,					help='''Path to location to store the models'''   )
										download_parser.add_argument(
										    '''--force'''   ,					action='''store_true'''   ,					help='''Force the model to be download even if already in cache-dir'''   )
										download_parser.add_argument(
										    '''--trust-remote-code'''   ,					action='''store_true'''   ,					help='''Whether or not to allow for custom models defined on the Hub in their own modeling files. Use only if you\'ve reviewed the code as it will execute on your local machine'''   ,					)
										download_parser.add_argument('''model'''   ,					type=lowerCAmelCase   ,					help='''Name of the model to download'''   )
										download_parser.set_defaults(func=lowerCAmelCase   )




				def __init__(	self    :				Dict   ,					lowerCAmelCase    :				str   ,					lowerCAmelCase    :				str   ,					lowerCAmelCase    :				bool   ,					lowerCAmelCase    :				bool   )->  Any:

										"""simple docstring"""




										UpperCAmelCase         =			model
										UpperCAmelCase         =			cache
										UpperCAmelCase         =			force
										UpperCAmelCase         =			trust_remote_code





				def   a__(	self    :				int   )->  Optional[Any]:

										"""simple docstring"""




										from ..models.auto import AutoModel, AutoTokenizer

										AutoModel.from_pretrained(
										    self._model   ,					cache_dir=self._cache   ,					force_download=self._force   ,					trust_remote_code=self._trust_remote_code   )
										AutoTokenizer.from_pretrained(
										    self._model   ,					cache_dir=self._cache   ,					force_download=self._force   ,					trust_remote_code=self._trust_remote_code   )





