Recap of our first web application
It’s incredible, but we really did it! Starting from scratch, from an empty file, we created a well-working web application that performs a lot of tasks and provides us with very nice outputs.
First of all, we created a Python environment, and then we installed all the required libraries in it. After that, we started building the skeleton of our application. This point is very important because this skeleton, consisting of a menu that contains all the main features of our web application and various parts of code to manage these features, is something that we can reuse any time we want to create a new application.
The code of the application was created using basic widgets in Streamlit, that is, titles, subheaders, buttons, text areas, warnings, info, and so on, as well as some very interesting components, such as columns and expanders.
We also learned how to add some basic HTML in our web applications, as well as some basic Markdown. We used these techniques to add some beautiful customizations on the titles. We then continued by talking about customizations. We also saw a way to associate a beautiful icon and a meaningful title or name to our application’s web browser window.
We delved into some fundamental concepts around NLP: tokens, lemmas, stopwords, word clouds, summarization, sentiment analysis, polarity, and objectivity. Our web app now also contains a very useful About section with information and working hyperlinks, which can be customized as you prefer.
Here are some screenshots of the final version of our application:
Figure 6.22: Text Analysis
In Figure 6.22, we can see the complete menu on the left side of the screen and the result of the Text Analysis function applied to the short sentence in the text area in the main part of the web app.
Figure 6.23: Translation
Figure 6.23 shows the behavior of the Translation function. This is quite self-explanatory: a sentence is typed into the text area, then a target language is selected, and finally, on pressing the Translate button, the translation task is performed and the result is displayed on the screen.
Figure 6.24: Sentiment Analysis
Figure 6.24 shows an example of Sentiment Analysis, which in this case shows a very high polarity.
We close the sequence of screenshots from the NLP web application we made together with the About section, as shown in Figure 6.25.
Figure 6.25: The About section
The About section is very useful since it contains information about the author, links to external web pages, and so on.
Here is all the code we have written together up to now:
Figure 6.26: NLP web application code part 1
In part 1, we imported the packages, set the page configuration, and defined the summarize_text function.
Figure 6.27: NLP web application code part 2
In part 2, we wrote the text_analyzer function, then the main function, which contains the main title of the application, a subheading, and the menu in the sidebar.
Figure 6.28: NLP web application code part 3
In part 3, we developed the main function using an if loop and many advanced widgets, such as columns and expanders.
Figure 6.29: NLP web application code part 4
In part 4, we mainly developed the Translation feature, making it possible to insert text and select a language.
Figure 6.30: NLP web application code part 5
In part 5, we implemented the Sentiment Analysis feature, leveraging the TextBlob library, then completed the web app by adding the About section.
The full listing of our web application’s code makes it clear how powerful Streamlit is. Less than 200 lines of code are enough to create a fully working web application with a lot of advanced features and quite a nice look and feel. We achieved this result just using standard Python, with no need for HTML, CSS, JavaScript, and so on.
Summary
Our web application utilizing NLP is finished and running. You should be very proud of that!
We also recapped the main points and takeaways. So, what else can we do?
If we think about it, our application works very well, but only locally, or at least within the same network as the machine that we coded on.
For a web application to be defined as a real web application, it needs to be public. This means it needs to be accessible everywhere.
To be accessed everywhere, our web application needs to live on a server on the real internet with a real public URL.
To put our web application on a real server on the web, we need to deploy it, and this is exactly what we are going to do in the next chapter.