MCPcopy
hub / github.com/open-compass/VLMEvalKit / download_file

Function download_file

vlmeval/smp/file.py:201–232  ·  view source on GitHub ↗
(url, filename=None)

Source from the content-addressed store, hash-verified

199
200
201def download_file(url, filename=None):
202 import urllib.request
203 from tqdm import tqdm
204
205 class DownloadProgressBar(tqdm):
206 def update_to(self, b=1, bsize=1, tsize=None):
207 if tsize is not None:
208 self.total = tsize
209 self.update(b * bsize - self.n)
210
211 if filename is None:
212 filename = url.split('/')[-1]
213
214 try:
215 with DownloadProgressBar(unit='B', unit_scale=True, miniters=1, desc=url.split('/')[-1]) as t:
216 urllib.request.urlretrieve(url, filename=filename, reporthook=t.update_to)
217 except Exception as e:
218 import logging
219 logging.warning(f'{type(e)}: {e}')
220 # Handle Failed Downloads from huggingface.co
221 if 'huggingface.co' in url:
222 url_new = url.replace('huggingface.co', 'hf-mirror.com')
223 try:
224 download_file(url_new, filename)
225 return filename
226 except Exception as e:
227 logging.warning(f'{type(e)}: {e}')
228 raise Exception(f'Failed to download {url}')
229 else:
230 raise Exception(f'Failed to download {url}')
231
232 return filename
233
234
235def ls(dirname='.', match=[], mode='all', level=1):

Callers 10

prepare_tsvMethod · 0.85
load_dataMethod · 0.85
prepare_tsvMethod · 0.85
prepare_tsvMethod · 0.85
post_buildMethod · 0.85
prepare_tsvMethod · 0.85
__init__Method · 0.85
__init__Method · 0.85
loadFunction · 0.85
parse_fileFunction · 0.85

Calls 1

DownloadProgressBarClass · 0.85

Tested by

no test coverage detected