Spaces:
Runtime error
Runtime error
Add local dev
Browse filesFiles changed (5)
- .env.exampleDeleted-4
- .env.templateAdded+4
- README.md+6
- app.py+67-41
- run_evaluation_jobs.py+24-13
1234AUTOTRAIN_USERNAME=autoevaluator # The bot that authors evaluation jobsHF_TOKEN=hf_xxx # An API token of the `autoevaluator` userAUTOTRAIN_BACKEND_API=https://api-staging.autotrain.huggingface.co # The AutoTrain backend to send jobs to. Use https://api.autotrain.huggingface.co for prodDATASETS_PREVIEW_API=https://datasets-server.huggingface.co # The API to grab dataset information from1234AUTOTRAIN_USERNAME=autoevaluator # The bot or user that authors evaluation jobsHF_TOKEN=hf_xxx # An API token of the `autoevaluator` userAUTOTRAIN_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 developmentDATASETS_PREVIEW_API=https://datasets-server.huggingface.co # The API to grab dataset information from53 unmodified lines5455565753 unmodified lines```AUTOTRAIN_BACKEND_API=https://api.autotrain.huggingface.co```53 unmodified lines5455565758596061626353 unmodified lines```AUTOTRAIN_BACKEND_API=https://api.autotrain.huggingface.co```To evaluate models with a _local_ instance of AutoTrain, change the environment to:```AUTOTRAIN_BACKEND_API=http://localhost:8000```
1234510 unmodified lines515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561import osfrom pathlib import Pathimport pandas as pd510 unmodified linestoken=HF_TOKEN,domain=AUTOTRAIN_BACKEND_API,).json()print(f"INFO -- AutoTrain job response: {train_json_resp}")if train_json_resp["success"]:train_eval_index = {"train-eval-index": [{"config": selected_config,"task": AUTOTRAIN_TASK_TO_HUB_TASK[selected_task],"task_id": selected_task,"splits": {"eval_split": selected_split},"col_mapping": col_mapping,}]}selected_metadata = yaml.dump(train_eval_index, sort_keys=False)dataset_card_url = get_dataset_card_url(selected_dataset)st.success("β Successfully submitted evaluation job!")st.markdown(f"""Evaluation can take up to 1 hour to complete, so grab a βοΈ or π΅ while you wait:* π 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.* π 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.* π₯± Tired of configuring evaluations? Add the following metadata to the [dataset card]({dataset_card_url}) to enable 1-click evaluations:""" # noqa)st.markdown(f"""```yaml{selected_metadata}""")print("INFO -- Pushing evaluation job logs to the Hub")evaluation_log = {}evaluation_log["project_id"] = project_json_resp["id"]evaluation_log["is_evaluated"] = Falseevaluation_log["payload"] = project_payloadevaluation_log["project_creation_response"] = project_json_respevaluation_log["dataset_creation_response"] = data_json_respevaluation_log["autotrain_job_response"] = train_json_respcommit_evaluation_log(evaluation_log, hf_access_token=HF_TOKEN)else:st.error("π Oh no, there was an error submitting your evaluation job!")else:st.warning("β οΈ No models left to evaluate! Please select other models and try again.")12345510 unmodified lines516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587import osimport timefrom pathlib import Pathimport pandas as pd510 unmodified linestoken=HF_TOKEN,domain=AUTOTRAIN_BACKEND_API,).json()# For local development we process and approve projects on-the-flyif "localhost" in AUTOTRAIN_BACKEND_API:with st.spinner("β³ Waiting for data processing to complete ..."):is_data_processing_success = Falsewhile is_data_processing_success is not True:project_status = http_get(path=f"/projects/{project_json_resp['id']}",token=HF_TOKEN,domain=AUTOTRAIN_BACKEND_API,).json()if project_status["status"] == 3:is_data_processing_success = Truetime.sleep(10)# Approve training jobtrain_job_resp = http_post(path=f"/projects/{project_json_resp['id']}/start_training",token=HF_TOKEN,domain=AUTOTRAIN_BACKEND_API,).json()st.success("β Data processing and project approval complete - go forth and evaluate!")else:# Prod/staging submissions are evaluated in a cron job via the run_evaluation_jobs.py scriptprint(f"INFO -- AutoTrain job response: {train_json_resp}")if train_json_resp["success"]:train_eval_index = {"train-eval-index": [{"config": selected_config,"task": AUTOTRAIN_TASK_TO_HUB_TASK[selected_task],"task_id": selected_task,"splits": {"eval_split": selected_split},"col_mapping": col_mapping,}]}selected_metadata = yaml.dump(train_eval_index, sort_keys=False)dataset_card_url = get_dataset_card_url(selected_dataset)st.success("β Successfully submitted evaluation job!")st.markdown(f"""Evaluation can take up to 1 hour to complete, so grab a βοΈ or π΅ while you wait:* π 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.* π 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.* π₯± Tired of configuring evaluations? Add the following metadata to the [dataset card]({dataset_card_url}) to enable 1-click evaluations:""" # noqa)st.markdown(f"""```yaml{selected_metadata}""")print("INFO -- Pushing evaluation job logs to the Hub")evaluation_log = {}evaluation_log["project_id"] = project_json_resp["id"]evaluation_log["autotrain_env"] = ("staging" if "staging" in AUTOTRAIN_BACKEND_API else "prod")evaluation_log["payload"] = project_payloadevaluation_log["project_creation_response"] = project_json_respevaluation_log["dataset_creation_response"] = data_json_respevaluation_log["autotrain_job_response"] = train_json_respcommit_evaluation_log(evaluation_log, hf_access_token=HF_TOKEN)else:st.error("π Oh no, there was an error submitting your evaluation job!")else:st.warning("β οΈ No models left to evaluate! Please select other models and try again.")
15 unmodified lines1617181920212223242526272829303132333435363738394041424315 unmodified linesAUTOTRAIN_USERNAME = os.getenv("AUTOTRAIN_USERNAME")AUTOTRAIN_BACKEND_API = os.getenv("AUTOTRAIN_BACKEND_API")def main():logs_df = load_dataset("autoevaluate/evaluation-job-logs", use_auth_token=True, split="train").to_pandas()evaluated_projects_ds = load_dataset("autoevaluate/evaluated-project-ids", use_auth_token=True, split="train")projects_df = logs_df.copy()[(~logs_df["project_id"].isnull()) & (logs_df["is_evaluated"] == False)]projects_to_approve = projects_df["project_id"].astype(int).tolist()for project_id in projects_to_approve:project_status = http_get(path=f"/projects/{project_id}",token=HF_TOKEN,domain=AUTOTRAIN_BACKEND_API,).json()if project_status["status"] == 3: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}")# if train_job_resp["approved"] == True:# # Update evaluation statusif __name__ == "__main__":15 unmodified lines16171819202122232425262728293031323334353637383940414243444546474849505152535415 unmodified linesAUTOTRAIN_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():logs_df = load_dataset("autoevaluate/evaluation-job-logs", use_auth_token=True, split="train").to_pandas()# Filter out# - legacy AutoTrain submissions prior to project approvals was implemented# - submissions for appropriate AutoTrain environment (staging vs prod)projects_df = logs_df.copy()[(~logs_df["project_id"].isnull()) & (logs_df.query(f"autotrain_env == '{AUTOTRAIN_ENV}'"))]projects_to_approve = projects_df["project_id"].astype(int).tolist()for project_id in projects_to_approve:try:project_info = http_get(path=f"/projects/{project_id}",token=HF_TOKEN,domain=AUTOTRAIN_BACKEND_API,).json()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}")except:print(f"There was a problem obtaining the project info for project ID {project_id}")passif __name__ == "__main__":
.env.exampleDeleted-4
.env.templateAdded+4
README.md+6
app.py+67-41
run_evaluation_jobs.py+24-13