In Machine Learning, an important step in the processing of data is its graphical representation, so that it can be visualized and its behavior better understood. People in professions such as Data Scientist are regularly called upon to interpret and visualize data for other teams in their company, for example with Streamlit.
In Machine Learning, an important step in the processing of data is its graphical representation, so that it can be visualized and its behavior better understood. People in professions such as Data Scientist are regularly called upon to interpret and visualize data for other teams in their company.
Streamlit: an open source Python library
Streamlit is an open source Python library created in 2018. Open source means that the source code is accessible to all. This implies that it can be reused by all users to create their own software, and thus allows great flexibility for everyone’s needs. Open source, which has become a veritable movement in software development, encourages collaborative production and thus enhances software quality.
Web app creation with Streamlit
Unlike mobile applications, which are installed on software external to the software executing their requests, web apps can be manipulated directly online. The processing of web page instructions is not carried out on two separate pieces of software, but on the same piece of software known as a web browser.
However, it does not replace these applications. Flask and Django, for example, have different specificities for different needs than Streamlit. Unlike Streamlit, Flask enables the creation of back-ends, which are the hidden part of processing requests made by a user on a site. Django, on the other hand, is a far more complex library, enabling both front-end and back-end development. It requires code to be written according to an imposed architecture, which makes it less convenient to use.
Streamlit lets you create an app simply by writing Python code. This makes Streamlit a very practical and accessible tool for anyone with a knowledge of Python who wants to create a web app. It’s a quick and easy tool for integrating data visualization into an application. It’s also easy to integrate Machine Learning models into the interface. Through the application, anyone can then predict and test their models on the data they have with customers or collaborators. Streamlit’s strong point is that there’s no need to worry about the interface, as its use is simplified thanks to its application programming interface (API), which requires few command lines.
Another plus point is that the Streamlit framework can be connected to several software platforms. It is compatible with the majority of dataviz (Matplotlib, Plotly, Seaborn,…) and Machine Learning (Pandas, Pytorch,…) frameworks. This boosts productivity and significantly reduces software development costs.
Installing Streamlit couldn’t be easier. You can do it on the Anaconda console with the ‘pip installer streamlit’ command. Streamlit is installed! To use Streamlit in a Python file, as with any Python package, simply call it up with the import code.
The best way to learn how to use Streamlit is to have a look at the platform documentation.
For a better understanding of how the interface works, here are two examples of commands.
The software displays text (titles, subtitles or even LaTex code for mathematical expressions and formulas) and/or all kinds of elements: dataframes, metrics, graphs, etc.
Various types of interaction objects called widgets: Sliders, Checkboxes… are available.
A good tool for getting started with Streamlit is the Streamlit cheat sheet application, which provides useful code examples.
If you want to go further, the software code is visible to all and can be reused to enhance the application by adding interface functionalities.
When the code undergoes changes on the application, there are two options available to the user in the Python script source code:
- rerun. This refreshes the application.
- always rerun. This allows the application to run continuously when it undergoes modifications to refresh it.
The second option offers faster, easier execution. By choosing this option, you get immediate results from your code. However, as code is constantly being compiled, it’s important to find a solution for costly operations such as downloading data. This is where the st.cache notation comes in handy. It triggers a process to store data in cache memory.
Once the demo project is complete, it can be deployed on the cloud or other deployment system, so that the results can be shared with a wider audience.
Streamlit - Conclusion
In conclusion, Streamlit is undeniably a practical and easy-to-use tool for any Machine Learning engineer or Data Scientist. Aesthetically, the application gives a very satisfying visual.
Streamlit’s main negative point concerns the runtime system. Indeed, this is an application that is re-executed as soon as a new function is added, which can affect model performance.
You can have a look at examples of web applications created with Streamlit at datascientest thanks to the datascientest studio accessible on this link.