kghamilton89 / spaces-scheduler

This is an automatic scheduler to restart your Hugging Face Space according to a cron job schedule.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

🤗 Spaces Scheduler

Please note, this mechanism has been optimized as a runtime solution. Whilst the core methodology remains viable, there is a more elegant way to implement this feature according to this template.

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.

Usage

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.

  1. To get started, fork or clone this repository to your own GitHub account.
  2. Navigate to /restart_space.py.
  3. 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.
  1. Modify DIBT-Russian/MPEP_Dashbaord to point to your Hugging Face Space using the syntax {{USER OR ORGANIZATION}}/{{SPACE}}.
  2. In the Repository Menu, follow the path Settings > Secrets and keys > Actions.
  3. On the Secrets tab, click New repository secret.
  4. Create a new repository secret called HF_KEY.
  5. Provide a Hugging Face token with write access from the account which owns the target Space.
  6. Navigate to /.github/workflows/restart_hf_space.yaml.
  7. Refer to cron schedule: */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.
  8. Commit your changes and that's it! Your rebuild scheduler is ready to go!

About

This is an automatic scheduler to restart your Hugging Face Space according to a cron job schedule.

License:Apache License 2.0


Languages

Language:Python 100.0%