|
import json
|
|
import uuid
|
|
import os
|
|
import re
|
|
from huggingface_hub import HfApi
|
|
from huggingface_hub import hf_hub_download
|
|
|
|
|
|
|
|
def file_name_decode(file_name):
|
|
|
|
|
|
|
|
match = re.match(rf'\[([^\[^\]]+)\]\[([^\[^\]]+)\]\[([^\[^\]]+)\]([^\[^\]]+)', file_name)
|
|
|
|
if match:
|
|
model_name, dataset, method, file_name = match.groups()
|
|
ret_dict = {
|
|
'model_name': model_name,
|
|
'dataset': dataset,
|
|
'method': method,
|
|
'file_name': file_name
|
|
}
|
|
return ret_dict
|
|
return None
|
|
|
|
def upload_scores_to_hub(api, scores_dict, path_in_repo,hub_repo='zhaorui-nb/test_json'):
|
|
|
|
save_json_path = f'.output/upload.json'
|
|
os.makedirs(os.path.dirname(save_json_path), exist_ok=True)
|
|
with open(save_json_path, 'w') as f:
|
|
json.dump(scores_dict, f , indent=4)
|
|
|
|
|
|
res = api.upload_file(
|
|
path_or_fileobj=save_json_path,
|
|
path_in_repo=path_in_repo,
|
|
repo_id=hub_repo,
|
|
repo_type="dataset",
|
|
)
|
|
|
|
return res
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|