Spaces:
Running
Running
Do not read big JSON file twice
Browse files
app.py
CHANGED
@@ -182,13 +182,12 @@ def submit_results(*inputs):
|
|
182 |
inputs = dict(zip(SUBMISSION_INPUTS, inputs))
|
183 |
with open(inputs["submission_file"]) as fp:
|
184 |
data = json.load(fp)
|
185 |
-
metadata = data["submission_metadata"]
|
186 |
gr.Info('Checking if the tournament is complete…')
|
187 |
-
leaderboard_server.save_model_submission(inputs["submission_file"],
|
188 |
gr.Info('Submission successful!')
|
189 |
|
190 |
# erase pre-submit
|
191 |
-
submission_id =
|
192 |
leaderboard_server.pre_submit.pop(submission_id)
|
193 |
|
194 |
with leaderboard_server.var_lock.ro:
|
@@ -225,8 +224,7 @@ def erase_pre_submit(*inputs):
|
|
225 |
inputs = dict(zip(SUBMISSION_INPUTS, inputs))
|
226 |
with open(inputs["submission_file"]) as fp:
|
227 |
data = json.load(fp)
|
228 |
-
|
229 |
-
submission_id = metadata["submission_id"]
|
230 |
leaderboard_server.pre_submit.pop(submission_id)
|
231 |
|
232 |
return (
|
|
|
182 |
inputs = dict(zip(SUBMISSION_INPUTS, inputs))
|
183 |
with open(inputs["submission_file"]) as fp:
|
184 |
data = json.load(fp)
|
|
|
185 |
gr.Info('Checking if the tournament is complete…')
|
186 |
+
leaderboard_server.save_model_submission(inputs["submission_file"], data=data)
|
187 |
gr.Info('Submission successful!')
|
188 |
|
189 |
# erase pre-submit
|
190 |
+
submission_id = data["submission_metadata"]["submission_id"]
|
191 |
leaderboard_server.pre_submit.pop(submission_id)
|
192 |
|
193 |
with leaderboard_server.var_lock.ro:
|
|
|
224 |
inputs = dict(zip(SUBMISSION_INPUTS, inputs))
|
225 |
with open(inputs["submission_file"]) as fp:
|
226 |
data = json.load(fp)
|
227 |
+
submission_id = data["submission_metadata"]["submission_id"]
|
|
|
228 |
leaderboard_server.pre_submit.pop(submission_id)
|
229 |
|
230 |
return (
|
server.py
CHANGED
@@ -937,16 +937,17 @@ class LeaderboardServer:
|
|
937 |
with open(file, "w") as f:
|
938 |
json.dump(data, f, separators=(',', ':')) # compact JSON
|
939 |
|
940 |
-
return self._prepare_model_for_submission(file,
|
941 |
|
942 |
-
def save_model_submission(self, file,
|
943 |
-
return self._prepare_model_for_submission(file,
|
944 |
|
945 |
-
def _prepare_model_for_submission(self, file,
|
946 |
with open(file, "r") as f:
|
947 |
-
|
|
|
948 |
|
949 |
-
submission_id =
|
950 |
|
951 |
while True:
|
952 |
submit_lock = self.submit_lock if do_submit else NoneLock()
|
@@ -973,7 +974,7 @@ class LeaderboardServer:
|
|
973 |
{
|
974 |
"results": data["results"],
|
975 |
"metadata": data.get("metadata", {}),
|
976 |
-
"submission_metadata":
|
977 |
}
|
978 |
)
|
979 |
self.pre_submit[submission_id] = pre_submit
|
|
|
937 |
with open(file, "w") as f:
|
938 |
json.dump(data, f, separators=(',', ':')) # compact JSON
|
939 |
|
940 |
+
return self._prepare_model_for_submission(file, data=data, do_submit=False)
|
941 |
|
942 |
+
def save_model_submission(self, file, data=None) -> PreSubmit:
|
943 |
+
return self._prepare_model_for_submission(file, data=data, do_submit=True)
|
944 |
|
945 |
+
def _prepare_model_for_submission(self, file, data=None, do_submit=False) -> PreSubmit:
|
946 |
with open(file, "r") as f:
|
947 |
+
if not data:
|
948 |
+
data = json.load(f)
|
949 |
|
950 |
+
submission_id = data["submission_metadata"]["submission_id"]
|
951 |
|
952 |
while True:
|
953 |
submit_lock = self.submit_lock if do_submit else NoneLock()
|
|
|
974 |
{
|
975 |
"results": data["results"],
|
976 |
"metadata": data.get("metadata", {}),
|
977 |
+
"submission_metadata": data["submission_metadata"],
|
978 |
}
|
979 |
)
|
980 |
self.pre_submit[submission_id] = pre_submit
|