mirror of
https://github.com/OpenBMB/MiniCPM-V.git
synced 2026-02-05 18:29:18 +08:00
Modify eval_mm for MiniCPM-o 2.6
This commit is contained in:
@@ -74,6 +74,20 @@ def LMUDataRoot():
|
||||
return root
|
||||
|
||||
|
||||
def HFCacheRoot():
|
||||
cache_list = ['HUGGINGFACE_HUB_CACHE', 'HF_HOME']
|
||||
for cache_name in cache_list:
|
||||
if cache_name in os.environ and osp.exists(os.environ[cache_name]):
|
||||
if os.environ[cache_name].split('/')[-1] == 'hub':
|
||||
return os.environ[cache_name]
|
||||
else:
|
||||
return osp.join(os.environ[cache_name], 'hub')
|
||||
home = osp.expanduser('~')
|
||||
root = osp.join(home, '.cache', 'huggingface', 'hub')
|
||||
os.makedirs(root, exist_ok=True)
|
||||
return root
|
||||
|
||||
|
||||
def MMBenchOfficialServer(dataset_name):
|
||||
root = LMUDataRoot()
|
||||
|
||||
@@ -190,20 +204,20 @@ def download_file(url, filename=None):
|
||||
if filename is None:
|
||||
filename = url.split('/')[-1]
|
||||
|
||||
# If HF_ENDPOINT is set, replace huggingface.co with it
|
||||
if 'huggingface.co' in url and os.environ.get('HF_ENDPOINT', '') != '':
|
||||
url = url.replace('huggingface.co', os.environ['HF_ENDPOINT'].split('://')[1])
|
||||
|
||||
try:
|
||||
with DownloadProgressBar(unit='B', unit_scale=True, miniters=1, desc=url.split('/')[-1]) as t:
|
||||
urllib.request.urlretrieve(url, filename=filename, reporthook=t.update_to)
|
||||
except:
|
||||
except Exception as e:
|
||||
import logging
|
||||
logging.warning(f'{type(e)}: {e}')
|
||||
# Handle Failed Downloads from huggingface.co
|
||||
if 'huggingface.co' in url:
|
||||
url_new = url.replace('huggingface.co', 'hf-mirror.com')
|
||||
try:
|
||||
os.system(f'wget {url_new} -O {filename}')
|
||||
except:
|
||||
download_file(url_new, filename)
|
||||
return filename
|
||||
except Exception as e:
|
||||
logging.warning(f'{type(e)}: {e}')
|
||||
raise Exception(f'Failed to download {url}')
|
||||
else:
|
||||
raise Exception(f'Failed to download {url}')
|
||||
@@ -286,6 +300,18 @@ def parse_file(s):
|
||||
suffix = osp.splitext(s)[1].lower()
|
||||
mime = mimetypes.types_map.get(suffix, 'unknown')
|
||||
return (mime, s)
|
||||
elif s.startswith('data:image/'):
|
||||
# To be compatible with OPENAI base64 format
|
||||
content = s[11:]
|
||||
mime = content.split(';')[0]
|
||||
content = ';'.join(content.split(';')[1:])
|
||||
dname = osp.join(LMUDataRoot(), 'files')
|
||||
assert content.startswith('base64,')
|
||||
b64 = content[7:]
|
||||
os.makedirs(dname, exist_ok=True)
|
||||
tgt = osp.join(dname, md5(b64) + '.png')
|
||||
decode_base64_to_image_file(b64, tgt)
|
||||
return parse_file(tgt)
|
||||
elif validators.url(s):
|
||||
suffix = osp.splitext(s)[1].lower()
|
||||
if suffix in mimetypes.types_map:
|
||||
|
||||
Reference in New Issue
Block a user