Spaces:
Runtime error
Runtime error
Add AutoNLP trigger
Browse files- .gitignore +4 -1
- app.py +71 -4
- requirements.txt +3 -2
- validate.py +1 -1
.gitignore
CHANGED
@@ -138,4 +138,7 @@ dmypy.json
|
|
138 |
cython_debug/
|
139 |
|
140 |
# Secrets
|
141 |
-
.env
|
|
|
|
|
|
|
|
138 |
cython_debug/
|
139 |
|
140 |
# Secrets
|
141 |
+
.env
|
142 |
+
|
143 |
+
# Submissions
|
144 |
+
submission_repo/
|
app.py
CHANGED
@@ -1,17 +1,32 @@
|
|
1 |
-
import streamlit as st
|
2 |
import json
|
3 |
-
from validate import validate_submission
|
4 |
-
from huggingface_hub import whoami, create_repo, Repository
|
5 |
import os
|
|
|
|
|
|
|
|
|
6 |
from pathlib import Path
|
|
|
|
|
7 |
from dotenv import load_dotenv
|
|
|
|
|
|
|
8 |
|
9 |
if Path(".env").is_file():
|
10 |
load_dotenv(".env")
|
11 |
|
12 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
13 |
|
14 |
with st.form(key="form"):
|
|
|
|
|
15 |
uploaded_file = st.file_uploader("Upload a submission.json file", type=["json"])
|
16 |
|
17 |
if uploaded_file is not None:
|
@@ -25,3 +40,55 @@ with st.form(key="form"):
|
|
25 |
validate_submission(json_data)
|
26 |
user_info = whoami(token)
|
27 |
user_name = user_info["name"]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import json
|
|
|
|
|
2 |
import os
|
3 |
+
import re
|
4 |
+
import shutil
|
5 |
+
import subprocess
|
6 |
+
from datetime import datetime
|
7 |
from pathlib import Path
|
8 |
+
|
9 |
+
import streamlit as st
|
10 |
from dotenv import load_dotenv
|
11 |
+
from huggingface_hub import Repository, whoami
|
12 |
+
|
13 |
+
from validate import validate_submission
|
14 |
|
15 |
if Path(".env").is_file():
|
16 |
load_dotenv(".env")
|
17 |
|
18 |
+
HF_TOKEN = os.getenv("HF_TOKEN")
|
19 |
+
|
20 |
+
# AutoNLP login
|
21 |
+
autonlp_login = subprocess.run(["autonlp", "login", f"--api-key {HF_TOKEN}"], stdout=subprocess.PIPE)
|
22 |
+
if autonlp_login.returncode == -1:
|
23 |
+
raise Exception(f"AutoNLP login failed with return code {autonlp_login.returncode}")
|
24 |
+
|
25 |
+
LOCAL_REPO = "submission_repo"
|
26 |
|
27 |
with st.form(key="form"):
|
28 |
+
# Flush local repo
|
29 |
+
shutil.rmtree(LOCAL_REPO, ignore_errors=True)
|
30 |
uploaded_file = st.file_uploader("Upload a submission.json file", type=["json"])
|
31 |
|
32 |
if uploaded_file is not None:
|
|
|
40 |
validate_submission(json_data)
|
41 |
user_info = whoami(token)
|
42 |
user_name = user_info["name"]
|
43 |
+
submission_name = json_data["submission_name"]
|
44 |
+
|
45 |
+
# Create submission dataset under benchmarks ORG
|
46 |
+
dataset_repo_url = f"https://huggingface.co/datasets/benchmarks/gem-{user_name}"
|
47 |
+
repo = Repository(
|
48 |
+
local_dir=LOCAL_REPO, clone_from=dataset_repo_url, repo_type="dataset", private=True, use_auth_token=HF_TOKEN
|
49 |
+
)
|
50 |
+
submission_metadata = {"benchmark": "gem", "type": "prediction", "submission_name": submission_name}
|
51 |
+
repo.repocard_metadata_save(submission_metadata)
|
52 |
+
|
53 |
+
with open(f"{LOCAL_REPO}/submission.json", "w", encoding="utf-8") as f:
|
54 |
+
json.dump(json_data, f)
|
55 |
+
|
56 |
+
# TODO: add informative commit msg
|
57 |
+
commit_url = repo.push_to_hub()
|
58 |
+
if commit_url is not None:
|
59 |
+
commit_sha = commit_url.split("/")[-1]
|
60 |
+
else:
|
61 |
+
commit_sha = repo.git_head_commit_url().split("/")[-1]
|
62 |
+
|
63 |
+
submission_time = str(int(datetime.now().timestamp()))
|
64 |
+
submission_id = submission_name + "__" + commit_sha + "__" + submission_time
|
65 |
+
process = subprocess.run(
|
66 |
+
[
|
67 |
+
"autonlp",
|
68 |
+
"benchmark",
|
69 |
+
"--eval_name",
|
70 |
+
"gem",
|
71 |
+
"--dataset",
|
72 |
+
"GEM/references",
|
73 |
+
"--submission",
|
74 |
+
f"gem-{user_name}",
|
75 |
+
"--submission_id",
|
76 |
+
f"{submission_id}",
|
77 |
+
],
|
78 |
+
stdout=subprocess.PIPE,
|
79 |
+
)
|
80 |
+
if process.returncode == -1:
|
81 |
+
st.write("Error laucnhing AutoNLP job")
|
82 |
+
else:
|
83 |
+
try:
|
84 |
+
match_job_id = re.search(r"# (\d+)", process.stdout.decode("utf-8"))
|
85 |
+
job_id = match_job_id.group(1)
|
86 |
+
st.write(f"Successfully launched evaluation job #{job_id} for submission {submission_name}!")
|
87 |
+
except Exception as e:
|
88 |
+
st.write(f"Could not extract AutoNLP job ID due to error: {e}")
|
89 |
+
|
90 |
+
st.write(json_data["submission_name"])
|
91 |
+
st.write(commit_sha)
|
92 |
+
|
93 |
+
# Flush local repo
|
94 |
+
shutil.rmtree(LOCAL_REPO, ignore_errors=True)
|
requirements.txt
CHANGED
@@ -1,2 +1,3 @@
|
|
1 |
-
huggingface-hub==0.2.1
|
2 |
-
python-dotenv
|
|
|
|
1 |
+
# huggingface-hub==0.2.1
|
2 |
+
python-dotenv
|
3 |
+
autonlp>=0.3.4
|
validate.py
CHANGED
@@ -1,7 +1,7 @@
|
|
1 |
import json
|
2 |
-
import streamlit as st
|
3 |
|
4 |
import jsonschema
|
|
|
5 |
|
6 |
|
7 |
def get_schema():
|
|
|
1 |
import json
|
|
|
2 |
|
3 |
import jsonschema
|
4 |
+
import streamlit as st
|
5 |
|
6 |
|
7 |
def get_schema():
|