tofu_leaderboard / uploads.py
Pratyush Maini
test
4b8641e
raw
history blame
2.21 kB
from email.utils import parseaddr
from huggingface_hub import HfApi
import os
import datetime
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"<p style='color: red; font-size: 20px; text-align: center;'>{msg}</p>"
def format_warning(msg):
return f"<p style='color: orange; font-size: 20px; text-align: center;'>{msg}</p>"
def format_log(msg):
return f"<p style='color: green; font-size: 20px; text-align: center;'>{msg}</p>"
def model_hyperlink(link, model_name):
return f'<a target="_blank" href="{link}" style="color: var(--link-text-color); text-decoration: underline;text-decoration-style: dotted;">{model_name}</a>'
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.")
print("Adding new eval")
# Check if the combination model/org already exists and prints a warning message if yes
# if model.lower() in set(eval_results[val_or_test]["model"]) and organisation.lower() in set(eval_results[val_or_test]["organisation"]):
# return format_warning("This model has been already submitted.")
if path_to_file is None:
return format_warning("Please attach a file.")
# Save submitted file
api.upload_file(
repo_id=LEADERBOARD_PATH,
path_or_fileobj=path_to_file.name,
path_in_repo=f"{organisation}/{model}/{YEAR_VERSION}_{val_or_test}_raw_{datetime.datetime.today()}.jsonl",
repo_type="spaces",
token=TOKEN
)
# Actual submission
eval_entry = {
"model": model,
"model_family": model_family,
"url": url,
"organisation": organisation,
"mail": mail,
"forget_rate": forget_rate,
}
return format_log(f"Model {model} submitted by {organisation} successfully. \nPlease refresh the leaderboard, and wait a bit to see the score displayed")