Spaces:
Runtime error
Runtime error
Get latest submission names with each submission
Browse files
app.py
CHANGED
@@ -7,7 +7,7 @@ from pathlib import Path
|
|
7 |
import jsonlines
|
8 |
import streamlit as st
|
9 |
from dotenv import load_dotenv
|
10 |
-
from huggingface_hub import HfApi, Repository,
|
11 |
|
12 |
from utils import http_post, validate_json
|
13 |
|
@@ -55,13 +55,17 @@ def load_json(path):
|
|
55 |
return json.load(f)
|
56 |
|
57 |
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
|
|
|
|
|
|
|
|
65 |
|
66 |
|
67 |
###########
|
@@ -95,6 +99,7 @@ with st.form(key="form"):
|
|
95 |
if uploaded_file:
|
96 |
data = str(uploaded_file.read(), "utf-8")
|
97 |
json_data = json.loads(data)
|
|
|
98 |
submission_name = json_data["submission_name"]
|
99 |
if submission_name in submission_names:
|
100 |
st.error(f"π Submission name `{submission_name}` is already taken. Please rename your submission.")
|
|
|
7 |
import jsonlines
|
8 |
import streamlit as st
|
9 |
from dotenv import load_dotenv
|
10 |
+
from huggingface_hub import HfApi, Repository, cached_download, hf_hub_url
|
11 |
|
12 |
from utils import http_post, validate_json
|
13 |
|
|
|
55 |
return json.load(f)
|
56 |
|
57 |
|
58 |
+
def get_submission_names():
|
59 |
+
"""Download all submission names.
|
60 |
+
|
61 |
+
The GEM frontend requires the submission names to be unique, so here we
|
62 |
+
download all submission names and use them as a check against the user
|
63 |
+
submissions.
|
64 |
+
"""
|
65 |
+
scores_url = hf_hub_url("GEM-submissions/submission-scores", "scores.json", repo_type="dataset")
|
66 |
+
scores_filepath = cached_download(scores_url, force_download=True)
|
67 |
+
scores_data = load_json(scores_filepath)
|
68 |
+
return [score["submission_name"] for score in scores_data]
|
69 |
|
70 |
|
71 |
###########
|
|
|
99 |
if uploaded_file:
|
100 |
data = str(uploaded_file.read(), "utf-8")
|
101 |
json_data = json.loads(data)
|
102 |
+
submission_names = get_submission_names()
|
103 |
submission_name = json_data["submission_name"]
|
104 |
if submission_name in submission_names:
|
105 |
st.error(f"π Submission name `{submission_name}` is already taken. Please rename your submission.")
|