Skip to main content

Deploying Streamlit/Gradio apps

XetHub supports deploying Streamlit and Gradio applications stored in XetHub through our capsules feature. This makes it easy for developers to quickly share interactive experiences for others to use or build upon.

Current specifications:

  • All capsules run on 2vCPU with 5GB RAM
  • Capsules use Python 3.9 on Debian Linux
  • Capsules are deleted if not accessed for 48 hours

Check out our Data Summarizer repository for a running example of requirements, application code, and interactive capsule.


Creating a capsule

Navigating to the Capsules tab of any repository you own will provide the option to create a new Streamlit or Gradio capsule.

Capsules will install the dependencies from requirements.txt in your root directory and run your app.py application. Deployed applications may take a few minutes to start running.

By default, capsules launch from the main branch. To compare applications across branches, use the + in the header to launch a new capsule from a different branch. All Capsules tabs are named by the branch they are launched from.

Capsule settings

Other than the branch, the capsule settings are tied to the repository. Select the Settings tab on any repository and click on the Capsules section to access the repository settings for each capsule.

Screenshot of Capsule Repository Settings

Within the repository settings, you have a few options to configure:

SDK

Screenshot of Capsule SDK Settings

We officially support Streamlit and Gradio app deployment. Streamlit and Gradio are powerful web-based user interface APIs for machine learning UX development. We recommend starting with one of these two APIs.

If you find that neither of these options work for you, we have a Custom SDK setting. This requires that you properly configure the startup command and port for running your app. Also, as capsules are containerized, you will need to ensure that they work in a container. The most common issue centers around the IP you are serving on. For your service, make sure to serve on 0.0.0.0 instead of 127.0.0.1.

Screenshot of Capsule Custom Settings

When you have determined what SDK option to use, select the appropriate SDK in the Capsule Settings.

We assume the following ports.

  • Streamlit: Port 8501
  • Gradio: Port 7860
  • Custom: Port 8080

Main file path

Screenshot of Main File Path

This is the entry point of your capsule if you are using the Streamlit or Gradio SDKs. By default, we will look for an app.py file, but you can select a different entry point from the list of available Python files in your repository.

This setting isn't available for a capsule using a Custom SDK. Specify the file path as part of the startup command.

Secrets

Screenshot of Capsule Secrets

Custom runtime environment variables can be specified in the advanced settings, which is highly recommended for securely specifying API keys without exposing them in your code. Click the Add button to add a new secret to your capsule launch settings.

There are two types of secrets, private (the default) and public. Secrets are private by default. This means that they won't be copied when the repository is forked or cloned. Public secrets will be visible to all with access to your repository. Unclick the checkbox to make it public. Any values you set will be visible to anyone who can duplicate or fork the repository, so don't use it to set API keys or any private information on a public repository.

Capsule lifetime

Capsules are automatically shut down after 48 hours of inactivity.

Updating a capsule

If you have made changes to your repository and want them to be reflected in your capsule, you can manually trigger a code refresh. This can be done from the Capsules tab by clicking on the branch name and selecting: Refresh Capsule from the dropdown:

Screenshot of Capsule Menu

If you have changed any of the capsule settings and would like that to be reflected, you will need to restart it by bringing it down and re-creating it.

This can be done from the Capsules tab by clicking on the branch name and selecting: Bring Capsule Down from the dropdown:

Screenshot of Capsule Menu

Once the capsule has been shut down, restart it by creating a new capsule from the appropriate branch.