File size: 2,575 Bytes
ae02377 815b0dc f3fe9b4 8ec4d2d ae02377 815b0dc f3fe9b4 5839973 815b0dc ae02377 815b0dc ae02377 815b0dc d5ca063 815b0dc ae02377 3ea1b9b ae02377 815b0dc ae02377 3ea1b9b ae02377 3ea1b9b ae02377 d5ca063 3ea1b9b |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
import json
from dataclasses import dataclass
from datetime import datetime
from huggingface_hub import hf_hub_download
from huggingface_hub.utils._errors import EntryNotFoundError
from loguru import logger
@dataclass
class CompetitionInfo:
competition_id: str
autotrain_token: str
def __post_init__(self):
try:
config_fname = hf_hub_download(
repo_id=self.competition_id,
filename="conf",
use_auth_token=self.autotrain_token,
repo_type="dataset",
)
competition_desc = hf_hub_download(
repo_id=self.competition_id,
filename="COMPETITION_DESC.md",
use_auth_token=self.autotrain_token,
repo_type="dataset",
)
dataset_desc = hf_hub_download(
repo_id=self.competition_id,
filename="DATASET_DESC.md",
use_auth_token=self.autotrain_token,
repo_type="dataset",
)
except EntryNotFoundError:
raise Exception("Competition config not found. Please check the competition id.")
except Exception as e:
logger.error(e)
raise Exception("Hugging Face Hub is unreachable, please try again later.")
self.config = self.load_config(config_fname)
self.competition_desc = self.load_md(competition_desc)
self.dataset_desc = self.load_md(dataset_desc)
def load_md(self, md_path):
with open(md_path) as f:
md = f.read()
return md
def load_config(self, config_path):
with open(config_path) as f:
config = json.load(f)
return config
@property
def submission_limit(self):
return self.config["SUBMISSION_LIMIT"]
@property
def selection_limit(self):
return self.config["SELECTION_LIMIT"]
@property
def end_date(self):
e_d = self.config["END_DATE"]
return datetime.strptime(e_d, "%Y-%m-%d")
@property
def eval_higher_is_better(self):
hb = self.config["EVAL_HIGHER_IS_BETTER"]
return True if int(hb) == 1 else False
@property
def competition_description(self):
return self.competition_desc
@property
def competition_name(self):
return self.config["COMPETITION_NAME"]
@property
def submission_columns(self):
return self.config["SUBMISSION_COLUMNS"].split(",")
@property
def dataset_description(self):
return self.dataset_desc
|