Switch from cached_download to hf_hub_download in remaining occurrences (#31284)

Switch from hf_hub_url to hf_hub_download in remaining occurences
This commit is contained in:
Lucain
2024-06-06 13:05:59 +02:00
committed by GitHub
parent 5fabd1e83b
commit 9ef93fccad
12 changed files with 29 additions and 24 deletions

View File

@@ -245,11 +245,12 @@ You'll also want to create a dictionary that maps a label id to a label class wh
```py
>>> import json
>>> from huggingface_hub import cached_download, hf_hub_url
>>> from pathlib import Path
>>> from huggingface_hub import hf_hub_download
>>> repo_id = "huggingface/label-files"
>>> filename = "ade20k-id2label.json"
>>> id2label = json.load(open(cached_download(hf_hub_url(repo_id, filename, repo_type="dataset")), "r"))
>>> id2label = json.loads(Path(hf_hub_download(repo_id, filename, repo_type="dataset")).read_text())
>>> id2label = {int(k): v for k, v in id2label.items()}
>>> label2id = {v: k for k, v in id2label.items()}
>>> num_labels = len(id2label)

View File

@@ -83,11 +83,12 @@ pip install -q datasets transformers evaluate
```py
>>> import json
>>> from huggingface_hub import cached_download, hf_hub_url
>>> from pathlib import Path
>>> from huggingface_hub import hf_hub_download
>>> repo_id = "huggingface/label-files"
>>> filename = "ade20k-id2label.json"
>>> id2label = json.load(open(cached_download(hf_hub_url(repo_id, filename, repo_type="dataset")), "r"))
>>> id2label = json.loads(Path(hf_hub_download(repo_id, filename, repo_type="dataset")).read_text())
>>> id2label = {int(k): v for k, v in id2label.items()}
>>> label2id = {v: k for k, v in id2label.items()}
>>> num_labels = len(id2label)

View File

@@ -83,11 +83,12 @@ pip install -q datasets transformers evaluate
```py
>>> import json
>>> from huggingface_hub import cached_download, hf_hub_url
>>> from pathlib import Path
>>> from huggingface_hub import hf_hub_download
>>> repo_id = "huggingface/label-files"
>>> filename = "ade20k-id2label.json"
>>> id2label = json.load(open(cached_download(hf_hub_url(repo_id, filename, repo_type="dataset")), "r"))
>>> id2label = json.loads(Path(hf_hub_download(repo_id, filename, repo_type="dataset")).read_text())
>>> id2label = {int(k): v for k, v in id2label.items()}
>>> label2id = {v: k for k, v in id2label.items()}
>>> num_labels = len(id2label)

View File

@@ -82,11 +82,12 @@ pip install -q datasets transformers evaluate
```py
>>> import json
>>> from huggingface_hub import cached_download, hf_hub_url
>>> from pathlib import Path
>>> from huggingface_hub import hf_hub_download
>>> repo_id = "huggingface/label-files"
>>> filename = "ade20k-id2label.json"
>>> id2label = json.load(open(cached_download(hf_hub_url(repo_id, filename, repo_type="dataset")), "r"))
>>> id2label = json.loads(Path(hf_hub_download(repo_id, filename, repo_type="dataset")).read_text())
>>> id2label = {int(k): v for k, v in id2label.items()}
>>> label2id = {v: k for k, v in id2label.items()}
>>> num_labels = len(id2label)