Upload catalog.py with huggingface_hub
Browse files1234567889101112131422 unmodified lines3738394041424351 unmodified lines959697989910010135 unmodified lines137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173import osimport refrom collections import Counterfrom pathlib import Pathfrom typing import Optional
import requests
from .artifact import Artifact, Artifactory, reset_artifacts_cachefrom .artifact import Artifact, Artifactories, Artifactory, reset_artifacts_cachefrom .logging_utils import get_loggerfrom .text_utils import print_dictfrom .version import version
logger = get_logger()22 unmodified linesclass LocalCatalog(Catalog): name: str = "local" location: str = default_catalog_path is_local: bool = True
def path(self, artifact_identifier: str): assert (51 unmodified lines repo = "unitxt" repo_dir = "src/unitxt/catalog" user = "IBM" is_local: bool = False
def prepare(self): tag = version35 unmodified lines artifact, name, overwrite=overwrite, verbose=verbose ) # remove collection (its actually the dir). # verify name
def get_local_catalogs_paths(): result = [] for artifactory in Artifactories(): if isinstance(artifactory, LocalCatalog): if artifactory.is_local: result.append(artifactory.location) return result
def count_files_recursively(folder): file_count = 0 for _, _, files in os.walk(folder): file_count += len(files) return file_count
def local_catalog_summary(catalog_path): result = {}
for dir in os.listdir(catalog_path): if os.path.isdir(os.path.join(catalog_path, dir)): result[dir] = count_files_recursively(os.path.join(catalog_path, dir))
return result
def summary(): result = Counter() for local_catalog_path in get_local_catalogs_paths(): result += Counter(local_catalog_summary(local_catalog_path)) print_dict(result) return resultcatalog.py+39-1