Utilizing predictions from ML 3 – Utilizing Pretrained Models to Create Specialized and Personalized Web Applications

The second and most important point is that the web application we just implemented is quite powerful since it performs several complex tasks, such as image enhancements, diagnosis, and more. Even though it’s complex, when we count the lines of code we wrote down, we will see that from the very beginning to the end, we wrote just about 130 lines of Python, comments included. This is the real power of Python and Streamlit together. In a few lines of code, we implemented a web application that performs several complex tasks, even leveraging AI. On top of that, we have all the typical widgets that are typically included in very professional applications, such as different kinds of text, buttons, progress bars, and more.

As usual, and considering that this time the code is even more complex, here are some screenshots of the complete transcript of the web application we just completed:

Figure 10.12: Part 1 of the Covid-19 Detection Tool web app

First, we imported the libraries and defined the main function. The main function starts by creating a beautiful title and then continues with the presence of a file_uploader widget. After that, there is a menu containing three voices – Image Enhancement, Diagnosis, and Disclaimer and Info:

Figure 10.13: Part 2 of the Covid-19 Detection Tool web app

Then, we mainly dealt with the Image Enhancement feature and completed the Diagnosis part. In this part, we pre-processed the image, prepared it for the ML model, loaded the classification model and a pretrained CNN, executed the prediction, and introduced some nice widgets, such as the progress bar:

Figure 10.14: Part 3 of the Covid-19 Detection Tool web app

Finally, we just suggested simple text for the Disclaimer and Info section and created the About the Author information page.

Summary

This chapter was very important since we learned how to integrate AI into our web applications.

AI is a highly disruptive technology that can completely change the game when managed and leveraged properly in our applications. In this chapter, we learned that it is possible to include AI models developed and trained separately in Streamlit. Several packages and tools can create AI models, and almost all these models can be included in Streamlit; it’s only a matter of checking the proper documentation and following the rules.

Loading AI models into our web applications is only one part of the process since each model needs to be fed information in a specific format. For this reason, all the data we provide as input to the model that we decide to use must be pre-processed so that it’s compliant with that specific format. This is the reason why we spent a good amount of our time manipulating and transforming the image of the X-ray we uploaded in a format that’s compatible with the CNN model we used. The uploaded image was converted into black and white, then resized and reshaped.

Having the input in the proper format is extremely important; otherwise, the model will not understand what to do and will generate a runtime error. After pre-processing the image, we focused on the prediction; we learned how to perform predictions and interpret them. Finally, we covered the frontend part and took care of visualizing the predictions in the web browser using beautiful effects such as the progress bar. We observed that when dealing with sensitive topics such as health, it’s good practice to include a disclaimer to avoid potential issues.

Having a working application is a very good starting point but it is not the real conclusion of our job. As we already did with the natural language processing web application, we still have to deploy our new tool to the cloud because only with deployment is it possible to build a well-done and well-performing application available to a very wide customer base. This is exactly what we are going to do in the next chapter.

Related Posts

Leave a Reply

Your email address will not be published. Required fields are marked *