Spaces:
Runtime error
Runtime error
File size: 2,513 Bytes
3ce0948 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
import os
from pathlib import Path
import typer
from datasets import load_dataset
from dotenv import load_dotenv
from utils import http_get, http_post
if Path(".env").is_file():
load_dotenv(".env")
HF_TOKEN = os.getenv("HF_TOKEN")
AUTOTRAIN_USERNAME = os.getenv("AUTOTRAIN_USERNAME")
AUTOTRAIN_BACKEND_API = os.getenv("AUTOTRAIN_BACKEND_API")
if "staging" in AUTOTRAIN_BACKEND_API:
AUTOTRAIN_ENV = "staging"
else:
AUTOTRAIN_ENV = "prod"
def main():
print(f"๐ก Starting jobs on {AUTOTRAIN_ENV} environment")
logs_df = load_dataset("autoevaluate/evaluation-job-logs", use_auth_token=HF_TOKEN, split="train").to_pandas()
# Filter out legacy AutoTrain submissions prior to project approvals requirement
projects_df = logs_df.copy()[(~logs_df["project_id"].isnull())]
# Filter IDs for appropriate AutoTrain env (staging vs prod)
projects_df = projects_df.copy().query(f"autotrain_env == '{AUTOTRAIN_ENV}'")
projects_to_approve = projects_df["project_id"].astype(int).tolist()
failed_approvals = []
print(f"๐ Found {len(projects_to_approve)} evaluation projects to approve!")
for project_id in projects_to_approve:
print(f"Attempting to evaluate project ID {project_id} ...")
try:
project_info = http_get(
path=f"/projects/{project_id}",
token=HF_TOKEN,
domain=AUTOTRAIN_BACKEND_API,
).json()
print(project_info)
# Only start evaluation for projects with completed data processing (status=3)
if project_info["status"] == 3 and project_info["training_status"] == "not_started":
train_job_resp = http_post(
path=f"/projects/{project_id}/start_training",
token=HF_TOKEN,
domain=AUTOTRAIN_BACKEND_API,
).json()
print(f"๐ค Project {project_id} approval response: {train_job_resp}")
else:
print(f"๐ช Project {project_id} either not ready or has already been evaluated. Skipping ...")
except Exception as e:
print(f"There was a problem obtaining the project info for project ID {project_id}")
print(f"Error message: {e}")
failed_approvals.append(project_id)
pass
if len(failed_approvals) > 0:
print(f"๐จ Failed to approve {len(failed_approvals)} projects: {failed_approvals}")
if __name__ == "__main__":
typer.run(main)
|