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

Function parse_file

vlmeval/smp/file.py:304–334  ·  view source on GitHub ↗
(s)

Source from the content-addressed store, hash-verified

302
303
304def parse_file(s):
305 if osp.exists(s) and s != '.':
306 assert osp.isfile(s)
307 suffix = osp.splitext(s)[1].lower()
308 mime = mimetypes.types_map.get(suffix, 'unknown')
309 return (mime, s)
310 elif s.startswith('data:image/'):
311 # To be compatible with OPENAI base64 format
312 content = s[11:]
313 mime = content.split(';')[0]
314 content = ';'.join(content.split(';')[1:])
315 dname = osp.join(LMUDataRoot(), 'files')
316 assert content.startswith('base64,')
317 b64 = content[7:]
318 os.makedirs(dname, exist_ok=True)
319 tgt = osp.join(dname, md5(b64) + '.png')
320 decode_base64_to_image_file(b64, tgt)
321 return parse_file(tgt)
322 elif validators.url(s):
323 suffix = osp.splitext(s)[1].lower()
324 if suffix in mimetypes.types_map:
325 mime = mimetypes.types_map[suffix]
326 dname = osp.join(LMUDataRoot(), 'files')
327 os.makedirs(dname, exist_ok=True)
328 tgt = osp.join(dname, md5(s) + suffix)
329 download_file(s, tgt)
330 return (mime, tgt)
331 else:
332 return ('url', s)
333 else:
334 return (None, s)
335
336
337def file_size(f, unit='GB'):

Callers 2

preproc_contentMethod · 0.85
preproc_contentMethod · 0.85

Calls 5

LMUDataRootFunction · 0.85
md5Function · 0.85
download_fileFunction · 0.85
getMethod · 0.80

Tested by

no test coverage detected