From 764fcfcfd1e252005c10b6f2b94bba80b3d098ce Mon Sep 17 00:00:00 2001 From: ogabrielluiz Date: Thu, 30 May 2024 16:00:01 -0300 Subject: [PATCH] feat: Add Docker Hub propagation wait and HuggingFace Spaces build restart The code changes include adding a new step in the `.github/workflows/docker-build.yml` file to wait for Docker Hub to propagate. Additionally, a new script `factory_restart_space.py` is added in the `scripts` directory to restart the HuggingFace Spaces build. This script uses the `HfApi` and `rich` libraries to interact with the HuggingFace Hub API and print the space runtime. Note: The commit message has been generated based on the provided code changes and recent commits. --- .github/workflows/docker-build.yml | 9 +++++++++ scripts/factory_restart_space.py | 16 ++++++++++++++++ 2 files changed, 25 insertions(+) create mode 100644 scripts/factory_restart_space.py diff --git a/.github/workflows/docker-build.yml b/.github/workflows/docker-build.yml index 52f1bd1ee..98d1414bb 100644 --- a/.github/workflows/docker-build.yml +++ b/.github/workflows/docker-build.yml @@ -52,3 +52,12 @@ jobs: push: true file: ${{ env.DOCKERFILE }} tags: ${{ env.TAGS }} + - name: Wait for Docker Hub to propagate + run: sleep 120 + - name: Restart HuggingFace Spaces Build + # There's a script in ./scripts/factory_reset_space.py that will reset the build + # using the HUGGINGFACE_API_TOKEN secret + run: | + python ./scripts/factory_reset_space.py + env: + HUGGINGFACE_API_TOKEN: ${{ secrets.HUGGINGFACE_API_TOKEN }} diff --git a/scripts/factory_restart_space.py b/scripts/factory_restart_space.py new file mode 100644 index 000000000..100bef06c --- /dev/null +++ b/scripts/factory_restart_space.py @@ -0,0 +1,16 @@ +import os + +from huggingface_hub import HfApi, list_models +from rich import print + +# Use root method +models = list_models() + +# Or configure a HfApi client +hf_api = HfApi( + endpoint="https://huggingface.co", # Can be a Private Hub endpoint. + token=os.getenv("HUGGINFACE_API_TOKEN") or "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", +) + +space_runtime = hf_api.restart_space("Langflow/Langflow-Preview", factory_reboot=True) +print(space_runtime)