Chainlit#

Tip

Ploomber Cloud is a great platform to host your Chainlit apps, even Chainlit recommends us!

To deploy a Chainlit application in Ploomber Cloud you need:

Dockerfile#

You need to provide a Dockerfile, you can use this template to get started. The template contains the minimal steps needed for a deployment but you need to modify so it installs any required dependencies and copies your code into the Docker image.

FROM python:3.11

COPY app.py app.py
RUN pip install chainlit

# do not change the arguments
ENTRYPOINT ["chainlit", "run", "app.py", "--host=0.0.0.0", "--port=80", "--headless"]

Testing locally#

To test your app, you can use docker locally:

# build the docker image
docker build . -t chainlit

# run it
docker run -p 5000:80 chainlit

Now, open http://0.0.0.0:5000/ to see your app.

Deploy#

Once you have all your files, create a zip file.

To deploy a Chainlit app from the deployment menu, follow these instructions:

Tip

To ensure your app doesn’t break on re-deployments, pin your dependencies.

Features#

Ploomber Cloud supports many features to help you build Streamlit applications quickly!

Password protection#

Currently, our password authentication feature doesn’t work with Chainlit, however, we can still use Chainlit’s authentication feature.

First, download the sample code. The Dockerfile remains the same, the only change happens in the app.py.

During deployment, you need to provide three secrets:

CHAINTLIT_USERNAME="user"
CHAINTLIT_PASSWORD="somepassword"

CHAINLIT_AUTH_SECRET="somerandomstring"

CHAINLIT_AUTH_SECRET is a random string used to authenticate user tokens, you can generate one by executing the following command in your terminal:

python -c 'from secrets import token_hex; print(token_hex(16))'

Note

You can change CHAINLIT_AUTH_SECRET, but it’ll log out all your users.

Examples#

Basic app

App with password

Chat with PDF

Private ChatGPT