Skip to content

Commit

Permalink
Merge pull request #5226 from voxel51/list-hf-hub-datasets
Browse files Browse the repository at this point in the history
List hf hub datasets
  • Loading branch information
brimoor authored Dec 25, 2024
2 parents 760b3e0 + 03e41a1 commit 18dde78
Showing 1 changed file with 30 additions and 8 deletions.
38 changes: 30 additions & 8 deletions fiftyone/utils/huggingface.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,6 @@
callback=lambda: fou.ensure_package("huggingface_hub>=0.20.0"),
)

hfu = fou.lazy_import(
"huggingface_hub.utils",
callback=lambda: fou.ensure_package("huggingface_hub>=0.20.0"),
)


DATASETS_SERVER_URL = "https://datasets-server.huggingface.co"
DEFAULT_MEDIA_TYPE = "image"
Expand All @@ -64,6 +59,33 @@
logger = logging.getLogger(__name__)


def list_hub_datasets(info=False):
"""Lists all FiftyOne datasets available on the Hugging Face Hub.
This method includes all datasets that are tagged to the ``FiftyOne``
library in Hugging Face.
Examples::
from fiftyone.utils.huggingface import list_hub_datasets
datasets = list_hub_datasets()
print(datasets)
Args:
info (False): whether to return dataset names (False) or
``huggingface_hub.hf_api.DatasetInfo`` objects (True)
Returns:
a list of dataset names or objects
"""
datasets = list(hfh.list_datasets(filter="library:fiftyone"))
if info:
return datasets

return [dataset.id for dataset in datasets]


def push_to_hub(
dataset,
repo_name,
Expand Down Expand Up @@ -678,14 +700,14 @@ def _count_samples(sample_collection):

@contextmanager
def _no_progress_bars():
pbs_disabled = hfu.are_progress_bars_disabled()
hfu.disable_progress_bars()
pbs_disabled = hfh.utils.are_progress_bars_disabled()
hfh.utils.disable_progress_bars()
try:
yield
finally:
# Restore the original state
if not pbs_disabled:
hfu.enable_progress_bars()
hfh.utils.enable_progress_bars()


class HFHubParquetFilesDatasetConfig(HFHubDatasetConfig):
Expand Down

0 comments on commit 18dde78

Please sign in to comment.