Datasets:

Languages:
English
ArXiv:
License:
mariosasko commited on
Commit
52d91f7
1 Parent(s): c5555b0

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

Files changed (1) hide show
  1. README.md +4 -1
README.md CHANGED
@@ -74,13 +74,16 @@ from datasets import load_dataset
74
  from datasets.utils.file_utils import get_datasets_user_agent
75
 
76
 
 
 
 
77
  def fetch_single_image(image_url, timeout=None, retries=0):
78
  for _ in range(retries + 1):
79
  try:
80
  request = urllib.request.Request(
81
  image_url,
82
  data=None,
83
- headers={"user-agent": get_datasets_user_agent()},
84
  )
85
  with urllib.request.urlopen(request, timeout=timeout) as req:
86
  image = PIL.Image.open(io.BytesIO(req.read()))
 
74
  from datasets.utils.file_utils import get_datasets_user_agent
75
 
76
 
77
+ USER_AGENT = 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": USER_AGENT},
87
  )
88
  with urllib.request.urlopen(request, timeout=timeout) as req:
89
  image = PIL.Image.open(io.BytesIO(req.read()))