o
    )jɥ                  '   @   s  d dl Z d dlZd dlZd dlZd dlZd dlmZ d dlmZ d dl	m
Z
 d dlmZ d dlmZmZmZmZmZ d dlmZ d dlmZmZmZmZmZmZ d d	lmZ d d
lmZ d dl m!Z! ddl"m#Z#m$Z$ ddl%m&Z& ddl'm(Z( ddl)m*Z*m+Z+ ddl,m-Z-m.Z.m/Z/ ddl0m1Z1 ddl2m3Z3m4Z4m5Z5m6Z6m7Z7 e Z8dZ9dddddddddddddeddddfde:dee: dee:edf deeee:f  dee; dee
 deee:ee: f  deee:ee: f  dee: deeee: e:f  d eeee: e:f  d!ee< d"e:d#ee: d$ee; d%eee&  d&ee: d'ee: d(e:f&d)d*Z=eddddddddddd+ddfd,e:dee: dee:edf dee: deeee:f  dee; dee
 deee:ee: f  deee:ee: f  deeee: e:f  d eeee: e:f  d$ee; d!e<d&ee: d'ee: d(e:f d-d.Z>dedddddddddd+dddd/d"e:d#ee: dee: dee:edf deeee:f  dee; dee
 deee:ee: f  deee:ee: f  dee: deeee: e:f  d eeee: e:f  d!e<d%eee&  d&ee: d'ee: f d0d1Z?dd2dddde9fd3d4Z@d5e:fd6d7ZAd8ee:ee: f fd9d:ZBd8ee: fd;d<ZCddddd=d>eeD deee:  deee:  deee:  d eee:  d(eeD fd?d@ZEdd2dddde9fdAdBZFe(ddfdCdDZGdedddddd+dddfd>ee: dEe1dFe:d"e:dGe#dHe:dIe:d#ee: dee: dee
 deee:ee: f  deee:ee: f  deeee: e:f  d eeee: e:f  d!e<d'ee: d%eee&  dJe;f$dKdLZHdS )M    N)ThreadPoolExecutor)nullcontext)	CookieJarPath)DictListOptionalTypeUnion)tqdm)DEFAULT_DATASET_REVISIONDEFAULT_MODEL_REVISIONINTRA_CLOUD_ACCELERATIONREPO_TYPE_DATASETREPO_TYPE_MODELREPO_TYPE_SUPPORT)get_modelscope_cache_dir)
get_logger)thread_executor   )HubApiModelScopeConfig)ProgressCallback)DEFAULT_MAX_WORKERS)FileDownloadErrorInvalidParameter)$create_temporary_directory_and_cachedownload_fileget_file_download_url)ModelFileSystemCache)extract_root_from_patternsget_model_masked_directorymodel_id_to_group_owner_name	strtoboolweak_file_lock   Fmodel_idrevision	cache_dir
user_agentlocal_files_onlycookiesignore_file_patternallow_file_pattern	local_dirallow_patternsignore_patternsmax_workersrepo_id	repo_typeenable_file_lockprogress_callbackstokenendpointreturnc                 C   s  |p| }|s
t d|tvrt d| dt |pt}|du r(|tkr&tnt}|du r5ttj	dd}|r]|dur=|nt
 }tjtj|ddd	 tj|d|d
d}t|}nt }| t|f||||||||||
|	||||dW  d   S 1 sw   Y  dS )a  Download all files of a repo.
    Downloads a whole snapshot of a repo's files at the specified revision. This
    is useful when you want all files from a repo, because you don't know which
    ones you will need a priori. All files are nested inside a folder in order
    to keep their actual filename relative to that folder.

    An alternative would be to just clone a repo but this would require that the
    user always has git and git-lfs installed, and properly configured.

    Args:
        repo_id (str): A user or an organization name and a repo name separated by a `/`.
        model_id (str): A user or an organization name and a model name separated by a `/`.
            if `repo_id` is provided, `model_id` will be ignored.
        repo_type (str, optional): The type of the repo, either 'model' or 'dataset'.
        revision (str, optional): An optional Git revision id which can be a branch name, a tag, or a
            commit hash. NOTE: currently only branch and tag name is supported
        cache_dir (str, Path, optional): Path to the folder where cached files are stored, model will
            be save as cache_dir/model_id/THE_MODEL_FILES.
        user_agent (str, dict, optional): The user-agent info in the form of a dictionary or a string.
        local_files_only (bool, optional): If `True`, avoid downloading the file and return the path to the
            local cached file if it exists.
        cookies (CookieJar, optional): The cookie of the request, default None.
        ignore_file_pattern (`str` or `List`, *optional*, default to `None`):
            Any file pattern to be ignored in downloading, like exact file names or file extensions.
        allow_file_pattern (`str` or `List`, *optional*, default to `None`):
            Any file pattern to be downloading, like exact file names or file extensions.
        local_dir (str, optional): Specific local directory path to which the file will be downloaded.
        allow_patterns (`str` or `List`, *optional*, default to `None`):
            If provided, only files matching at least one pattern are downloaded, priority over allow_file_pattern.
            For hugging-face compatibility.
        ignore_patterns (`str` or `List`, *optional*, default to `None`):
            If provided, files matching any of the patterns are not downloaded, priority over ignore_file_pattern.
            For hugging-face compatibility.
        max_workers (`int`): The maximum number of workers to download files, default 8.
        enable_file_lock (`bool`): Enable file lock, this is useful in multiprocessing downloading, default `True`.
            If you find something wrong with file lock and have a problem modifying your code,
            change `MODELSCOPE_HUB_FILE_LOCK` env to `false`.
        progress_callbacks (`List[Type[ProgressCallback]]`, **optional**, default to `None`):
            progress callbacks to track the download progress.
        token (str, optional): The user token.
    Raises:
        ValueError: the value details.

    Returns:
        str: Local folder path (string) of repo snapshot

    Note:
        Raises the following errors:
        - [`EnvironmentError`](https://docs.python.org/3/library/exceptions.html#EnvironmentError)
        if `use_auth_token=True` and the token cannot be found.
        - [`OSError`](https://docs.python.org/3/library/exceptions.html#OSError) if
        ETag cannot be determined.
        - [`ValueError`](https://docs.python.org/3/library/exceptions.html#ValueError)
        if some parameter value is invalid
    z*Please provide a valid model_id or repo_idInvalid repo type: z, only support: NMODELSCOPE_HUB_FILE_LOCKtrue.lockTexist_ok/___)r4   r(   r)   r*   r+   r,   r-   r.   r/   r1   r0   r2   r6   r7   r8   )
ValueErrorr   r   r   r   r   r$   osenvirongetr   makedirspathjoinreplacer%   r   _snapshot_download)r'   r(   r)   r*   r+   r,   r-   r.   r/   r0   r1   r2   r3   r4   r5   r6   r7   r8   system_cache	lock_filecontext rN   a/var/www/html/Deteccion_Ine/venv/lib/python3.10/site-packages/modelscope/hub/snapshot_download.pysnapshot_download)   sV   L


$rP      
dataset_idc                 C   s   |du rt tjdd}|r5|dur|nt }tjtj|ddd tj|d| dd}t	|}nt
 }| t| t|||||||||
|	|||d	W  d   S 1 sXw   Y  dS )
a  Download raw files of a dataset.
    Downloads all files at the specified revision. This
    is useful when you want all files from a dataset, because you don't know which
    ones you will need a priori. All files are nested inside a folder in order
    to keep their actual filename relative to that folder.

    An alternative would be to just clone a dataset but this would require that the
    user always has git and git-lfs installed, and properly configured.

    Args:
        dataset_id (str): A user or an organization name and a dataset name separated by a `/`.
        revision (str, optional): An optional Git revision id which can be a branch name, a tag, or a
            commit hash. NOTE: currently only branch and tag name is supported
        cache_dir (str, Path, optional): Path to the folder where cached files are stored, dataset will
            be save as cache_dir/dataset_id/THE_DATASET_FILES.
        local_dir (str, optional): Specific local directory path to which the file will be downloaded.
        user_agent (str, dict, optional): The user-agent info in the form of a dictionary or a string.
        local_files_only (bool, optional): If `True`, avoid downloading the file and return the path to the
            local cached file if it exists.
        cookies (CookieJar, optional): The cookie of the request, default None.
        ignore_file_pattern (`str` or `List`, *optional*, default to `None`):
            Any file pattern to be ignored in downloading, like exact file names or file extensions.
            Use regression is deprecated.
        allow_file_pattern (`str` or `List`, *optional*, default to `None`):
            Any file pattern to be downloading, like exact file names or file extensions.
        allow_patterns (`str` or `List`, *optional*, default to `None`):
            If provided, only files matching at least one pattern are downloaded, priority over allow_file_pattern.
            For hugging-face compatibility.
        ignore_patterns (`str` or `List`, *optional*, default to `None`):
            If provided, files matching any of the patterns are not downloaded, priority over ignore_file_pattern.
            For hugging-face compatibility.
        enable_file_lock (`bool`): Enable file lock, this is useful in multiprocessing downloading, default `True`.
            If you find something wrong with file lock and have a problem modifying your code,
            change `MODELSCOPE_HUB_FILE_LOCK` env to `false`.
        max_workers (`int`): The maximum number of workers to download files, default 8.
        token (str, optional): The user token.
    Raises:
        ValueError: the value details.

    Returns:
        str: Local folder path (string) of repo snapshot

    Note:
        Raises the following errors:
        - [`EnvironmentError`](https://docs.python.org/3/library/exceptions.html#EnvironmentError)
        if `use_auth_token=True` and the token cannot be found.
        - [`OSError`](https://docs.python.org/3/library/exceptions.html#OSError) if
        ETag cannot be determined.
        - [`ValueError`](https://docs.python.org/3/library/exceptions.html#ValueError)
        if some parameter value is invalid
    Nr;   r<   r=   Tr>   r@   rA   )r4   r(   r)   r*   r+   r,   r-   r.   r/   r1   r0   r2   r7   r8   )r$   rC   rD   rE   r   rF   rG   rH   rI   r%   r   rJ   r   )rR   r(   r)   r/   r*   r+   r,   r-   r.   r0   r1   r5   r2   r7   r8   rK   rL   rM   rN   rN   rO   dataset_snapshot_download   s>   D


$rS   )r4   r(   r)   r*   r+   r,   r-   r.   r/   r0   r1   r2   r6   r7   r8   c          !      C   s  |st }|tvrtd|tf t| |	||d\}}|d ur |nt }|r;t|jdkr0tdt	d|  |
 S tj|dtt d}tdkrdtd	pUt  }|rdtd
|   ||d< t|d}|d u ru|j| ||d}|d u r}| }|t kr|	rtj|	}n|rtjj|g| dR  }ntjj|dg| dR  }td| d|  |j| |||d}|d }dtjv ri |ddi}ni |ddi}|jd ur|j|d< t t!|t!|
d}|j"| ||d|d u rdn|||d}|s |d ur t	d| d |j"| |d d|d u rdn|||d}t#||||
|d}t$|||| |d d ||||d|||d  d!| v rt%|| }tj&|rStd" ntd#| d$ ztj'tj||dd% W n t(y   t	d&| d'tj| d! Y n|w nz|t)kr |	rtj|	}n|rtjj|g| dR  }ntjj|d(g| dR  }td)|  t*| \}}|pt+}t t!|t!|
d}|rd| nd}td*| d+ t,|| |||||||
|d,
}t-|||| |||||||||d- |j.|d. |
 } | S )/Nz'Invalid repo type: %s, only support: %s)r/   r)   r4   r   zCannot find the requested files in the cached path and outgoing traffic has been disabled. To enable look-ups and downloads online, set 'local_files_only' to False.z6We can not confirm the cached file is for revision: %s)r*   )z
user-agentzsnapshot-identifierr<   ZINTRA_CLOUD_ACCELERATION_REGIONz6Intra-cloud acceleration enabled for downloading from zx-aliyun-region-id)r7   )r3   r4   r7   r@   modelszDownloading Model from z to directory: )r(   r,   r8   ZRevisionZCI_TESTzsnapshot-ci-testTrueZSnapshotcached_model_revision)r.   r0   TF)r'   r(   root	recursiveZuse_cookiesheadersr8   zroot='zF' returned no model files, falling back to root=None for full listing.r.   r-   r0   r1   )r4   r(   r,   pre_filteredr2   r8   r6   .z3Target directory already exists, skipping creation.zCreating symbolic link [z].)target_is_directoryzFailed to create symbolic link z for Zdatasetsz"Downloading Dataset to directory: zFetching file list (root: z)...)r7   	root_pathr.   r-   r0   r1   )cachetemporary_cache_dirr3   apidataset_name	namespacerY   r(   r,   r2   r8   r6   )Zrevision_info)/r   r   r   r   r   lencached_filesrB   loggerwarningZget_root_locationr   Zget_user_agentstruuiduuid4r   rC   getenvr   Z!_get_internal_acceleration_domaininfoZget_endpoint_for_readZget_cookiesrG   abspathrH   splitprintZget_valid_revision_detailrD   rV   r!   _normalize_patternsZget_model_filesfilter_files_by_patterns_download_file_listsr"   existssymlinkOSErrorr   r#   r   _iter_dataset_file_pages_pipeline_download_datasetZsave_model_version)!r3   r4   r(   r)   r*   r+   r,   r-   r.   r/   r0   r1   r2   r6   r7   r8   r`   r_   rK   rY   Z	region_id_api	directoryZrevision_detailZsnapshot_headerZextracted_root
repo_filesZmasked_directorygroup_or_ownernamer^   file_page_iterZcache_root_pathrN   rN   rO   rJ     sf  















rJ   r@   c                    s   d	vrt d	 d	dd\}} j||d\}tg 	
fdd}||}|sO|dkrOtd| d	 |d}|S )
aw  Fetch and filter dataset repo files with pagination and server-side prefix filtering.

    Applies per-page pattern filtering to minimize memory usage.
    Falls back to root_path='/' if the extracted prefix yields no results.

    Args:
        _api: HubApi instance.
        repo_id: Dataset repo identifier (owner/name).
        revision: Git revision.
        endpoint: API endpoint URL.
        token: Authentication token.
        root_path: Server-side directory prefix filter.
        allow_file_pattern: Include patterns for client-side filtering.
        ignore_file_pattern: Exclude patterns for client-side filtering.
        allow_patterns: Additional include patterns (HF-compatible).
        ignore_patterns: Additional exclude patterns (HF-compatible).
        page_size: Number of files per API page request.

    Returns:
        List of filtered file entry dicts.
    r@   Invalid repo_id: '', expected format 'owner/name'r   rb   rc   r8   r7   c                    s   d}g }	 z j 	
| d|d	}W n ty3 } ztd| d|  W Y d}~|S d}~ww |s9	 |S rJt|d}|| n
|dd	 |D  t|k r]	 |S |d7 }q)
zFFetch all pages with the given root_path, applying per-page filtering.r   T	r3   r(   r^   rX   page_number	page_sizer8   r7   Zdataset_hub_id#Error fetching dataset files (page ): NrZ   c                 s   s"    | ]}| d dkr|V  qdS )r
   treeNrE   .0frN   rN   rO   	<genexpr>.  s    zAfetch_repo_files.<locals>._paginate_and_filter.<locals>.<genexpr>)get_dataset_files	Exceptionrf   errorrq   extendrd   )effective_root_pathr   rz   dataset_filesepage_filteredrx   Z_hub_idr.   r0   r8   Zhas_patternsr-   r1   r   r3   r(   r7   rN   rO   _paginate_and_filter
  sV   



z.fetch_repo_files.<locals>._paginate_and_filterzroot_path='F' returned no results, falling back to root_path='/' for full listing.)r   rn   get_dataset_id_and_typeanyrf   rg   )rx   r3   r(   r8   r7   r^   r.   r-   r0   r1   r   _owner_dataset_name_r   rz   rN   r   rO   fetch_repo_files  s*   "

"/r   patternc                 C   s&   zt |  W dS  ty   Y dS w )NTF)recompileBaseException)r   rN   rN   rO   _is_valid_regexD  s   
r   patternsc                 C   s*   t | tr| g} | d urdd | D } | S )Nc                 S   s"   g | ]}| d s|n|d qS )r@   *)endswith)r   itemrN   rN   rO   
<listcomp>P  s    z'_normalize_patterns.<locals>.<listcomp>)
isinstancerh   )r   rN   rN   rO   rp   L  s   
rp   c                 C   s0   | d urg }| D ]}t |r|| q|S d S N)r   append)r   Zregex_patternsr   rN   rN   rO   _get_valid_regex_patternV  s   
r   rZ   rz   c                   s   t |}t |}t |}t |}t|}g }| D ]u  d dkr!qzM|r1t fdd|D r1W q|r@t fdd|D r@W q|rOt fdd|D rOW q|r^t fdd|D s^W q|rmt fdd|D smW qW n ty } ztd	|  W Y d
}~qd
}~ww |  q|S )a  Filter repo file entries by include/exclude patterns.

    Skips 'tree' type entries. Applies fnmatch and regex pattern matching.
    Returns only file entries that pass all filter criteria.

    Args:
        repo_files: List of file entry dicts with 'Type', 'Path', 'Name' keys.
        allow_file_pattern: Include patterns (fnmatch). Files must match at least one.
        ignore_file_pattern: Exclude patterns (fnmatch). Matching files are skipped.
        allow_patterns: Additional include patterns (HF-compatible).
        ignore_patterns: Additional exclude patterns (HF-compatible).

    Returns:
        List of file entries that pass all filters.
    r
   r   c                 3        | ]}t   d  |V  qdS r   Nfnmatchr   p	repo_filerN   rO   r     
    
z+filter_files_by_patterns.<locals>.<genexpr>c                 3   r   r   r   r   r   rN   rO   r     r   c                 3   s$    | ]}t | d  duV  qdS NameNr   searchr   r   rN   rO   r     s
    
c                 3   r   r   r   r   r   rN   rO   r     r   c                 3   r   r   r   r   r   rN   rO   r     r   zInvalid file pattern: %sN)rp   r   r   r   rf   rg   r   )rz   r.   r-   r0   r1   ignore_regex_patternfilteredr   rN   r   rO   rq   a  sL   rq   c                 #   s    d	vrt d	 d	dd\}} j||d\}tg 	
fdd}z8d}||D ]}d	}|V  q@|s`|dkrftd
| d |dD ]}|V  qZW t  dS W t  dS W t  dS t  w )a  Generator that yields filtered file pages from a dataset repo.

    Each yield is a non-empty list of file-entry dicts for one API page.
    Applies per-page pattern filtering to minimize memory usage.
    Falls back to root_path='/' if the extracted prefix yields no results.

    Args:
        _api: HubApi instance.
        repo_id: Dataset repo identifier (owner/name).
        revision: Git revision.
        endpoint: API endpoint URL.
        token: Authentication token.
        root_path: Server-side directory prefix filter.
        allow_file_pattern: Include patterns (fnmatch).
        ignore_file_pattern: Exclude patterns (fnmatch).
        allow_patterns: Additional include patterns (HF-compatible).
        ignore_patterns: Additional exclude patterns (HF-compatible).
        page_size: Number of files per API page request.

    Yields:
        List[dict]: Non-empty list of filtered file entries per page.
    r@   r~   r   r   r   c                 3   s    d}d}	 z j 	
| d|d	}W n ty4 } ztd| d|  W Y d}~dS d}~ww |s9dS rEt|d}nd	d
 |D }|t|7 }|rW|V  td| d| dddd t|k rmdS |d7 }q)z2Yield filtered file pages for the given root_path.r   r   Tr   r   r   NrZ   c                 S   s   g | ]}| d dkr|qS )r
   r   r   r   rN   rN   rO   r     s    zE_iter_dataset_file_pages.<locals>._paginate_pages.<locals>.<listcomp>z  Fetched z matching files (z
 pages)... )endflush)r   r   rf   r   rq   rd   ro   )r   r   total_foundr   r   r   r   rN   rO   _paginate_pages  sd   

z1_iter_dataset_file_pages.<locals>._paginate_pagesFTz
  root_path='r   N)r   rn   r   r   ro   )rx   r3   r(   r8   r7   r^   r.   r-   r0   r1   r   r   r   r   r   Zyielded_anypagerN   r   rO   rv     s@   #

"7

rv   c                    s  d}d}g t  fdd tddddft|
dQ}| D ]F}|D ]A}|d7 }|_  ||rB|d7 }d q&|j|d	 ||||d
}|j	t
||||||	d|d	}||f fdd	 q&q"W d   n1 ssw   Y  W d   n1 sw   Y  rdd D }tt dddd |D   || t }td| d| d| drdt dnd d  rtt d| ddS )a_  Pipeline consumer: download dataset files as pages are yielded.

    Consumes the page iterator from _iter_dataset_file_pages, submitting
    each file to a thread pool for concurrent download. Uses tqdm for
    real-time progress and thread-safe error collection.

    Args:
        file_page_iter: Iterator yielding List[dict] file pages.
        cache: ModelFileSystemCache instance for dedup.
        temporary_cache_dir: Temp staging directory.
        repo_id: Dataset repo identifier.
        api: HubApi instance.
        dataset_name: Dataset name component.
        namespace: Owner/namespace component.
        headers: HTTP request headers.
        revision: Git revision.
        cookies: HTTP cookies.
        max_workers: Thread pool concurrency.
        endpoint: API endpoint URL.
        progress_callbacks: Optional progress callback list.
    r   c                    s   zQz|    W n: tyA } z.  ||f W d   n1 s#w   Y  td|dd d|  W Y d}~nd}~ww W d dS W d dS d w )z8Done callback: update progress bar and collect failures.NzDownload failed for r   ?z: r   )resultr   r   rf   debugrE   update)futurer   exc)failed_itemslockpbarrN   rO   _on_doneH  s   z,_pipeline_download_dataset.<locals>._on_donez filesF)totalunitdisable)r2   r   r   	file_namerb   rc   r(   r8   disable_tqdmr6   c                    s
    | |S r   rN   )r   rf)r   rN   rO   <lambda>x  s   
 z,_pipeline_download_dataset.<locals>.<lambda>Nc                 S   s.   g | ]\}}t |tr|d dnt|qS )r   r   )r   dictrE   rh   r   r   r   rN   rN   rO   r   ~  s    z._pipeline_download_dataset.<locals>.<listcomp> file(s) failed to download:

c                 s       | ]}d | V  qdS z  - NrN   r   rN   rN   rO   r         z-_pipeline_download_dataset.<locals>.<genexpr>zDownload complete: z files found, z	 cached, z downloadedz, z failedr   r\   # file(s) failed to download out of )	threadingLockr   r   r   refreshrs   r   get_dataset_file_urlZsubmitr   Zadd_done_callbackrf   r   rd   rH   ro   r   )r}   r_   r`   r3   ra   rb   rc   rY   r(   r,   r2   r8   r6   r   Ztotal_cachedexecutorZ
page_filesr   urlr   failed_pathsZ
downloadedrN   )r   r   r   r   rO   rw     s   $

(

rw   r_   r`   ra   r|   r{   r[   c                    s  |r&g }| D ] rtjd }td| d q| qnt|}t|}t|}t|}t|}g }| D ]d dkrGq>zm|rWt	fdd|D rWW q>|rft	fdd|D rfW q>|rut	fd	d|D ruW q>|d ur|rt	fd
d|D sW q>|d ur|rt	fdd|D sW q> rtjd }td| d W q>W n t
y } ztd|  W Y d }~q>d }~ww | q>t|ddd 	
fdd}t|dkrRtdt| d ||}g }t|tr3t|dkr3|\}}|r3dd |D }tt| dddd |D   tdt| d	 d |rTtt| dt| dd S d S ) Nr   zFile z8 already in cache with identical hash, skip downloading!r
   r   c                       g | ]
}t   d  |qS r   r   r   r   r   rN   rO   r         z(_download_file_lists.<locals>.<listcomp>c                    r   r   r   r   r   rN   rO   r     r   c                    s    g | ]}t | d  duqS r   r   r   r   rN   rO   r     s    c                 3   r   r   r   r   r   rN   rO   r     r   z'_download_file_lists.<locals>.<genexpr>c                 3   r   r   r   r   r   rN   rO   r     r   z The file pattern is invalid : %sFT)r2   r   Zfault_tolerantc              
      sp   	t krt| d 
d}n	tkr  j| d 
d}n
td	 dt t|| dd d S )Nr   )r'   	file_pathr(   r8   r   r:   z, supported types: Fr   )r   r   r   r   r   r   r   )r   r   )ra   r_   r,   r8   r{   rY   r|   r6   r3   r4   r(   r`   rN   rO   _download_single_file  s8   
z3_download_file_lists.<locals>._download_single_filer   zGot z files, start to download ...   c                 S   s*   g | ]\}}t |tr|d  nt|qS r   )r   r   rh   r   rN   rN   rO   r     s    r   r   c                 s   r   r   rN   r   rN   rN   rO   r     r   zFinish downloading z files for repo ''r   r\   )rs   rC   rG   basenamerf   r   r   rp   r   r   r   rg   r   rd   rl   r   tupler   rH   r   )rz   r_   r`   r3   ra   r|   r{   rY   r4   r(   r,   r-   r.   r0   r1   r2   r8   r6   r[   Zfiltered_repo_filesr   r   r   r   Zdownload_resultr   r   r   rN   )ra   r_   r,   r8   r{   rY   r|   r6   r   r3   r4   r(   r`   rO   rr     s   




$
rr   )Ir   rC   r   r   ri   concurrent.futuresr   
contextlibr   http.cookiejarr   pathlibr   typingr   r   r	   r
   r   Z	tqdm.autor   Zmodelscope.utils.constantr   r   r   r   r   r   Zmodelscope.utils.file_utilsr   Zmodelscope.utils.loggerr   Zmodelscope.utils.thread_utilsr   ra   r   r   callbackr   	constantsr   errorsr   r   Zfile_downloadr   r   r   Zutils.cachingr    Zutils.utilsr!   r"   r#   r$   r%   rf   ZDEFAULT_DATASET_PAGE_SIZErh   boolintrP   rS   rJ   r   r   rp   r   r   rq   rv   rw   rr   rN   rN   rN   rO   <module>   s   	


}	

g	


 W
k





H
 
{	

