Turning Python Scripts into Working Web Apps Quickly with Streamlit
I just realized that I am using Streamlit since almost one year now, posted about in Twitter or LinkedIn several times, but never wrote a blog post about it before.
Communication in Data Science and Machine Learning is the key. Being able to showcase work in progress and share results with the business makes the difference. Verbal and non-verbal communication skills are important. Having some tool that could support you in this kind of conversation with a mixed audience that couldn’t have a technical background or would like to hear in terms of results and business value would be of great help. I found that Streamlit fits well this scenario.
Streamlit is an Open Source (Apache License 2.0) Python framework that turns data or ML scripts into shareable web apps in minutes (no kidding). Python only: no front‑end experience required.
To start with Streamlit, just install it through pip (it is available in Anaconda too):
pip install streamlit
and you are ready to execute the working demo application:
accessible to a web browser at the http://localhost:8501 address.
Streamlit is based on these three principles:
- Scripting: building an app has to happen in a few lines of code. Developers can then see it automatically update as they iteratively save the source file. Typically you can implement a full working app writing around 50 lines of Python code.
- Instant deployment: the Streamlit company offers a platform for rapid apps deployment and sharing and to enhance collaboration. It is possible anyway to deploy Streamlit web apps in different platforms such as Heroku or AWS but you have to manage SSO, security, scalability, etc. as required for the specific platform used.
All the major Python visualization libraries are compatible with Streamlit (I have worked mostly with Plotly and Matplotlib, but you can find dozens of examples with others). Same in terms of ML/DL frameworks (my experience so far is with Keras and TensorFlow, but these aren’t the only ones supported). And of course the common libraries to any DS or ML project such as Numpy, Pandas or OpenCV can be used with Streamlit.
With Streamlit you can build really powerful apps: it maintains the promises you can read in the official website. Rather that going through the API, I prefer to share here some Streamlit apps available in my GitHub space, so that you can check yourself what it is possible to do with this framework:
Detection, segmentation and classification of materials inside mostly transparent vessels in images using a CNN:
A demo app for the Google’s MediaPipe hands tracking: https://github.com/virtualramblas/streamlit-mediapipe-hands-tracking
A simple frontend for a pre-trained MobileNet CNN model + OpenCV for face mask detection in images:
What are you waiting for to start evaluating it and join the community?
I will write blog posts on specific Streamlit topics in the future. Stay tuned!
Published on Java Code Geeks with permission by Guglielmo Iozzia, partner at our JCG program. See the original article here: Turning Python Scripts into Working Web Apps Quickly with Streamlit
Opinions expressed by Java Code Geeks contributors are their own.