Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automatically restart spaces if they're down #2405

Merged
merged 5 commits into from
Oct 11, 2022
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ No changes to highlight.
No changes to highlight.

## Full Changelog:
No changes to highlight.
* Automatically restart spaces if they're down by [@aliabd](https://github.com/aliabd) in [PR 2405](https://github.com/gradio-app/gradio/pull/2405)

## Contributors Shoutout:
No changes to highlight.
Expand Down
10 changes: 10 additions & 0 deletions website/homepage/src/demos/restart_demos.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from upload_demos import demos_by_category, upload_demo_to_space, AUTH_TOKEN, gradio_version
from gradio.networking import url_ok


for category in demos_by_category:
for demo in category["demos"]:
space_id = "gradio/" + demo["dir"]
if not url_ok(f"https://hf.space/embed/{space_id}/+"):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note that those URLs will change soon-ish :)

(but when they change, they will be then considered "public API" ie. they won't change again after that)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for clarifying @julien-c, will make sure to change this when the urls change.

Do you know if there's a way in the api to programmatically check if the space has a build error? Instead of the way I'm doing it now which is checking if the url returns 200

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes there's a way

Stage should be exposed in SpaceInfo in huggingface_hub, for instance

print(f"{space_id} was down, restarting")
upload_demo_to_space(demo_name=demo["dir"], space_id=space_id, hf_token=AUTH_TOKEN, gradio_version=gradio_version)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will this trigger a restart if this files haven't changed?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, which is intended. We don't only restart demos when files have changed. We also restart them when the version is changed. This just restarts them if they're down.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed. My question is, will this be sufficient to restart the Space? In other words, if you push to a Space and the files haven't changed, will it actually restart the Space?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh got it @abidlabs, yes it will.

10 changes: 6 additions & 4 deletions website/homepage/src/demos/upload_demos.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,10 @@ def upload_demo_to_space(
)
return f"https://huggingface.co/spaces/{space_id}"

for category in demos_by_category:
for demo in category["demos"]:
space_id = "gradio/" + demo["dir"]
upload_demo_to_space(demo_name=demo["dir"], space_id=space_id, hf_token=AUTH_TOKEN, gradio_version=gradio_version)
if __name__ == "__main__":
if AUTH_TOKEN is not None:
for category in demos_by_category:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like this includes all of the demos in recipe_demos.json but what about demos in other parts of the website like the docs and homepage?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still working on that in the other PR.

for demo in category["demos"]:
space_id = "gradio/" + demo["dir"]
upload_demo_to_space(demo_name=demo["dir"], space_id=space_id, hf_token=AUTH_TOKEN, gradio_version=gradio_version)