Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add catalog summary printing functionality #519

Merged
merged 2 commits into from
Jan 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,14 @@ In the dynamic landscape of generative NLP, traditional text processing pipeline

https://github.com/IBM/unitxt/assets/23455264/baef9131-39d4-4164-90b2-05da52919fdf

### 🦄 Currently on Unitxt Catalog

![NLP Tasks](https://img.shields.io/badge/NLP_tasks-21-blue)
![Dataset Cards](https://img.shields.io/badge/Dataset_Cards-377-blue)
![Templates](https://img.shields.io/badge/Templates-143-blue)
![Formats](https://img.shields.io/badge/Formats-7-blue)
![Metrics](https://img.shields.io/badge/Metrics-47-blue)

### 🦄 Run Unitxt Exploration Dashboard

To launch unitxt graphical user interface run:
Expand Down
40 changes: 39 additions & 1 deletion src/unitxt/catalog.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import os
import re
from collections import Counter
from pathlib import Path
from typing import Optional

import requests

from .artifact import Artifact, Artifactory, reset_artifacts_cache
from .artifact import Artifact, Artifactories, Artifactory, reset_artifacts_cache
from .logging_utils import get_logger
from .text_utils import print_dict
from .version import version

logger = get_logger()
Expand Down Expand Up @@ -35,6 +37,7 @@
class LocalCatalog(Catalog):
name: str = "local"
location: str = default_catalog_path
is_local: bool = True

def path(self, artifact_identifier: str):
assert (
Expand Down Expand Up @@ -92,6 +95,7 @@
repo = "unitxt"
repo_dir = "src/unitxt/catalog"
user = "IBM"
is_local: bool = False

def prepare(self):
tag = version
Expand Down Expand Up @@ -133,3 +137,37 @@
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

Check warning on line 148 in src/unitxt/catalog.py

View check run for this annotation

Codecov / codecov/patch

src/unitxt/catalog.py#L143-L148

Added lines #L143 - L148 were not covered by tests


def count_files_recursively(folder):
file_count = 0
for _, _, files in os.walk(folder):
file_count += len(files)
return file_count

Check warning on line 155 in src/unitxt/catalog.py

View check run for this annotation

Codecov / codecov/patch

src/unitxt/catalog.py#L152-L155

Added lines #L152 - L155 were not covered by tests


def local_catalog_summary(catalog_path):
result = {}

Check warning on line 159 in src/unitxt/catalog.py

View check run for this annotation

Codecov / codecov/patch

src/unitxt/catalog.py#L159

Added line #L159 was not covered by tests

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))

Check warning on line 163 in src/unitxt/catalog.py

View check run for this annotation

Codecov / codecov/patch

src/unitxt/catalog.py#L161-L163

Added lines #L161 - L163 were not covered by tests

return result

Check warning on line 165 in src/unitxt/catalog.py

View check run for this annotation

Codecov / codecov/patch

src/unitxt/catalog.py#L165

Added line #L165 was not covered by tests


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 result

Check warning on line 173 in src/unitxt/catalog.py

View check run for this annotation

Codecov / codecov/patch

src/unitxt/catalog.py#L169-L173

Added lines #L169 - L173 were not covered by tests
Loading