set_page_config accepts a certain number of arguments, as follows:
- page_title: The title of our page; this is a string
- page_icon: An icon (an image file) or an emoji (the emoji itself or its code)
- layout: This can be centered or wide
- initial_sidebar_state: This can be wide, expanded, or collapsed
You can experiment with different configurations and easily find information on how to use each instruction in Streamlit’s Documentation section, which includes input arguments and output results.
The following screenshot explains the set_page_config() instruction. As you can see, there are several different configurations that we didn’t explore, and it’s possible to combine them to fully customize your web application. So, please don’t forget to carefully check the official Streamlit documentation to get the most value out of this incredible framework:
Figure 4.22: Streamlit’s official documentation
Now that we’ve looked at Streamlit’s official documentation, let’s have a look at our web application with the new page title and icon:
Figure 4.23: Icon and title customization in the browser panel
As you can see, in the browser tile related to our web application, we have a full set of customizations: an icon representing a thumb and a personalized title stating NLP Web App. This is the result of the code we saw in Figure 4.21.
If you want to, you can see what happens upon changing the 👍 emoji we used as an icon with an image, such as a PNG file that you like. You can also check how the web application behaves when we set initial_sidebar_state to wide, expanded, or collapsed and layout to wide.
The decorations we added to our web app skeleton are clean, neat, and good-looking but up until now, excluding the About section, which can be considered closed, the rest need to be completed with some business logic to make the various Text Analysis, Translation, and Sentiment Analysis tasks work properly. This is exactly what we are going to do in the next chapter.
The following figure shows all the code we wrote. It’s quite interesting to point out how, in only 64 lines of code, including empty lines and comments, we have built up a working web application that lives on the web and can be used by a browser and that contains a menu, some sections, HTML, titles, and decorations:
Figure 4.24: The app.py file
The best part is that you can reuse it as you wish!
Summary
In this chapter, we began from scratch. First of all, we prepared our pipenv environment, installed all packages needed for the web application, and finally created an empty Python file.
After that, we built up a skeleton that can be reused any time we want to develop a new web application. This skeleton is made up of an initial part where we import all the packages we need and a main function that is dedicated to containing all the business logic of our web app.
In the first part of the main function, some features must be applied to the entire web application, such as its title and subtitle, which we created with very beautiful and colorful HTML, and the web browser’s panel icon and title.
In the second part of the main function, we created a menu that will be shown on the left-hand side of our web application and that lets the user choose from the various tasks our web application can perform. Upon selecting one of the tasks in the menu, the web application will show its specific section performing its specific task. We implemented this because we wanted to start with a very easy case. The About section now performs well, showing the name/title of the web application and some useful information – in this case, the working link to Streamlit’s website.
Everything is working well and has been customized according to our willingness and future needs. This shows that this skeleton is a great weapon in our developer’s toolkit!
In the next chapter, we’ll start building the complete business logic of our application by using and learning about some very powerful widgets such as columns and expanders, as well as some NLP techniques!