lewtun HF staff commited on
Commit
0ef1d60
β€’
1 Parent(s): 0398e81

Get latest submission names with each submission

Browse files
Files changed (1) hide show
  1. app.py +13 -8
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, hf_hub_url, cached_download
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
- # 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
  ###########
@@ -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.")