Download cli.py from abulte/datagouvfr-datasets: direct link, hf CLI and curl.
- Browser
- Download file 1.36 kB
-
https://huggingface.co/datasets/abulte/datagouvfr-datasets/resolve/refs%2Fpr%2F3/cli.py
- Command line
-
hf download hf://datasets/abulte/datagouvfr-datasets@refs/pr/3/cli.py
-
curl -L -o cli.py https://huggingface.co/datasets/abulte/datagouvfr-datasets/resolve/refs%2Fpr%2F3/cli.py
1.36 kB
| import csv | |
| import sys | |
| from pathlib import Path | |
| from datasets import load_dataset | |
| from markdown_it import MarkdownIt | |
| from mdit_plain.renderer import RendererPlain | |
| from minicli import cli, run | |
| from progressist import ProgressBar | |
| csv.field_size_limit(sys.maxsize) | |
| catalog = Path("datasets-filtered.csv") | |
| def generate(): | |
| """ | |
| Loads catalog, parse markdown description, return concatenated title and description | |
| """ | |
| print("Loading corpus...") | |
| corpus = [] | |
| parser = MarkdownIt(renderer_cls=RendererPlain) | |
| with catalog.open() as f: | |
| reader = csv.DictReader(f) | |
| lines = list(reader) | |
| bar = ProgressBar(total=len(lines)) | |
| for line in bar.iter(lines): | |
| description = parser.render(line["description"]) | |
| corpus.append({ | |
| "id": line["id"], | |
| "content": f'{line["title"]} {description}', | |
| "tags": line["tags"], | |
| }) | |
| with open("data/datagouvfr-datasets.csv", "w") as f: | |
| writer = csv.DictWriter(f, fieldnames=["id", "content", "tags"]) | |
| writer.writeheader() | |
| writer.writerows(corpus) | |
| return corpus | |
| def inspect(): | |
| ds = load_dataset("abulte/datagouvfr-datasets", split="train") | |
| print(list(zip(ds["id"][:10], ds["content"][:10], ds["tags"][:10]))) | |
| if __name__ == "__main__": | |
| run() | |