mariosasko
commited on
Commit
·
9c38607
1
Parent(s):
bf651cd
Make code for image downloading from image urls cacheable (#4218)
Browse files* Make code for image downloading from image urls cacheable
* Minor improvement in RedCaps card
* Minor fixes in formatting
Commit from https://github.com/huggingface/datasets/commit/6a201a6f8fb8837f37925e38c4cc69e92155120f
README.md
CHANGED
@@ -77,13 +77,16 @@ from datasets import load_dataset
|
|
77 |
from datasets.utils.file_utils import get_datasets_user_agent
|
78 |
|
79 |
|
|
|
|
|
|
|
80 |
def fetch_single_image(image_url, timeout=None, retries=0):
|
81 |
for _ in range(retries + 1):
|
82 |
try:
|
83 |
request = urllib.request.Request(
|
84 |
image_url,
|
85 |
data=None,
|
86 |
-
headers={"user-agent":
|
87 |
)
|
88 |
with urllib.request.urlopen(request, timeout=timeout) as req:
|
89 |
image = PIL.Image.open(io.BytesIO(req.read()))
|
|
|
77 |
from datasets.utils.file_utils import get_datasets_user_agent
|
78 |
|
79 |
|
80 |
+
USER_AGENT = get_datasets_user_agent()
|
81 |
+
|
82 |
+
|
83 |
def fetch_single_image(image_url, timeout=None, retries=0):
|
84 |
for _ in range(retries + 1):
|
85 |
try:
|
86 |
request = urllib.request.Request(
|
87 |
image_url,
|
88 |
data=None,
|
89 |
+
headers={"user-agent": USER_AGENT},
|
90 |
)
|
91 |
with urllib.request.urlopen(request, timeout=timeout) as req:
|
92 |
image = PIL.Image.open(io.BytesIO(req.read()))
|