Upload catalog.py with huggingface_hub
Browse files12345678910111222 unmodified lines35363738394051 unmodified lines92939495969735 unmodified lines133134135import osimport refrom pathlib import Pathfrom typing import Optionalimport requestsfrom .artifact import Artifact, Artifactory, reset_artifacts_cachefrom .logging_utils import get_loggerfrom .version import versionlogger = get_logger()22 unmodified linesclass LocalCatalog(Catalog):name: str = "local"location: str = default_catalog_pathdef path(self, artifact_identifier: str):assert (51 unmodified linesrepo = "unitxt"repo_dir = "src/unitxt/catalog"user = "IBM"def prepare(self):tag = version35 unmodified linesartifact, name, overwrite=overwrite, verbose=verbose) # remove collection (its actually the dir).# verify name123456789101112131422 unmodified lines3738394041424351 unmodified lines959697989910010135 unmodified lines137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173import osimport refrom collections import Counterfrom pathlib import Pathfrom typing import Optionalimport requestsfrom .artifact import Artifact, Artifactories, Artifactory, reset_artifacts_cachefrom .logging_utils import get_loggerfrom .text_utils import print_dictfrom .version import versionlogger = get_logger()22 unmodified linesclass LocalCatalog(Catalog):name: str = "local"location: str = default_catalog_pathis_local: bool = Truedef path(self, artifact_identifier: str):assert (51 unmodified linesrepo = "unitxt"repo_dir = "src/unitxt/catalog"user = "IBM"is_local: bool = Falsedef prepare(self):tag = version35 unmodified linesartifact, name, overwrite=overwrite, verbose=verbose) # remove collection (its actually the dir).# verify namedef get_local_catalogs_paths():result = []for artifactory in Artifactories():if isinstance(artifactory, LocalCatalog):if artifactory.is_local:result.append(artifactory.location)return resultdef count_files_recursively(folder):file_count = 0for _, _, files in os.walk(folder):file_count += len(files)return file_countdef 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 resultdef summary():result = Counter()for local_catalog_path in get_local_catalogs_paths():result += Counter(local_catalog_summary(local_catalog_path))print_dict(result)return result
catalog.py+39-1