Reader small image

You're reading from  Web App Development Made Simple with Streamlit

Product typeBook
Published inFeb 2024
PublisherPackt
ISBN-139781835086315
Edition1st Edition
Right arrow
Author (1)
Rosario Moscato
Rosario Moscato
author image
Rosario Moscato

Rosario Moscato has a master's degree in electronic engineering, a second level master in internet software design and a first level master's in science and faith. In about 25 years of experience, he has worked on innovative technology development in Europe and Asia. Recently, his interests have been focused exclusively on AI, pursuing the goal of making every business extremely competitive and analyzing the ethical implications deriving from the new scenarios that these disciplines open. Rosario has authored two books, and he is a speaker at international research centres and conferences as well as a trainer and technical/scientific consultant. Currently, he is working as CTO with one of the oldest AI companies in Italy.
Read more about Rosario Moscato

Right arrow

Deploying and Managing Complex Libraries on Streamlit Share

Let’s continue our exploration of deployment on Streamlit Share, a service provided by the Streamlit framework that allows users to deploy their web applications, implemented with Streamlit, to the cloud with just a few clicks. This time, we have to pack up the Covid-19 Detection Tool app and try to deploy it. Many heavy libraries will be involved here, so this time, the task is a little bit more complex.

When we deal with heavy files, the deployment task becomes more difficult because GitHub has some limitations regarding file size; in fact, it is not possible to directly upload files with a size over 25 MB. In the case of our Covid-19 Detection Tool app, unfortunately, the file of the AI model is over 25 MB. Files to be uploaded on GitHub can’t be any bigger than this, at least at the time of writing this book.

There are some techniques we can use to bypass this limit; I’ll show you a rather smart...

Technical requirements

Consolidating cloud deployment skills

Considering that we are at Chapter 11 of this book, we should be aware of the fact that implementing a web application is only one part of the process and that the process ends only when the web app is deployed and shared.

We already understand the importance of web application deployment as we covered this when we created the NLP web application in the first part of this book, as well as because it’s one of the first things we see when we land on Streamlit’s website:

Figure 11.1: Streamlit’s slogan about app sharing

Figure 11.1: Streamlit’s slogan about app sharing

When we click on the Cloud voice of the main menu, we are redirected to a page containing a quick video about the deployment and an important declaration: Deploy, manage, and share your apps with the world, directly from Streamlit — all for free:

Figure 11.2: Streamlit Cloud

Figure 11.2: Streamlit Cloud

The most important message here is share your apps with the world. A...

Avoiding bad behavior

Bad behavior is any kind of missing, wrong, or incomplete action that produces a runtime problem during the deployment, where the result is the deployment task failing. For this reason, in this section, we will learn about the steps that are required to complete any deployment.

Creating a list of all the packages that were installed and used to develop the Python code

The first thing we need to run our web application is the list of all the packages that were installed and used to develop the Python code. As we know, there are several ways to get this list, but the easiest one is to use pipreqs. Let’s take a look:

  1. First of all, let’s install pipreqs by typing the following command in the Terminal:
    pipenv install pipreqs (simply "pip install pipreqs" if you are not using pipenv)
  2. Then, we can create the requirements.txt file with the following simple instruction:
    pipreqs ./covid

    Here, covid is the name of the directory containing...

Managing difficult libraries

To fix the problem of file size, we must install the GitHub Desktop application, which at the time of writing is only available for Windows or macOS. So, follow these steps:

  1. Download the GitHub Desktop application from desktop.github.com and install it.
  2. Then, log into your GitHub account and authorize. You should see the following window:
Figure 11.7: GitHub Desktop application

Figure 11.7: GitHub Desktop application

  1. Now, select the covid19-book repository (if you used another name, you must look for it) and click Clone....

    A clone of the repository will be created on your machine, as shown in Figure 11.8:

Figure 11.8: Cloning the GitHub repository locally

Figure 11.8: Cloning the GitHub repository locally

  1. Once the cloning operation is finished, open the local folder of the repository on your Mac Finder or via Windows File Explorer, as shown in Figure 11.9:
Figure 11.9: Local folder of the repository

Figure 11.9: Local folder of the repository

  1. Now, create the...

Deploying the app on Streamlit Cloud

The hardest part is over. From here on, we can follow the same procedure we adopted for the NLP web application. Here are the steps:

  1. Sign into Streamlit Cloud by selecting Continue with Github, authorizing and using the same account you used for GitHub.
  2. Once you’re in, select New app.

You should only have the application we created in Chapter 7 among the deployed applications. The window should look like what’s shown in Figure 11.14:

Figure 11.14: Creating a new app on Streamlit Cloud

Figure 11.14: Creating a new app on Streamlit Cloud

  1. After selecting New app, in the new form, choose the right repository, the main branch, and the name of the Python file (it should be app.py), and specify a meaningful name to the app URL, as shown in Figure 11.15:
Figure 11.15: Deploying the web app on Streamlit Cloud

Figure 11.15: Deploying the web app on Streamlit Cloud

  1. When everything is ready, click Deploy! and wait since Your app is in the oven:
...

Summary

Great job! Deploying the Covid-19 Detection Tool app was complex. As we saw, there are many potential problems to avoid.

First of all, we needed to recreate the same structure of files and directories that were used in the Python code, and not forget to also include the picture files in the GitHub repository.

The second problem was allowing Streamlit Cloud to manage all the dependencies related to opencv. To do this, it was necessary to add a packages.txt file to the repository containing the instructions to get these dependencies.

Finally, we found out that GitHub – at least its online version – only manages files that are smaller than 25 MB, but sometimes, such as with the CNN AI model, we need to upload bigger files. This operation requires us to install the GitHub Desktop application and the local (on our computers) cloning of the repository. Once we have the repository on our computers, we can add this big file and push it back toward the origin...

lock icon
The rest of the chapter is locked
You have been reading a chapter from
Web App Development Made Simple with Streamlit
Published in: Feb 2024Publisher: PacktISBN-13: 9781835086315
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
undefined
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime

Author (1)

author image
Rosario Moscato

Rosario Moscato has a master's degree in electronic engineering, a second level master in internet software design and a first level master's in science and faith. In about 25 years of experience, he has worked on innovative technology development in Europe and Asia. Recently, his interests have been focused exclusively on AI, pursuing the goal of making every business extremely competitive and analyzing the ethical implications deriving from the new scenarios that these disciplines open. Rosario has authored two books, and he is a speaker at international research centres and conferences as well as a trainer and technical/scientific consultant. Currently, he is working as CTO with one of the oldest AI companies in Italy.
Read more about Rosario Moscato