Skip to content

List hf hub datasets #5226

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

Merged
merged 4 commits into from
Dec 25, 2024
Merged

List hf hub datasets #5226

merged 4 commits into from
Dec 25, 2024

Conversation

harpreetsahota204
Copy link
Contributor

@harpreetsahota204 harpreetsahota204 commented Dec 5, 2024

What changes are proposed in this pull request?

Added proper documentation and improved implementation of the list_hub_datasets() function in fiftyone/utils/huggingface.py. The changes include:

  • Added comprehensive docstring explaining function purpose and usage
  • Improved code readability with clear comments

How is this patch tested? If it is not, please explain why.

The changes can be tested by:

  1. Running the function directly:
from fiftyone.utils.huggingface import list_hub_datasets
list_hub_datasets()
  1. Checking the docstring help:
help(list_hub_datasets)

Release Notes

Is this a user-facing change that should be mentioned in the release notes?

  • No. You can skip the rest of this section.
  • Yes. You can now easily list the datasets we have on our HF org

Added documentation and improved implementation of list_hub_datasets() function, making it easier for users to discover and load FiftyOne datasets from the Hugging Face Hub.

What areas of FiftyOne does this PR affect?

  • App: FiftyOne application changes
  • Build: Build and test infrastructure changes
  • [] Core: Core fiftyone Python library changes
  • Documentation: FiftyOne documentation changes
  • Other: utils/huggingface.py

Summary by CodeRabbit

  • New Features
    • Introduced a new function to list all FiftyOne datasets available on the Hugging Face Hub, enhancing user access to discoverable datasets.

@harpreetsahota204 harpreetsahota204 added the enhancement Code enhancement label Dec 5, 2024
@harpreetsahota204 harpreetsahota204 self-assigned this Dec 5, 2024
Copy link
Contributor

coderabbitai bot commented Dec 5, 2024

Walkthrough

A new function named list_hub_datasets has been introduced in the fiftyone/utils/huggingface.py file. This function retrieves and lists all FiftyOne datasets available on the Hugging Face Hub, utilizing the hfh.list_datasets method. It includes a detailed docstring with usage examples and specifies that it returns a generator of dataset objects containing metadata about each dataset published by Voxel51. The addition does not alter existing functionalities or the overall structure of the module.

Changes

File Path Change Summary
fiftyone/utils/huggingface.py Added list_hub_datasets function to list datasets from Hugging Face Hub. Removed lazy import of huggingface_hub.utils and updated references.

Possibly related PRs

  • Docs integration updates #4940: The changes in this PR involve updates to the documentation for the Hugging Face integration, which is directly related to the new list_hub_datasets function added in the main PR, as both pertain to managing datasets from the Hugging Face Hub.

Suggested reviewers

  • mwoodson1

🐰 In the meadow, datasets bloom,
Hugging Face Hub, there's plenty of room.
With list_hub_datasets, we now can see,
All the treasures, just waiting for thee!
Hop along, discover with glee,
The datasets await, come join the spree! 🌼


📜 Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between ac80a8d and 03e41a1.

📒 Files selected for processing (1)
  • fiftyone/utils/huggingface.py (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • fiftyone/utils/huggingface.py

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🧹 Outside diff range and nitpick comments (2)
fiftyone/utils/huggingface.py (2)

67-72: Documentation could be more comprehensive.

The docstring should include:

  • Return value description
  • Possible exceptions
  • Example usage with expected output
 def list_hub_datasets():
     """Lists all FiftyOne datasets available on the Hugging Face Hub.
 
     This function prints instructions for loading datasets and displays a list of
     all datasets published by Voxel51 on the Hugging Face Hub.
+
+    Returns:
+        None
+
+    Raises:
+        huggingface_hub.utils.HfHubHTTPError: If there are connectivity issues
+            or authentication errors with the Hugging Face Hub.
+
+    Example:
+        >>> import fiftyone.utils.huggingface as fhub
+        >>> fhub.list_hub_datasets()
+        You can load any of the following datasets as follows:
+
+        from fiftyone.utils.huggingface import load_from_hub
+        dataset = load_from_hub("Voxel51/dataset-name")
+
+        Datasets on the Hugging Face Hub:
+
+        quickstart
+        open-images-v7
+        ...
     """

67-85: Consider performance optimization for large dataset listings.

The current implementation might be inefficient for organizations with many datasets.

Consider implementing pagination or limiting the number of datasets retrieved at once:

def list_hub_datasets(limit=None):
    """Lists FiftyOne datasets available on the Hugging Face Hub.
    
    Args:
        limit (None): Optional maximum number of datasets to list
    """
    try:
        datasets = list_datasets(author="Voxel51")
        if limit:
            datasets = itertools.islice(datasets, limit)
            
        print('You can load any of the following datasets as follows:\n')
        print('from fiftyone.utils.huggingface import load_from_hub')
        print('dataset = load_from_hub("Voxel51/dataset-name")\n')
        print('Datasets on the Hugging Face Hub:\n')
        
        for dataset in datasets:
            dataset_name = dataset.id.split('Voxel51/')[-1]
            print(dataset_name)
            
    except Exception as e:
        logger.error(f"Failed to fetch datasets from Hugging Face Hub: {e}")
        raise
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 1649f2f and 3455030.

📒 Files selected for processing (1)
  • fiftyone/utils/huggingface.py (2 hunks)
🔇 Additional comments (1)
fiftyone/utils/huggingface.py (1)

Line range hint 34-42: Verify huggingface_hub dependency version compatibility.

The new list_hub_datasets() function relies on the list_datasets function from huggingface_hub. Ensure it's compatible with the minimum version requirement.

✅ Verification successful

Dependency version requirement is compatible with the implementation

The implementation of list_hub_datasets() uses list_datasets from huggingface_hub, and the minimum version requirement is set to >=0.20.0. The list_datasets function has been a core feature of huggingface_hub since well before version 0.20.0, making this implementation safe and compatible with the specified version constraint.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check if list_datasets is available in the minimum required version

# Get the minimum required version from the lazy import
min_version=$(rg -A 1 'huggingface_hub.*callback.*ensure_package' | grep -o '[0-9]\+\.[0-9]\+\.[0-9]\+')

# Check when list_datasets was introduced in huggingface_hub
gh api graphql -f query='
{
  repository(owner: "huggingface", name: "huggingface_hub") {
    object(expression: "main") {
      ... on Commit {
        history(first: 1, path: "src/huggingface_hub/hf_api.py", search: "def list_datasets") {
          nodes {
            associatedPullRequests(first: 1) {
              nodes {
                title
                mergedAt
              }
            }
          }
        }
      }
    }
  }
}'

Length of output: 901


Script:

#!/bin/bash
# Let's try a different approach to verify the dependency compatibility

# Search for list_datasets usage in the codebase
rg "list_datasets" -B 2 -A 2

# Check the actual implementation to understand the dependency
ast-grep --pattern 'def list_hub_datasets($$$)'

Length of output: 15882


Script:

#!/bin/bash
# Let's check the actual implementation of list_hub_datasets and its usage of huggingface_hub

# Find the implementation of list_hub_datasets
rg -B 5 -A 10 "def list_hub_datasets"

# Check the huggingface_hub version requirement in other files
rg -g "*.py" "huggingface.*>=[0-9]+\.[0-9]+\.[0-9]+"

Length of output: 1324

Copy link
Contributor

@brimoor brimoor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Returns:
a list of dataset names or objects
"""
datasets = list(hfh.list_datasets(filter="library:fiftyone"))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This used to be author="Voxel51" but I switched it to filter="library:fiftyone" so that we include all FiftyOne-compatible datasets

@brimoor brimoor enabled auto-merge December 25, 2024 19:37
@brimoor brimoor disabled auto-merge December 25, 2024 21:14
@brimoor brimoor merged commit 18dde78 into develop Dec 25, 2024
12 of 14 checks passed
@brimoor brimoor deleted the list-hf-hub-datasets branch December 25, 2024 21:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Code enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants