Spaces:
Running
Running
Decrease amount of updating leaderboard source data
Browse files
app.py
CHANGED
@@ -115,7 +115,6 @@ def get_submission_ids_and_titles():
|
|
115 |
|
116 |
def submit_results():
|
117 |
leaderboard_server.save_pre_submit()
|
118 |
-
leaderboard_server.update_leaderboard()
|
119 |
gr.Info('Submission successful!')
|
120 |
|
121 |
with leaderboard_server.var_lock.ro:
|
@@ -234,8 +233,6 @@ def hide_modal():
|
|
234 |
|
235 |
|
236 |
def on_application_load():
|
237 |
-
leaderboard_server.update_leaderboard()
|
238 |
-
|
239 |
with leaderboard_server.var_lock.ro:
|
240 |
leaderboard = leaderboard_server.get_leaderboard(category=leaderboard_server.TASKS_CATEGORY_OVERALL)
|
241 |
submission_ids_and_titles = get_submission_ids_and_titles()
|
|
|
115 |
|
116 |
def submit_results():
|
117 |
leaderboard_server.save_pre_submit()
|
|
|
118 |
gr.Info('Submission successful!')
|
119 |
|
120 |
with leaderboard_server.var_lock.ro:
|
|
|
233 |
|
234 |
|
235 |
def on_application_load():
|
|
|
|
|
236 |
with leaderboard_server.var_lock.ro:
|
237 |
leaderboard = leaderboard_server.get_leaderboard(category=leaderboard_server.TASKS_CATEGORY_OVERALL)
|
238 |
submission_ids_and_titles = get_submission_ids_and_titles()
|
server.py
CHANGED
@@ -149,12 +149,6 @@ class LeaderboardServer:
|
|
149 |
def __init__(self):
|
150 |
self.SERVER_ADDRESS = REPO
|
151 |
self.REPO_TYPE = "dataset"
|
152 |
-
self.results_dataset_local_snapshot = snapshot_download(
|
153 |
-
self.SERVER_ADDRESS,
|
154 |
-
repo_type=self.REPO_TYPE,
|
155 |
-
token=HF_TOKEN,
|
156 |
-
local_dir="./",
|
157 |
-
)
|
158 |
self.TASKS_METADATA = json.load(open(TASKS_METADATA_PATH))
|
159 |
self.TASKS_CATEGORIES = {self.TASKS_METADATA[task]["category"] for task in self.TASKS_METADATA}
|
160 |
self.TASKS_CATEGORY_OVERALL = "Overall"
|
@@ -165,34 +159,40 @@ class LeaderboardServer:
|
|
165 |
self.submission_id_to_file = {} # Map submission ids to file paths
|
166 |
self.submission_id_to_model_title = {}
|
167 |
self.submission_id_to_data = {} # Only data (results and metadata) using by leaderboard
|
168 |
-
self.
|
169 |
-
|
|
|
|
|
170 |
|
171 |
self.pre_submit_lock = pre_submit_lock
|
172 |
self.pre_submit = None
|
173 |
|
|
|
174 |
self.results_dataset_integrity_check() # Check integrity of the results dataset after (re)start Hugging Face Space
|
175 |
|
176 |
def update_leaderboard(self):
|
177 |
-
self.
|
178 |
-
self.
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
|
|
|
185 |
tournament_results = self.load_tournament_results()
|
|
|
186 |
with self.var_lock.rw:
|
187 |
self.tournament_results = tournament_results
|
188 |
|
189 |
def load_tournament_results(self):
|
190 |
-
|
191 |
-
|
192 |
-
|
193 |
-
|
194 |
-
|
195 |
-
|
|
|
196 |
|
197 |
def _prepare_category_to_task_abbr_to_details(self):
|
198 |
tasks_per_category = {}
|
@@ -224,18 +224,29 @@ class LeaderboardServer:
|
|
224 |
|
225 |
def fetch_existing_models(self):
|
226 |
# Models data
|
227 |
-
|
228 |
-
|
229 |
-
|
230 |
-
|
231 |
-
|
232 |
-
|
233 |
-
|
234 |
-
|
235 |
-
|
236 |
-
|
237 |
-
|
238 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
239 |
|
240 |
def results_dataset_integrity_check(self):
|
241 |
"""
|
@@ -611,6 +622,7 @@ class LeaderboardServer:
|
|
611 |
self._upload_tournament_results(tournament_results)
|
612 |
|
613 |
self.pre_submit = None
|
|
|
614 |
|
615 |
def _upload_submission(self, submission_id, file):
|
616 |
api.upload_file(
|
@@ -623,9 +635,10 @@ class LeaderboardServer:
|
|
623 |
|
624 |
def _upload_tournament_results(self, tournament_results):
|
625 |
# Temporary save tournament results
|
626 |
-
|
627 |
-
|
628 |
-
|
|
|
629 |
|
630 |
api.upload_file(
|
631 |
path_or_fileobj=tournament_results_path,
|
|
|
149 |
def __init__(self):
|
150 |
self.SERVER_ADDRESS = REPO
|
151 |
self.REPO_TYPE = "dataset"
|
|
|
|
|
|
|
|
|
|
|
|
|
152 |
self.TASKS_METADATA = json.load(open(TASKS_METADATA_PATH))
|
153 |
self.TASKS_CATEGORIES = {self.TASKS_METADATA[task]["category"] for task in self.TASKS_METADATA}
|
154 |
self.TASKS_CATEGORY_OVERALL = "Overall"
|
|
|
159 |
self.submission_id_to_file = {} # Map submission ids to file paths
|
160 |
self.submission_id_to_model_title = {}
|
161 |
self.submission_id_to_data = {} # Only data (results and metadata) using by leaderboard
|
162 |
+
self.tournament_results = None
|
163 |
+
|
164 |
+
self.results_dataset_local_snapshot_lock = ReadWriteLock()
|
165 |
+
self.results_dataset_local_snapshot = None
|
166 |
|
167 |
self.pre_submit_lock = pre_submit_lock
|
168 |
self.pre_submit = None
|
169 |
|
170 |
+
self.update_leaderboard()
|
171 |
self.results_dataset_integrity_check() # Check integrity of the results dataset after (re)start Hugging Face Space
|
172 |
|
173 |
def update_leaderboard(self):
|
174 |
+
with self.results_dataset_local_snapshot_lock.rw:
|
175 |
+
self.results_dataset_local_snapshot = snapshot_download(
|
176 |
+
self.SERVER_ADDRESS,
|
177 |
+
repo_type=self.REPO_TYPE,
|
178 |
+
token=HF_TOKEN,
|
179 |
+
local_dir="./",
|
180 |
+
)
|
181 |
|
182 |
+
self.fetch_existing_models()
|
183 |
tournament_results = self.load_tournament_results()
|
184 |
+
|
185 |
with self.var_lock.rw:
|
186 |
self.tournament_results = tournament_results
|
187 |
|
188 |
def load_tournament_results(self):
|
189 |
+
with self.results_dataset_local_snapshot_lock.ro:
|
190 |
+
metadata_rank_paths = os.path.join(self.results_dataset_local_snapshot, "tournament.json")
|
191 |
+
if not os.path.exists(metadata_rank_paths):
|
192 |
+
return {}
|
193 |
+
with open(metadata_rank_paths) as ranks_file:
|
194 |
+
results = json.load(ranks_file)
|
195 |
+
return results
|
196 |
|
197 |
def _prepare_category_to_task_abbr_to_details(self):
|
198 |
tasks_per_category = {}
|
|
|
224 |
|
225 |
def fetch_existing_models(self):
|
226 |
# Models data
|
227 |
+
submission_ids = set()
|
228 |
+
submission_id_to_file = {}
|
229 |
+
submission_id_to_model_title = {}
|
230 |
+
submission_id_to_data = {}
|
231 |
+
|
232 |
+
with self.results_dataset_local_snapshot_lock.ro:
|
233 |
+
for submission_file in glob.glob(os.path.join(self.results_dataset_local_snapshot, "data") + "/*.json"):
|
234 |
+
data = json.load(open(submission_file))
|
235 |
+
metadata = data.get('metadata')
|
236 |
+
if metadata is None:
|
237 |
+
continue
|
238 |
+
submission_id = metadata["submission_id"]
|
239 |
+
|
240 |
+
submission_ids.add(submission_id)
|
241 |
+
submission_id_to_file[submission_id] = submission_file
|
242 |
+
submission_id_to_model_title[submission_id] = metadata["team_name"] + "/" + metadata["model_name"]
|
243 |
+
submission_id_to_data[submission_id] = {"results": data["results"], "metadata": metadata}
|
244 |
+
|
245 |
+
with self.var_lock.rw:
|
246 |
+
self.submission_ids = submission_ids
|
247 |
+
self.submission_id_to_file = submission_id_to_file
|
248 |
+
self.submission_id_to_model_title = submission_id_to_model_title
|
249 |
+
self.submission_id_to_data = submission_id_to_data
|
250 |
|
251 |
def results_dataset_integrity_check(self):
|
252 |
"""
|
|
|
622 |
self._upload_tournament_results(tournament_results)
|
623 |
|
624 |
self.pre_submit = None
|
625 |
+
self.update_leaderboard()
|
626 |
|
627 |
def _upload_submission(self, submission_id, file):
|
628 |
api.upload_file(
|
|
|
635 |
|
636 |
def _upload_tournament_results(self, tournament_results):
|
637 |
# Temporary save tournament results
|
638 |
+
with self.results_dataset_local_snapshot_lock.rw:
|
639 |
+
tournament_results_path = os.path.join(self.results_dataset_local_snapshot, "tournament.json")
|
640 |
+
with open(tournament_results_path, "w") as f:
|
641 |
+
json.dump(tournament_results, f, sort_keys=True, indent=2) # readable JSON
|
642 |
|
643 |
api.upload_file(
|
644 |
path_or_fileobj=tournament_results_path,
|