from email.utils import parseaddr from huggingface_hub import HfApi import os import datetime import pandas as pd OWNER="locuslab" LEADERBOARD_PATH = f"{OWNER}/tofu_leaderboard" api = HfApi() TOKEN = os.environ.get("TOKEN", None) YEAR_VERSION = "2024" def format_error(msg): return f"
{msg}
" def format_warning(msg): return f"{msg}
" def format_log(msg): return f"{msg}
" def model_hyperlink(link, model_name): return f'{model_name}' def add_new_eval( model: str, model_family: str, forget_rate: str, url: str, path_to_file: str, organisation: str, mail: str, ): # Very basic email parsing _, parsed_mail = parseaddr(mail) if not "@" in parsed_mail: return format_warning("Please provide a valid email adress.") return format_log(f"Model {model} submitted by {organisation} successfully. \nPlease refresh the leaderboard, and wait a bit to see the score displayed") file_value = path_to_file.value if file_value is None: return format_warning("Please attach a file.") # load the file df = pd.read_csv(file_value) # modify the df to include metadata df["model"] = model df["model_family"] = model_family df["forget_rate"] = forget_rate df["url"] = url df["organisation"] = organisation df["mail"] = mail df["timestamp"] = datetime.datetime.now() #upload to spaces using the hf api at RESULTS_PATH = "locuslab/tofu_leaderboard" path_in_repo = f"versions/{model_family}-{forget_rate.replace('%', 'p')}" file_name = f"{model}-{organisation}-{datetime.datetime.now().strftime('%Y-%m-%d')}.csv" # upload the df to spaces new_file = df.to_csv(index=False) api.upload_file( repo_id = RESULTS_PATH, path_in_repo = f"{path_in_repo}/{file_name}", file_name = file_value, token=TOKEN, repo_type="space", )