Spaces:
Runtime error
Runtime error
Merge branch 'main' into add-nli
Browse files- .env.example +0 -4
- .env.template +4 -0
- .github/workflows/run_evaluation_jobs.yml +30 -0
- README.md +8 -2
- app.py +69 -41
- requirements.txt +1 -0
- run_evaluation_jobs.py +64 -0
.env.example
DELETED
@@ -1,4 +0,0 @@
|
|
1 |
-
AUTOTRAIN_USERNAME=autoevaluator # The bot that authors evaluation jobs
|
2 |
-
HF_TOKEN=hf_xxx # An API token of the `autoevaluator` user
|
3 |
-
AUTOTRAIN_BACKEND_API=https://api-staging.autotrain.huggingface.co # The AutoTrain backend to send jobs to. Use https://api.autotrain.huggingface.co for prod
|
4 |
-
DATASETS_PREVIEW_API=https://datasets-server.huggingface.co # The API to grab dataset information from
|
|
|
|
|
|
|
|
|
|
.env.template
ADDED
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
1 |
+
AUTOTRAIN_USERNAME=autoevaluator # The bot or user that authors evaluation jobs
|
2 |
+
HF_TOKEN=hf_xxx # An API token of the `autoevaluator` user
|
3 |
+
AUTOTRAIN_BACKEND_API=https://api-staging.autotrain.huggingface.co # The AutoTrain backend to send jobs to. Use https://api.autotrain.huggingface.co for prod or http://localhost:8000 for local development
|
4 |
+
DATASETS_PREVIEW_API=https://datasets-server.huggingface.co # The API to grab dataset information from
|
.github/workflows/run_evaluation_jobs.yml
ADDED
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
name: Start evaluation jobs
|
2 |
+
|
3 |
+
on:
|
4 |
+
schedule:
|
5 |
+
- cron: '*/15 * * * *' # Start evaluations every 15th minute
|
6 |
+
|
7 |
+
jobs:
|
8 |
+
|
9 |
+
build:
|
10 |
+
runs-on: ubuntu-latest
|
11 |
+
|
12 |
+
steps:
|
13 |
+
- name: Checkout code
|
14 |
+
uses: actions/checkout@v2
|
15 |
+
|
16 |
+
- name: Setup Python Environment
|
17 |
+
uses: actions/setup-python@v2
|
18 |
+
with:
|
19 |
+
python-version: 3.8
|
20 |
+
|
21 |
+
- name: Install requirements
|
22 |
+
run: pip install -r requirements.txt
|
23 |
+
|
24 |
+
- name: Execute scoring script
|
25 |
+
env:
|
26 |
+
HF_TOKEN: ${{ secrets.HF_TOKEN }}
|
27 |
+
AUTOTRAIN_USERNAME: ${{ secrets.AUTOTRAIN_USERNAME }}
|
28 |
+
AUTOTRAIN_BACKEND_API: ${{ secrets.AUTOTRAIN_BACKEND_API }}
|
29 |
+
run: |
|
30 |
+
HF_TOKEN=$HF_TOKEN AUTOTRAIN_USERNAME=$AUTOTRAIN_USERNAME AUTOTRAIN_BACKEND_API=$AUTOTRAIN_BACKEND_API python run_evaluation_jobs.py
|
README.md
CHANGED
@@ -39,7 +39,7 @@ pip install -r requirements.txt
|
|
39 |
Next, copy the example file of environment variables:
|
40 |
|
41 |
```
|
42 |
-
cp .env.
|
43 |
```
|
44 |
|
45 |
and set the `HF_TOKEN` variable with a valid API token from the `autoevaluator` user. Finally, spin up the application by running:
|
@@ -53,5 +53,11 @@ streamlit run app.py
|
|
53 |
Models are evaluated by AutoTrain, with the payload sent to the `AUTOTRAIN_BACKEND_API` environment variable. The current configuration for evaluation jobs running on Spaces is:
|
54 |
|
55 |
```
|
56 |
-
AUTOTRAIN_BACKEND_API=https://api.autotrain.huggingface.co
|
|
|
|
|
|
|
|
|
|
|
|
|
57 |
```
|
|
|
39 |
Next, copy the example file of environment variables:
|
40 |
|
41 |
```
|
42 |
+
cp .env.template .env
|
43 |
```
|
44 |
|
45 |
and set the `HF_TOKEN` variable with a valid API token from the `autoevaluator` user. Finally, spin up the application by running:
|
|
|
53 |
Models are evaluated by AutoTrain, with the payload sent to the `AUTOTRAIN_BACKEND_API` environment variable. The current configuration for evaluation jobs running on Spaces is:
|
54 |
|
55 |
```
|
56 |
+
AUTOTRAIN_BACKEND_API=https://api-staging.autotrain.huggingface.co
|
57 |
+
```
|
58 |
+
|
59 |
+
To evaluate models with a _local_ instance of AutoTrain, change the environment to:
|
60 |
+
|
61 |
+
```
|
62 |
+
AUTOTRAIN_BACKEND_API=http://localhost:8000
|
63 |
```
|
app.py
CHANGED
@@ -1,4 +1,5 @@
|
|
1 |
import os
|
|
|
2 |
from pathlib import Path
|
3 |
|
4 |
import pandas as pd
|
@@ -561,50 +562,77 @@ with st.form(key="form"):
|
|
561 |
).json()
|
562 |
print(f"INFO -- Dataset creation response: {data_json_resp}")
|
563 |
if data_json_resp["download_status"] == 1:
|
564 |
-
train_json_resp =
|
565 |
-
path=f"/projects/{project_json_resp['id']}/data/
|
566 |
token=HF_TOKEN,
|
567 |
domain=AUTOTRAIN_BACKEND_API,
|
568 |
).json()
|
569 |
-
|
570 |
-
if
|
571 |
-
|
572 |
-
|
573 |
-
|
574 |
-
|
575 |
-
"
|
576 |
-
|
577 |
-
|
578 |
-
|
579 |
-
|
580 |
-
|
581 |
-
|
582 |
-
|
583 |
-
|
584 |
-
|
585 |
-
|
586 |
-
|
587 |
-
|
588 |
-
|
589 |
-
|
590 |
-
* π Click [here](https://hf.co/spaces/autoevaluate/leaderboards?dataset={selected_dataset}) to view the results from your submission once the Hub pull request is merged.
|
591 |
-
* π₯± Tired of configuring evaluations? Add the following metadata to the [dataset card]({dataset_card_url}) to enable 1-click evaluations:
|
592 |
-
""" # noqa
|
593 |
-
)
|
594 |
-
st.markdown(
|
595 |
-
f"""
|
596 |
-
```yaml
|
597 |
-
{selected_metadata}
|
598 |
-
"""
|
599 |
-
)
|
600 |
-
print("INFO -- Pushing evaluation job logs to the Hub")
|
601 |
-
evaluation_log = {}
|
602 |
-
evaluation_log["payload"] = project_payload
|
603 |
-
evaluation_log["project_creation_response"] = project_json_resp
|
604 |
-
evaluation_log["dataset_creation_response"] = data_json_resp
|
605 |
-
evaluation_log["autotrain_job_response"] = train_json_resp
|
606 |
-
commit_evaluation_log(evaluation_log, hf_access_token=HF_TOKEN)
|
607 |
else:
|
608 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
609 |
else:
|
610 |
st.warning("β οΈ No models left to evaluate! Please select other models and try again.")
|
|
|
1 |
import os
|
2 |
+
import time
|
3 |
from pathlib import Path
|
4 |
|
5 |
import pandas as pd
|
|
|
562 |
).json()
|
563 |
print(f"INFO -- Dataset creation response: {data_json_resp}")
|
564 |
if data_json_resp["download_status"] == 1:
|
565 |
+
train_json_resp = http_post(
|
566 |
+
path=f"/projects/{project_json_resp['id']}/data/start_processing",
|
567 |
token=HF_TOKEN,
|
568 |
domain=AUTOTRAIN_BACKEND_API,
|
569 |
).json()
|
570 |
+
# For local development we process and approve projects on-the-fly
|
571 |
+
if "localhost" in AUTOTRAIN_BACKEND_API:
|
572 |
+
with st.spinner("β³ Waiting for data processing to complete ..."):
|
573 |
+
is_data_processing_success = False
|
574 |
+
while is_data_processing_success is not True:
|
575 |
+
project_status = http_get(
|
576 |
+
path=f"/projects/{project_json_resp['id']}",
|
577 |
+
token=HF_TOKEN,
|
578 |
+
domain=AUTOTRAIN_BACKEND_API,
|
579 |
+
).json()
|
580 |
+
if project_status["status"] == 3:
|
581 |
+
is_data_processing_success = True
|
582 |
+
time.sleep(10)
|
583 |
+
|
584 |
+
# Approve training job
|
585 |
+
train_job_resp = http_post(
|
586 |
+
path=f"/projects/{project_json_resp['id']}/start_training",
|
587 |
+
token=HF_TOKEN,
|
588 |
+
domain=AUTOTRAIN_BACKEND_API,
|
589 |
+
).json()
|
590 |
+
st.success("β
Data processing and project approval complete - go forth and evaluate!")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
591 |
else:
|
592 |
+
# Prod/staging submissions are evaluated in a cron job via run_evaluation_jobs.py
|
593 |
+
print(f"INFO -- AutoTrain job response: {train_json_resp}")
|
594 |
+
if train_json_resp["success"]:
|
595 |
+
train_eval_index = {
|
596 |
+
"train-eval-index": [
|
597 |
+
{
|
598 |
+
"config": selected_config,
|
599 |
+
"task": AUTOTRAIN_TASK_TO_HUB_TASK[selected_task],
|
600 |
+
"task_id": selected_task,
|
601 |
+
"splits": {"eval_split": selected_split},
|
602 |
+
"col_mapping": col_mapping,
|
603 |
+
}
|
604 |
+
]
|
605 |
+
}
|
606 |
+
selected_metadata = yaml.dump(train_eval_index, sort_keys=False)
|
607 |
+
dataset_card_url = get_dataset_card_url(selected_dataset)
|
608 |
+
st.success("β
Successfully submitted evaluation job!")
|
609 |
+
st.markdown(
|
610 |
+
f"""
|
611 |
+
Evaluation can take up to 1 hour to complete, so grab a βοΈ or π΅ while you wait:
|
612 |
+
|
613 |
+
* π A [Hub pull request](https://huggingface.co/docs/hub/repositories-pull-requests-discussions) with the evaluation results will be opened for each model you selected. Check your email for notifications.
|
614 |
+
* π Click [here](https://hf.co/spaces/autoevaluate/leaderboards?dataset={selected_dataset}) to view the results from your submission once the Hub pull request is merged.
|
615 |
+
* π₯± Tired of configuring evaluations? Add the following metadata to the [dataset card]({dataset_card_url}) to enable 1-click evaluations:
|
616 |
+
""" # noqa
|
617 |
+
)
|
618 |
+
st.markdown(
|
619 |
+
f"""
|
620 |
+
```yaml
|
621 |
+
{selected_metadata}
|
622 |
+
"""
|
623 |
+
)
|
624 |
+
print("INFO -- Pushing evaluation job logs to the Hub")
|
625 |
+
evaluation_log = {}
|
626 |
+
evaluation_log["project_id"] = project_json_resp["id"]
|
627 |
+
evaluation_log["autotrain_env"] = (
|
628 |
+
"staging" if "staging" in AUTOTRAIN_BACKEND_API else "prod"
|
629 |
+
)
|
630 |
+
evaluation_log["payload"] = project_payload
|
631 |
+
evaluation_log["project_creation_response"] = project_json_resp
|
632 |
+
evaluation_log["dataset_creation_response"] = data_json_resp
|
633 |
+
evaluation_log["autotrain_job_response"] = train_json_resp
|
634 |
+
commit_evaluation_log(evaluation_log, hf_access_token=HF_TOKEN)
|
635 |
+
else:
|
636 |
+
st.error("π Oh no, there was an error submitting your evaluation job!")
|
637 |
else:
|
638 |
st.warning("β οΈ No models left to evaluate! Please select other models and try again.")
|
requirements.txt
CHANGED
@@ -4,6 +4,7 @@ streamlit==1.10.0
|
|
4 |
datasets<2.3
|
5 |
evaluate<0.2
|
6 |
jsonlines
|
|
|
7 |
# Dataset specific deps
|
8 |
py7zr<0.19
|
9 |
openpyxl<3.1
|
|
|
4 |
datasets<2.3
|
5 |
evaluate<0.2
|
6 |
jsonlines
|
7 |
+
typer
|
8 |
# Dataset specific deps
|
9 |
py7zr<0.19
|
10 |
openpyxl<3.1
|
run_evaluation_jobs.py
ADDED
@@ -0,0 +1,64 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
from pathlib import Path
|
3 |
+
|
4 |
+
import typer
|
5 |
+
from datasets import load_dataset
|
6 |
+
from dotenv import load_dotenv
|
7 |
+
|
8 |
+
from utils import http_get, http_post
|
9 |
+
|
10 |
+
if Path(".env").is_file():
|
11 |
+
load_dotenv(".env")
|
12 |
+
|
13 |
+
HF_TOKEN = os.getenv("HF_TOKEN")
|
14 |
+
AUTOTRAIN_USERNAME = os.getenv("AUTOTRAIN_USERNAME")
|
15 |
+
AUTOTRAIN_BACKEND_API = os.getenv("AUTOTRAIN_BACKEND_API")
|
16 |
+
|
17 |
+
if "staging" in AUTOTRAIN_BACKEND_API:
|
18 |
+
AUTOTRAIN_ENV = "staging"
|
19 |
+
else:
|
20 |
+
AUTOTRAIN_ENV = "prod"
|
21 |
+
|
22 |
+
|
23 |
+
def main():
|
24 |
+
print(f"π‘ Starting jobs on {AUTOTRAIN_ENV} environment")
|
25 |
+
logs_df = load_dataset("autoevaluate/evaluation-job-logs", use_auth_token=HF_TOKEN, split="train").to_pandas()
|
26 |
+
# Filter out legacy AutoTrain submissions prior to project approvals requirement
|
27 |
+
projects_df = logs_df.copy()[(~logs_df["project_id"].isnull())]
|
28 |
+
# Filter IDs for appropriate AutoTrain env (staging vs prod)
|
29 |
+
projects_df = projects_df.copy().query(f"autotrain_env == '{AUTOTRAIN_ENV}'")
|
30 |
+
projects_to_approve = projects_df["project_id"].astype(int).tolist()
|
31 |
+
failed_approvals = []
|
32 |
+
print(f"π Found {len(projects_to_approve)} evaluation projects to approve!")
|
33 |
+
|
34 |
+
for project_id in projects_to_approve:
|
35 |
+
print(f"Attempting to evaluate project ID {project_id} ...")
|
36 |
+
try:
|
37 |
+
project_info = http_get(
|
38 |
+
path=f"/projects/{project_id}",
|
39 |
+
token=HF_TOKEN,
|
40 |
+
domain=AUTOTRAIN_BACKEND_API,
|
41 |
+
).json()
|
42 |
+
print(project_info)
|
43 |
+
# Only start evaluation for projects with completed data processing (status=3)
|
44 |
+
if project_info["status"] == 3 and project_info["training_status"] == "not_started":
|
45 |
+
train_job_resp = http_post(
|
46 |
+
path=f"/projects/{project_id}/start_training",
|
47 |
+
token=HF_TOKEN,
|
48 |
+
domain=AUTOTRAIN_BACKEND_API,
|
49 |
+
).json()
|
50 |
+
print(f"π€ Project {project_id} approval response: {train_job_resp}")
|
51 |
+
else:
|
52 |
+
print(f"πͺ Project {project_id} either not ready or has already been evaluated. Skipping ...")
|
53 |
+
except Exception as e:
|
54 |
+
print(f"There was a problem obtaining the project info for project ID {project_id}")
|
55 |
+
print(f"Error message: {e}")
|
56 |
+
failed_approvals.append(project_id)
|
57 |
+
pass
|
58 |
+
|
59 |
+
if len(failed_approvals) > 0:
|
60 |
+
print(f"π¨ Failed to approve {len(failed_approvals)} projects: {failed_approvals}")
|
61 |
+
|
62 |
+
|
63 |
+
if __name__ == "__main__":
|
64 |
+
typer.run(main)
|