Conf42 Python 2021 - Online

Streamlit: The Fastest Way to build Data Apps

Video size:

Abstract

When we think about building python-based data science apps, we think Flask. But there is a better option now. Streamlit.

Streamlit is a fantastic new tool that lets you create powerful & highly-interactive web apps for your machine learning projects with deceptively simple Python scripts. The best thing about Streamlit is that it doesn’t require any knowledge of web dev. If you know Python, you’re good to go!

In this talk, we’ll go through how to build a very simple Streamlit app step-by-step. I will also review the pros and cons of Streamlit, as regards to other popular Python web frameworks being used by Data Scientists and ML Engineers.

Summary

  • Steven Kolawole will be speaking on Streamlit, the fastest way to build data apps. I'll be explaining the problem being faced by data scientists and machine learning engineers in building web apps. Also, we have in a sneak peek at the different use cases of Streamlit.
  • Streamlit is the app that data scientists have been waiting for. Building apps with Streamlit is as easy as writing Python script. But it might not be the ultimate solution to all data apps problem.
  • The idea behind this is this. I have a younger sister who is starting with data science journey. She gets to see what she's learning and get to know and see how it works. Everything youre seeing up there is implemented with this, I think less than 15 online support. Let's go through the process of getting the data upstream.
  • Streamlit demo lets you perform semantic search across the entire odor city self driving car for the data set. Another demo is an apartment pricing app. Gallery contains apps built by streamlit developers all over the world. Feel free to check out all of this on your own account.
  • Streamlit might not be the ultimate solution to all our web problems, but there, number one is the convenience. There is a cap on the size of data impute and it's 50 megabytes. Also there's limited support for video and animation. You can build an app with functionalities with complex functionalities.
  • Streamlit is simple enough to use for every Python program. It's superb if you want an interactive data very quickly. I could spin up a web app in less than 30 minutes. Also you can buy.

Transcript

This transcript was autogenerated. To make changes, submit a PR.
Hi everyone, I'm Steven Kolawole all the way from Lagos, Nigeria, and I'll be speaking on Streamlit, the fastest way to build data apps. Let's get started. Here's my table of contents. I'll be explaining the problem being faced by data scientists and machine learning engineers in building web apps today. Then we'll move on to Streamlit. I will explain what Streamlit is all about and what it does afterwards. We'll play around with the storage process and we'll check out them. And then we'll move on to building the step by step process of building an interf and then I'll be showing you the building blocks that streamlit makes youre in the building of a data hub. Also, we have in a sneak peek at the different use cases of Streamlit. Finally, I'll be taking us to the console streamlit. Why? Streamlit might not be the ultimate solution to all data apps problem out there all right, so here's my profile. I'm currently a machine learning engineers. I'm currently looking for my next gig. I'm a computer science undergrad at Federal University of Agriculture Abiocuta. I'm a finalist. I mean, I'm in my final year of school and also I consider my skill set to be somewhere in the intersection of software engineering and data science. I'm also a Liverpool citizen since I've been a kid. And yeah, I'm a python freak. I use Python for most of my stuff. I use Python for web development, for data science, for machine learning at home. Yeah, I'm also a foodie. Yeah, I like my food. Okay, so let's get down to business. What's our problem statement? If you've asked to build a data hub or a data driven web app before, this is the issue process, right? The first step is usually the data processing and data analysis, which is done in iPOIMB files, right? And then if you want to share your findings with others, you might want to do that using notebooks, right? Or better still, if you want to reach a wider audience, that you might want to copy all the relevant functions into a Py scripts into a Python script. You can then create an app using flask, right? And then if you're using flux, you need to build a front end part too. And for you to do that you need to use HTML, CSS, JavaScript and JSON. At very least you might want to use a JavaScript framework also, right? But let's say your work is part of an organization process. So it is an organization, then you most likely have a dedicated software engineering team, right? So that means you don't have to build the web app yourself. So you could give the requirements, the specifications to the engineering team. And of course the engineering team will take care of the designing. And of course let's say in a week or two you might have a state of the heart hub and then the team lead for the engineering team might probably tell you able only be able to carry out updates on your hub in let's say two or three months, right? So that leads us to the pain point. Now, depending upon the software engineering team to do this for you is nice, but also take up a bunch of our time, this sort of back and forth and they need to get the specification right. Communication can really be stressed at times and you probably won't want that. And also you won't be able to create new features and updates on a web, right? Because youre need to talk to the software development team. And of course doing that take time and software development team. I also have lot of stuff on this page. Yeah we'd rather create this apps ourselves. But for one, most of us are not particular athletes. If you're like me, I can't recognize a blue color from a yellow color. I suck at UI designs. Of course creating web apps means you'll be spending a huge amount of time and most of us will rather use that amount of time to do something else. Also, if you're using Flask for your app, it also means that youre have to bother with JavaScript, with HTML, with CSS amongst others and of course learning. Those also take a while. And finally, most of us prefer to use our code to generate insights or building model. And then I use our code to provide user with a blizzard experience. And that leads us to the million dollar question, what if we can build apps as easy as writing Python script? That will probably change the world, right? So that leads us to streamlit. What is streamlit? So let's just say that Streamlit is the app that data scientists have been waiting for. Building apps with Streamlit is as easy as writing Python script. Let's say you have a particular Python script here, then you write in your functions, you sprinkle in a few public API call and calls and of course then youre go back to your browser. Of course you'll be able to see your new beautiful web app. Is that easy, right? Yeah, and it covers most UI used in data hub think. But the check the select post you have in a chart you have in a drag button, right? And all this would probably take minutes or hours. You try to implement them on the front end side, but with streamlit they already made functions, not even functions ready made. Readymade. Okay, lets me use methods. They are readymade methods that you could use. You could do them in less than maybe a line or two of code and I think that's quite fun. Also, streamlit supports multiple interaction visualization libraries. Talk of plotty bokeh, Pydec or mathplotly seaborne. Yeah, streamlit supports every one of them. And also your favorite machine learning tools like pandas, psychics, all of them are fully supported by Streamlit. Having said that, let's go through the installation process and maybe play with it then. All right, so for you to install streamlit you need to do app stop pp stuff streamlit. And afterwards you can best on it using Streamlit. Hello. I'm going to try it out. So I already have streamlit installed. So I'll just do streamlit. Hello. So it's coming up and got this up on my browser. You can see the documentation. Feel free to try this out on your phone later and just have fun with it. So I could just to play analyze the demo. I'm going to try this plot and demo. Okay. You can see it's loading up and you can see the nice animation over there. And I can zoom in. I can zoom but so you could try this out. It's quite nice. And the animation is just for 5 seconds, I think. And let's go further. Let's go down. Yeah. So everything youre seeing up there is implemented with this, I think less than 15 online support. I think that's pretty amazing. Feel free to try out all the other DevOps. So let's move on. Now I'm going to walk us through the process of getting the data upstream. Let's assume that we have a file called hello Py file. And of course you have to input streamlit it as ST and then style. Now then you go back to your bash or your command prompt on windows and try streamlit on lo PI. And of course it's going to bring this up in your browser automatically. And I think this is pretty amazing because if you are doing this in flask, you'll be doing it in I think, five or seven lines of code. I feel this task quite wonderful. Yeah. So moving on, let's try that part. All right, so I'm going to open up the other five, but I think it's straightforward. So I'm not going to try it out. I'm going to try out a slightly more complex example. Here we are. Now, this file you're looking at, the idea behind this is this. I have a younger sister who is starting with data science journey. So she was busy with the statistics and probability part, and I felt that it would make much more sense. She gets to see what she's learning. She gets to see it in parties and get to know and see how it works. So that's the idea behind this scripts. So of course, I have to import it as sd, import numpy as mp. I expect most of you to be familiar with that. Numpy is a numerical computational library, Python. All right, so ST title, I think that's self explanatory. We are going to have a pick title distribution test as the words and ST threads means that we might have a line of code with this particular test. Pick a distribution from the list, and we shall draw the line chart from blah, blah, blah. Okay? Yeah. So here's another line of code. We have the keys, which is actually a list and number. We have number and uniform elements in the list. I have this key, which is actually a symbolic method, and it's a select, but you can see a sticker select, but which distribution do you want to plot? And I passed in the key list variable as an argument. Now, if this key is equals to number, right, I'm going to have nums. And nums is going to be a randomly generated number within the range of zero to 1000. To 1000. Of course, if this key is uniform, right, they're going to have a list of range zero to 1000. Then it's going to be a randomly generated number. It says zero to one. Now, the highland line of code is a line chart, right. And we are passing in the nums list or elements as an argument. All right, so I'm going to go over to my browser. I'm going to go over to my terminal and run this. All right, so let's see what comes up. Now, you can see the editor, you can see the line of code. You can see our select boss right. Now it's at number by default. Now, let's say I change this to uniform. Let's see what happens. Okay. You can see the difference between normal and uniform. And it's quite amazing that we're able to come up with this little app in less than six lines of code. I think that's pretty amazing. I know the amount of code I'll probably use on this if I'm on flush, right? Yeah. So let's move on so let's have a look at the different use cases of streamlit. Here's the streamlit demo that lets youre perform the semantic search across the entire odor city self driving car for the data set. And you can run a complete neural net in real time from within the app in less than 300 lines of code. I think that's pretty amazing. Yeah, but we get to see that later. All right, so let's come here. So if you want to try it out, I think it's here. I'm going to open it up. Okay. Yeah, so it's actually build by the streamlit itself. You could check it out on your own. All you have to do to run it is just copy paste this following comments in your browser all right, so I want to show you another demo. This is an apartment pricing app and it was developed by a friend of mine, Moyo. All right, let's check back on this later. I'm going to open up this. This is another use case. This is streamlit gallery. And the gallery contains app built by streamlit developers all over the world. I'm going to open this up. So the outstandwise an app is build for major cities in Lagos. Lagos State is like the financial capital of Nigeria and the data was created from Propertypro ng. And you can select the particular city you want to live in. Lackey is I twelve city in Lagos states. And let's select Lakey. And of course you can choose the type of area you want to live in and you can choose the number of bedroom, number of bathrooms. So I'm picking two for youre number of toilets and device. Do you want to live in an estate? Do you want to live in a Tegus apartment? Do youre prefer a new apartment? All these are choices that you can make so that the apartment is tailored to your preferences. Now, once I press evaluate, so it's going to give me an estimation of all that particular kind of house is going to cost, right? So I have an estimation of 1,050,000. Then it's giving me the range of outfits you can see 5 million for the ones that cost quite much, and then youre could have 1.5 million for those that cost lets. And I think this is actually a nice use case of streamlit. And don't be surprised the amount of code that is needed to do this particular evaluation to build this app in a space Daniel of 100 lines of code. So let's move on. Now, looking at this gallery, you can see apps that have been built by sending developers all over the world you can see New York City, Uber right? Sharing. There are lots youre can see computer vision, images, finance and business, and others buying Tesla predictor. I think this was which I think commodity market price predictor and others. I will include a link in the comment section, so feel free to check out all of this on your own account. And I particularly feel that Student is awesome. Yeah, so let's move on. What are the cons of Streamlit? Why Streamlit might not be the ultimate solution to all our web problems, but there, number one is the convenience. Let's make it fade up. This means that most of those checkboxes, most of the uis are automated, right? You don't have to worry about them. So that means that you can't make custom changes to them. I mean, you can't just decide to place the chart side by side. Actually strength of stream rate, but what you get in terms of time and speed of execution, you have to compensate for it in terms of flexibility. And also there is a cap on the size of data impute and it's 50 megabytes. Yeah, that might be a con for youre too. Also there's limited support for video and animation. Finally, you can build an app with functionalities with complex functionalities. Think of user dedication, newsletter subscription, chatbots, you can do that. If you're thinking of building a web app with functionalities like that, you might want to consider flask or jungle for that. All right, so moving on. Even with all the consoles streamlit, it is simple enough to use for every Python program, which is portable with Python Basic, and it's superb if you want an interactive data very quickly. I've done this, me working on an NLP projects. I just want to see how my model is performing. So far it's easier. I mean, I could spin up a web app in less than 30 minutes and I feel that's actually quite good. And also, if staff flux developer, you need flask, you need JavaScript, HTML, CSS and JSON. At the very least, you might still have to bother with JavaScript frameworks like angular. And I think that's quite a lot, might take a month or maybe years. Master all those, but with Streamlit, all youre ever going to need is just streamlit it. And then if you're thinking of containerization, that you might need docker too. Having said that, thank you for taking your time to listen to my talk and that youre feel free to say. Also you can buy.
...

Steven Kolawole

Data Scientist @ SCITYLANA

Steven Kolawole's LinkedIn account Steven Kolawole's twitter account



Awesome tech events for

Priority access to all content

Video hallway track

Community chat

Exclusive promotions and giveaways