Spaces:
Runtime error
Runtime error
Add logging of submission jobs
Browse files- app.py +44 -19
- 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 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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
|