File size: 3,970 Bytes
ae02377
815b0dc
f3fe9b4
8ec4d2d
ae02377
 
815b0dc
f3fe9b4
5839973
815b0dc
ae02377
815b0dc
 
 
 
ae02377
 
815b0dc
527614c
815b0dc
ae02377
 
3ea1b9b
 
 
 
 
 
 
 
 
 
 
 
ae02377
 
 
815b0dc
ae02377
 
 
3ea1b9b
 
470460b
 
 
 
 
 
 
 
 
 
3ea1b9b
 
 
 
 
ae02377
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3ea1b9b
ae02377
 
 
 
 
470460b
 
 
 
d5ca063
 
3ea1b9b
936d8d9
 
 
 
 
 
 
 
1094cbb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0558a9f
 
 
 
abe3598
 
 
90724cf
f63d039
 
 
 
de15d44
 
 
 
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
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.json",
                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)
        try:
            submission_desc = hf_hub_download(
                repo_id=self.competition_id,
                filename="SUBMISSION_DESC.md",
                use_auth_token=self.autotrain_token,
                repo_type="dataset",
            )
            self.submission_desc = self.load_md(submission_desc)
        except Exception:
            self.submission_desc = None

    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 submission_columns(self):
        return self.config["SUBMISSION_COLUMNS"].split(",")

    @property
    def submission_description(self):
        return self.submission_desc

    @property
    def dataset_description(self):
        return self.dataset_desc

    @property
    def logo_url(self):
        return self.config["LOGO"]

    @property
    def competition_type(self):
        return self.config["COMPETITION_TYPE"].lower().strip()

    @property
    def metric(self):
        return self.config["EVAL_METRIC"]

    @property
    def submission_id_col(self):
        return self.config["SUBMISSION_ID_COLUMN"]

    @property
    def submission_cols(self):
        cols = self.config["SUBMISSION_COLUMNS"].split(",")
        cols = [c.strip() for c in cols]
        return cols

    @property
    def submission_rows(self):
        return self.config["SUBMISSION_ROWS"]

    @property
    def time_limit(self):
        return self.config["TIME_LIMIT"]

    @property
    def hardware(self):
        return self.config.get("HARDWARE", "cpu-basic")

    @property
    def dataset(self):
        return self.config.get("DATASET", "")

    @property
    def submission_filenames(self):
        return self.config.get("SUBMISSION_FILENAMES", ["submission.csv"])