Dealing with more advanced web app features
In Chapter 8, we stopped our development at the point shown in the following figure:
Figure 9.1: Chapter09 starting point
So, let’s start working on the menu’s three voices: Image Enhancement, Diagnosis, and Disclaimer and Info. Before that, since we are entering some advanced features of Streamlit and considering that new versions are released quite often, it’s very important to remember how Streamlit’s official documentation (https://docs.streamlit.io/) is always the best place to get detailed info about all the available components and APIs; for example, in case you have any doubts about, let’s say, the Image widget, you can just search for it in the API reference menu on the left side of the official documentation page or directly in the search bar in the top-right corner and check out all the results.
Figure 9.2: Streamlit’s official documentation
Let’s open our code in Sublime Text and let’s continue with our development since, at the moment, we have only an empty menu.
We have already defined a list of voices for our menu, which is called activities, and an if clause that checks which of these voices has been selected and put in a variable named choice; our job now is to write the business logic for each one of these three possibilities:
Figure 9.3: The points where the business logic has to be inserted
We know very well that pass is just a placeholder, so we can start our coding from the first one of the menu voices: Image Enhancement.
Images can be enhanced in many ways – for example, by changing their brightness or contrast. So we can use some radio buttons in the sidebar to give the user the faculty to choose what kind of enhancement they want to perform.
The radio buttons, as we should know, have a couple of mandatory arguments: a label (a title) and a list of all the items that can be selected:
Figure 9.4: Radio button for Image Enhancement
As usual, the list of items in the radio button contains all the features we want to show on the screen:
Figure 9.5: Radio button in the browser
It’s quite clear that now we need some if clauses. This is because if the enhance_type variable is Original, we need to do something; if it’s Contrast, we need to do something different, and if it’s Brightness, we need to do something else:
Figure 9.6: If clauses for “Image Enhancement”
As already said, pass is just a placeholder, so let’s take care of these if clauses one by one. The first one is Contrast.