Manage your Space
Last updated
Last updated
In this guide, we will see how to manage your Space runtime (, , and ) using boincai_hub
.
Here is an end-to-end example to create and setup a Space on the Hub.
1. Create a Space on the Hub.
Copied
1. (bis) Duplicate a Space.
This can prove useful if you want to build up from an existing Space instead of starting from scratch. It is also useful is you want control over the configuration/settings of a public Space. See for more details.
Copied
2. Upload your code using your preferred solution.
Here is an example to upload the local folder src/
from your machine to your Space:
Copied
At this step, your app should already be running on the Hub for free ! However, you might want to configure it further with secrets and upgraded hardware.
3. Configure secrets and variables
Copied
Secrets and variables can be deleted as well:
Copied
From within your Space, secrets are available as environment variables (or Streamlit Secrets Management if using Streamlit). No need to fetch them via the API!Any change in your Space configuration (secrets or hardware) will trigger a restart of your app.
Bonus: set secrets and variables when creating or duplicating the Space!
Secrets and variables can be set when creating or duplicating a space:
Copied
Copied
4. Configure the hardware
Copied
Hardware updates are not done immediately as your Space has to be reloaded on our servers. At any time, you can check on which hardware your Space is running to see if your request has been met.
Copied
You now have a Space fully configured. Make sure to downgrade your Space back to ācpu-classicā when you are done using it.
Bonus: request hardware when creating or duplicating the Space!
Upgraded hardware will be automatically assigned to your Space once itās built.
Copied
Copied
5. Pause and restart your Space
Copied
Copied
Note: if you are using a ācpu-basicā hardware, you cannot configure a custom sleep time. Your Space will automatically be paused after 48h of inactivity.
Bonus: set a sleep time while requesting hardware
Upgraded hardware will be automatically assigned to your Space once itās built.
Copied
Bonus: set a sleep time when creating or duplicating the Space!
Copied
Copied
6. Add persistent storage to your Space
Copied
You can also delete your storage, losing all the data permanently.
Copied
Note: You cannot decrease the storage tier of your space once itās been granted. To do so, you must delete the storage first then request the new desired tier.
Bonus: request storage when creating or duplicating the Space!
Copied
Copied
Spaces allow for a lot of different use cases. Sometimes, you might want to temporarily run a Space on a specific hardware, do something and then shut it down. In this section, we will explore how to benefit from Spaces to finetune a model on demand. This is only one way of solving this particular problem. It has to be taken as a suggestion and adapted to your use case.
Letās assume we have a Space to finetune a model. It is a Gradio app that takes as input a model id and a dataset id. The workflow is as follows:
(Prompt the user for a model and a dataset)
Load the model from the Hub.
Load the dataset from the Hub.
Finetune the model on the dataset.
Upload the new model to the Hub.
Step 3. requires a custom hardware but you donāt want your Space to be running all the time on a paid GPU. A solution is to dynamically request hardware for the training and shut it down afterwards. Since requesting hardware restarts your Space, your app must somehow ārememberā the current task it is performing. There are multiple ways of doing this. In this guide we will see one solution using a Dataset as ātask schedulerā.
Here is what your app would look like. On startup, check if a task is scheduled and if yes, run it on the correct hardware. Once done, set back hardware to the free-plan CPU and prompt the user for a new task.
Such a workflow does not support concurrent access as normal demos. In particular, the interface will be disabled when training occurs. It is preferable to set your repo as private to ensure you are the only user.Copied
Scheduling tasks can be done in many ways. Here is an example how it could be done using a simple CSV stored as a Dataset.
Copied
Your Space might require some secret keys, token or variables to work. See for more details. For example, an HF token to upload an image dataset to the Hub once generated from your Space.
By default, your Space will run on a CPU environment for free. You can upgrade the hardware to run it on GPUs. A payment card or a community grant is required to access upgrade your Space. See for more details.
By default if your Space is running on an upgraded hardware, it will never be stopped. However to avoid getting billed, you might want to pause it when you are not using it. This is possible using . A paused Space will be inactive until the owner of the Space restarts it, either with the UI or via API using . For more details about paused mode, please refer to
Another possibility is to set a timeout for your Space. If your Space is inactive for more than the timeout duration, it will go to sleep. Any visitor landing on your Space will start it back up. You can set a timeout using . For more details about sleeping mode, please refer to .
You can choose the storage tier of your choice to access disk space that persists across restarts of your Space. This means you can read and write from disk like you would with a traditional hard drive. See for more details.