Hugging Face Spaces offer a simple way to host ML apps directly on the Hugging Face platform.
The MPEP initiative, a part of the DIBT project, identifed a use case wherein it would be desireable to have performance dashboards hosted in Spaces refresh on a schedule.
Efforts to build a BackgroundScheduler() function in the Gradio app proved imperfect.
This repository is a lightweight scheduler that leverages GitHub Actions to externally trigger dashboard rebuild and by extension, data update.
It may be generalized to induce refresh of arbitrary Hugging Face Spaces.
Follow these instructions to schedule automated rebuilds of your Hugging Face Space. You need to update the repository to point to the target Space and provide a Hugging Face write token.
- To get started, fork or clone this repository to your own GitHub account.
- Navigate to
/restart_space.py. - Refer to
restart_space()function:
def restart_space():
token = os.environ['HF_TOKEN'] # Please navigate to Settings > Secrets and variables > Actions and define "HF_TOKEN".
repo_id = "DIBT-Russian/MPEP_Dashboard" # Please replace this value with the name of your own Hugging Face Space.- Modify
DIBT-Russian/MPEP_Dashbaordto point to your Hugging Face Space using the syntax{USER OR ORGANIZATION}/{SPACE}. - In the Repository Menu, follow the path
Settings > Secrets and keys > Actions. - On the Secrets tab, click New repository secret.
- Create a new repository secret called
HF_TOKEN. - Provide a Hugging Face token with
writeaccess from the account which owns the target Space. - Navigate to
/.github/workflows/restart_hf_space.yaml. - Refer to
cronschedule:*/30 * * * *and update it to your desired value. Please note, inducing rebuild too frequently can result in errored builds caused by compute throttling from Hugging Face. On a free-tier Gradio Space, schedule*/10 * * * *proved to be too frequent and hanging builds were observed. - Commit your changes and that's it! Your rebuild scheduler is ready to go!