Spaces:
Runtime error
Runtime error
Moved upload to functions
Browse files
server.py
CHANGED
@@ -537,29 +537,34 @@ class LeaderboardServer:
|
|
537 |
if self.pre_submit:
|
538 |
tournament_results, submission_id, file = self.pre_submit
|
539 |
|
540 |
-
|
541 |
-
|
542 |
-
path_in_repo=f"data/{submission_id}.json",
|
543 |
-
repo_id=self.server_address,
|
544 |
-
repo_type=self.repo_type,
|
545 |
-
token=HF_TOKEN,
|
546 |
-
)
|
547 |
-
|
548 |
-
# Temporary save tournament results
|
549 |
-
tournament_results_path = os.path.join(self.local_leaderboard, "tournament.json")
|
550 |
-
with open(tournament_results_path, "w") as f:
|
551 |
-
json.dump(tournament_results, f, sort_keys=True, indent=2) # readable JSON
|
552 |
-
|
553 |
-
api.upload_file(
|
554 |
-
path_or_fileobj=tournament_results_path,
|
555 |
-
path_in_repo="tournament.json",
|
556 |
-
repo_id=self.server_address,
|
557 |
-
repo_type=self.repo_type,
|
558 |
-
token=HF_TOKEN,
|
559 |
-
)
|
560 |
|
561 |
self.pre_submit = None
|
562 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
563 |
def get_model_detail(self, submission_id):
|
564 |
if submission_id not in self.submission_id_to_data:
|
565 |
raise gr.Error(f"Submission [{submission_id}] not found")
|
|
|
537 |
if self.pre_submit:
|
538 |
tournament_results, submission_id, file = self.pre_submit
|
539 |
|
540 |
+
self._upload_submission(submission_id, file)
|
541 |
+
self._upload_tournament_results(tournament_results)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
542 |
|
543 |
self.pre_submit = None
|
544 |
|
545 |
+
def _upload_submission(self, submission_id, file):
|
546 |
+
api.upload_file(
|
547 |
+
path_or_fileobj=file,
|
548 |
+
path_in_repo=f"data/{submission_id}.json",
|
549 |
+
repo_id=self.server_address,
|
550 |
+
repo_type=self.repo_type,
|
551 |
+
token=HF_TOKEN,
|
552 |
+
)
|
553 |
+
|
554 |
+
def _upload_tournament_results(self, tournament_results):
|
555 |
+
# Temporary save tournament results
|
556 |
+
tournament_results_path = os.path.join(self.local_leaderboard, "tournament.json")
|
557 |
+
with open(tournament_results_path, "w") as f:
|
558 |
+
json.dump(tournament_results, f, sort_keys=True, indent=2) # readable JSON
|
559 |
+
|
560 |
+
api.upload_file(
|
561 |
+
path_or_fileobj=tournament_results_path,
|
562 |
+
path_in_repo="tournament.json",
|
563 |
+
repo_id=self.server_address,
|
564 |
+
repo_type=self.repo_type,
|
565 |
+
token=HF_TOKEN,
|
566 |
+
)
|
567 |
+
|
568 |
def get_model_detail(self, submission_id):
|
569 |
if submission_id not in self.submission_id_to_data:
|
570 |
raise gr.Error(f"Submission [{submission_id}] not found")
|