Skip to content

Automates the process of restarting and rebuilding Hugging Face spaces.

License

Notifications You must be signed in to change notification settings

fuegovic/HF-Restarter

Repository files navigation

HF-Restarter 🤗⌛

HF-Restarter is a Python script that automates the process of restarting and rebuilding Hugging Face spaces. It uses the HfApi class from the huggingface_hub library to interact with the Hugging Face API and schedule the restart and rebuild operations at regular intervals.

Installation and Usage

  • Install the required dependencies using pip: pip install -r requirements.txt
  • Create a .env file in the same directory as your script and add the following environment variables:
    • USERNAME: your Hugging Face username. You can find your username on your profile page here.
    • TOKEN: your Hugging Face token. Use a token with write access. You can generate a token from your settings page here.
    • OWNER: the owner of the space you want to restart or rebuild
    • NAME: the name of the space you want to restart or rebuild
    • RESTART_DELAY: the number of minutes between each restart
    • REBUILD_DELAY: the number of minutes between each rebuild
  • Run the script using python: python restarter.py
  • The script will print the current time and the time until the next restart and rebuild every minute. It will also print a message when it performs a restart or rebuild operation.

How it works

The script uses the schedule library to create a simple scheduler that runs two functions: restart_space and rebuild_space. These functions use the HfApi.restart_space method to send a request to the Hugging Face API to restart or rebuild a given space. The script also defines a helper function print_next_job_time that prints the current time and the time until the next restart and rebuild. The script calls this function every minute using the scheduler.

The script uses the dotenv library to load the environment variables from the .env file. These variables are used to create an instance of the HfApi class and to pass the parameters to the restart_space method. The script also uses the datetime library to calculate the time until the next restart and rebuild, and to format the time in a user-friendly way.

Benefits and Limitations

The script provides a simple and convenient way to automate the restart and rebuild of Hugging Face spaces. It can help you avoid manual intervention and ensure that your spaces are always up to date and running smoothly. It can also help you save resources and avoid unnecessary costs by restarting or rebuilding your spaces only when needed.

However, the script also has some limitations and drawbacks. For example, it does not handle any errors or exceptions that may occur during the restart or rebuild process. It also does not provide any feedback or notification on the status or outcome of the restart or rebuild operations. It also does not allow you to customize the restart or rebuild parameters, such as the factory reboot option or the branch name. Moreover, the script relies on the availability and functionality of the Hugging Face API, which may change or break at any time.

License

This project is licensed under the MIT License. See the LICENSE file for more details.

Acknowledgements

This project was inspired by the Hugging Face Spaces platform, which provides a simple and easy way to deploy machine learning models and applications. This project also uses the huggingface_hub library, which provides a high-level interface to the Hugging Face API. This project also uses the schedule library, which provides a human-friendly way to schedule tasks in Python. This project also uses the dotenv library, which loads environment variables from a .env file.

About

Automates the process of restarting and rebuilding Hugging Face spaces.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Languages