Spaces:
Runtime error
Runtime error
Validate submission name
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 |
|
|
@@ -50,6 +50,20 @@ def generate_dataset_card(submission_name):
|
|
| 50 |
f.write(markdown)
|
| 51 |
|
| 52 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 53 |
###########
|
| 54 |
### APP ###
|
| 55 |
###########
|
|
@@ -81,12 +95,16 @@ with st.form(key="form"):
|
|
| 81 |
if uploaded_file:
|
| 82 |
data = str(uploaded_file.read(), "utf-8")
|
| 83 |
json_data = json.loads(data)
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
st.success(message)
|
| 87 |
-
else:
|
| 88 |
-
st.error(message)
|
| 89 |
submission_errors += 1
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 90 |
|
| 91 |
with st.expander("Submission format"):
|
| 92 |
st.markdown(
|
|
@@ -208,6 +226,6 @@ if submit_button and submission_errors == 0:
|
|
| 208 |
"π Oh noes, there was an error submitting your submission! Please [contact the organisers](mailto:gehrmann@google.com)"
|
| 209 |
)
|
| 210 |
|
| 211 |
-
# Flush local repos
|
| 212 |
shutil.rmtree(LOCAL_REPO, ignore_errors=True)
|
| 213 |
shutil.rmtree(LOGS_REPO, ignore_errors=True)
|
|
|
|
| 7 |
import jsonlines
|
| 8 |
import streamlit as st
|
| 9 |
from dotenv import load_dotenv
|
| 10 |
+
from huggingface_hub import HfApi, Repository, hf_hub_url, cached_download
|
| 11 |
|
| 12 |
from utils import http_post, validate_json
|
| 13 |
|
|
|
|
| 50 |
f.write(markdown)
|
| 51 |
|
| 52 |
|
| 53 |
+
def load_json(path):
|
| 54 |
+
with open(path, "r") as f:
|
| 55 |
+
return json.load(f)
|
| 56 |
+
|
| 57 |
+
|
| 58 |
+
# The GEM frontend requires the submission names to be unique, so here we
|
| 59 |
+
# download all submission names and use them as a check against the user
|
| 60 |
+
# submissions
|
| 61 |
+
scores_url = hf_hub_url("GEM-submissions/submission-scores", "scores.json", repo_type="dataset")
|
| 62 |
+
scores_filepath = cached_download(scores_url)
|
| 63 |
+
scores_data = load_json(scores_filepath)
|
| 64 |
+
submission_names = [score["submission_name"] for score in scores_data]
|
| 65 |
+
|
| 66 |
+
|
| 67 |
###########
|
| 68 |
### APP ###
|
| 69 |
###########
|
|
|
|
| 95 |
if uploaded_file:
|
| 96 |
data = str(uploaded_file.read(), "utf-8")
|
| 97 |
json_data = json.loads(data)
|
| 98 |
+
if json_data["submission_name"] in submission_names:
|
| 99 |
+
st.error("π Submission name is already taken. Please rename your submission")
|
|
|
|
|
|
|
|
|
|
| 100 |
submission_errors += 1
|
| 101 |
+
else:
|
| 102 |
+
is_valid, message = validate_json(json_data)
|
| 103 |
+
if is_valid:
|
| 104 |
+
st.success(message)
|
| 105 |
+
else:
|
| 106 |
+
st.error(message)
|
| 107 |
+
submission_errors += 1
|
| 108 |
|
| 109 |
with st.expander("Submission format"):
|
| 110 |
st.markdown(
|
|
|
|
| 226 |
"π Oh noes, there was an error submitting your submission! Please [contact the organisers](mailto:gehrmann@google.com)"
|
| 227 |
)
|
| 228 |
|
| 229 |
+
# # Flush local repos
|
| 230 |
shutil.rmtree(LOCAL_REPO, ignore_errors=True)
|
| 231 |
shutil.rmtree(LOGS_REPO, ignore_errors=True)
|