lewtun HF staff commited on
Commit
5f44f14
β€’
1 Parent(s): 8322101

Add logging of submission jobs

Browse files
Files changed (2) hide show
  1. app.py +44 -19
  2. requirements.txt +2 -1
app.py CHANGED
@@ -4,6 +4,7 @@ import shutil
4
  from datetime import datetime
5
  from pathlib import Path
6
 
 
7
  import streamlit as st
8
  from dotenv import load_dotenv
9
  from huggingface_hub import HfApi, Repository
@@ -17,6 +18,7 @@ HF_TOKEN = os.getenv("HF_TOKEN")
17
  AUTONLP_USERNAME = os.getenv("AUTONLP_USERNAME")
18
  HF_AUTONLP_BACKEND_API = os.getenv("HF_AUTONLP_BACKEND_API")
19
  LOCAL_REPO = "submission_repo"
 
20
 
21
  ## TODO ##
22
  # 1. Add check that fields are nested under `tasks` field correctly
@@ -146,25 +148,48 @@ if submit_button and submission_errors == 0:
146
 
147
  submission_id = submission_name + "__" + commit_sha + "__" + submission_time
148
 
149
- # payload = {
150
- # "username": AUTONLP_USERNAME,
151
- # "dataset": "GEM/references",
152
- # "task": 1,
153
- # "model": "gem",
154
- # "submission_dataset": f"GEM-submissions/{user_name}",
155
- # "submission_id": submission_id,
156
- # "col_mapping": {},
157
- # "split": "test",
158
- # "config": None,
159
- # }
160
- # json_resp = http_post(
161
- # path="/evaluate/create", payload=payload, token=HF_TOKEN, domain=HF_AUTONLP_BACKEND_API
162
- # ).json()
163
-
164
- # if json_resp["status"] == 1:
165
- # st.success(f"βœ… Submission {submission_name} was successfully submitted for evaluation!")
166
- # else:
167
- # st.error("πŸ™ˆ Oh noes, there was an error submitting your submission! Please contact the organisers")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
168
 
169
  # Flush local repo
170
  shutil.rmtree(LOCAL_REPO, ignore_errors=True)
 
 
4
  from datetime import datetime
5
  from pathlib import Path
6
 
7
+ import jsonlines
8
  import streamlit as st
9
  from dotenv import load_dotenv
10
  from huggingface_hub import HfApi, Repository
 
18
  AUTONLP_USERNAME = os.getenv("AUTONLP_USERNAME")
19
  HF_AUTONLP_BACKEND_API = os.getenv("HF_AUTONLP_BACKEND_API")
20
  LOCAL_REPO = "submission_repo"
21
+ LOGS_REPO = "submission-logs"
22
 
23
  ## TODO ##
24
  # 1. Add check that fields are nested under `tasks` field correctly
 
148
 
149
  submission_id = submission_name + "__" + commit_sha + "__" + submission_time
150
 
151
+ payload = {
152
+ "username": AUTONLP_USERNAME,
153
+ "dataset": "GEM/references",
154
+ "task": 1,
155
+ "model": "gem",
156
+ "submission_dataset": f"GEM-submissions/{user_name}",
157
+ "submission_id": submission_id,
158
+ "col_mapping": {},
159
+ "split": "test",
160
+ "config": None,
161
+ }
162
+ json_resp = http_post(
163
+ path="/evaluate/create", payload=payload, token=HF_TOKEN, domain=HF_AUTONLP_BACKEND_API
164
+ ).json()
165
+
166
+ logs_repo_url = f"https://huggingface.co/datasets/GEM-submissions/{LOGS_REPO}"
167
+ logs_repo = Repository(
168
+ local_dir=LOGS_REPO,
169
+ clone_from=logs_repo_url,
170
+ repo_type="dataset",
171
+ private=True,
172
+ use_auth_token=HF_TOKEN,
173
+ )
174
+ json_resp["submission_name"] = submission_name
175
+ with jsonlines.open(f"{LOGS_REPO}/logs.jsonl") as r:
176
+ lines = []
177
+ for obj in r:
178
+ lines.append(obj)
179
+
180
+ lines.append(json_resp)
181
+ with jsonlines.open(f"{LOGS_REPO}/logs.jsonl", mode="w") as writer:
182
+ for job in lines:
183
+ writer.write(job)
184
+ logs_repo.push_to_hub(commit_message=f"Submission with job ID {json_resp['id']}")
185
+
186
+ if json_resp["status"] == 1:
187
+ st.success(
188
+ f"βœ… Submission {submission_name} was successfully submitted for evaluation with job ID {json_resp['id']}"
189
+ )
190
+ else:
191
+ st.error("πŸ™ˆ Oh noes, there was an error submitting your submission! Please contact the organisers")
192
 
193
  # Flush local repo
194
  shutil.rmtree(LOCAL_REPO, ignore_errors=True)
195
+ shutil.rmtree(LOGS_REPO, ignore_errors=True)
requirements.txt CHANGED
@@ -1,2 +1,3 @@
1
  python-dotenv
2
- huggingface-hub==0.2.1
 
 
1
  python-dotenv
2
+ huggingface-hub==0.2.1
3
+ jsonlines