Rapid intensification (RI) prediction for Tropical cyclone (TC)

Streamlit — secrets — Dropbox— DNN models

Mika Rafieferantsoa
4 min readMar 30, 2022

--

I am comfortable with deploying models by dockerizing them first. But when I dockerized a DNN model and the resulting image was more than 6GB in size (using my M1 chipped laptop), I was too lazy to find a way to reduce the size (if you know a way, please send me a link), and thought I could explore other alternatives to deploy our interface.

Without even considering the deployment pipelines from Google/AWS/Azure I went straight to Streamlit and I was happy with my decision.

This post is about

  1. How can you deploy (i.e. use) your trained model(s) using Streamlit?
  2. How can you use the secrets capabilities of Streamlit to store sensitive information that you do not wish to put in the public domain. Such information can be a password, an email or a Dropbox link?
  3. Push the changes to your git repository and your web interface updates itself.

This post is not about

  1. What is Streamlit and how to use it.
  2. Training a DNN model. The title refers to how to download and use the best weights of a trained DNN model if it were stored in Dropbox or other data storage and you do not want to put the link to that storage in your public repository.

Main files

You need 2 files in your directory as building blocks of your interface.

app_folder
|____ streamlit_app.py
|____ requirements.txt

You can have as many file as you want in your app_folder on top of those required files.

streamlit_app.py should contain your desired layout for the interface, as well as any pythonic instructions you need. It is preferred (standard practice) that your main file is named streamlit_app.py to ease the Streamlit app manager to create a link for your interface.
requirements.txt should contain the libraries required/used in your app.

Once ready, push your files to your github repository.

How to deploy

Sign in to https://streamlit.io/ and connect your git repository to it, the sign-in process will guide you there without a hassle.

klkjlkjlkjlkj

When logged in, click on New app, and it will guide you to choose your github account (in our case, the one containing the app_folder repository).

Once that is done, you can deploy your app right away by just clicking on Deploy!. While deploying, keep an eye on the right pad, a black console displaying the deployment logs.

Use secrets for sensitive information

To add your sensitive information during the development, you need to create a new file secrets.toml inside a new folder .streamlit

app_folder/
|____ streamlit_app.py
|____ requirements.txt
|____.streamlit/
|____secrets.toml

You can put as much sensitive information as you wish in your secrets.toml file. Here is an example

# my email address
email = 'myemail@org.com'
# the link of to my model weights.
model_url = 'https://www.dropbox.com/xxxx/best_weights.h5?dl=1'

Once you have those information in your secrets.toml file, you can use them in your streamlit code:

Your .streamlit folder will not be pushed to the repository. For your deployed app to know about your secrets, add them to the secrets modal. To find the later, navigate the following steps:

Manage app (bottom right of your streamlit page)> Settings > Secrets

If you know your secrets in advance, before you even deployed the app (Deploy! button), add them directly to the Secrets modal via “Advanced settings…” (on the Deploy! page).

Copy the content of your secrets.toml and paste it there and Save. The secrets should be in a TOML format.

Your app/interface will update itself.

How to make changes on your app

You will want to add new features, fix some typo or change the overall layout of your interface.

To do that, you only need to push your changes to the repository and the app will update itself. Only keep an eye on the app manager console as you might have missed some bugs.

Example of a deployed app

Please see my repository and my interface related to this post.
I am still learning and any critics or advice to improve are very welcome.

--

--