Add dataset cards (#363)

This commit is contained in:
Simon Alibert
2024-08-16 10:08:44 +02:00
committed by GitHub
parent bbe9057225
commit b98ea415c1
4 changed files with 49 additions and 4 deletions

View File

@@ -23,11 +23,19 @@ from typing import Dict
import datasets
import torch
from datasets import load_dataset, load_from_disk
from huggingface_hub import HfApi, hf_hub_download, snapshot_download
from huggingface_hub import DatasetCard, HfApi, hf_hub_download, snapshot_download
from PIL import Image as PILImage
from safetensors.torch import load_file
from torchvision import transforms
DATASET_CARD_TEMPLATE = """
---
# Metadata will go there
---
This dataset was created using [🤗 LeRobot](https://github.com/huggingface/lerobot).
"""
def flatten_dict(d, parent_key="", sep="/"):
"""Flatten a nested dictionary structure by collapsing nested keys into one key with a separator.
@@ -400,3 +408,14 @@ def create_branch(repo_id, *, branch: str, repo_type: str | None = None):
api.delete_branch(repo_id, repo_type=repo_type, branch=branch)
api.create_branch(repo_id, repo_type=repo_type, branch=branch)
def create_lerobot_dataset_card(tags: list | None = None, text: str | None = None) -> DatasetCard:
card = DatasetCard(DATASET_CARD_TEMPLATE)
card.data.task_categories = ["robotics"]
card.data.tags = ["LeRobot"]
if tags is not None:
card.data.tags += tags
if text is not None:
card.text += text
return card