Machine Learning Model Deployment Using Streamlit

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
[Music] hi and welcome back to the continuation of the practical machine learning you know for beginners where we take it from moderate building to deployment in the last video i showed you how to deploy a machine learning model using the flask framework by creating an api in this video we're going to do similar thing but we'll be using the stream lit right so i i'm already in my project folder and in case you've not and in case this is the first video you are consuming you should go back to the playlist and see when we started from ideas up to the point of ingesting data and building the model i have my project folder which is here i have the data i have the you know pico file as well and here i'm in visual studio code i have opened up the project folder i'm going to create a new file this is the last one we did using flask api but i'm going to create another one now which will be by clicking on this button here answer streamlit streamleads api dot py making it a python note file click enter i have this open file again what is streamlit and you know why we're using it so first i have the documentation of stream list written up here i'm also going to add it to the video description section where you can you know understand what it does you know how to get started how can you do your api reference and upgrade it but because this video is not really about that it's just for you to see what is possible with this and you can take it up to learn more about it all right first thing we're going to do is just to import the necessary library we want to deploy so i'm one of the first the first library i'm going to employ um import is pico so i'm going to import pico so people will use it on pico the model we have built so that's what we're going to use pico for all right the other library is streamlit i'm going to import streamlit as st you need to have install streamly before you can import it and to do that you can go to your cmd or anaconda thing and just you know peep install streamlit you'll be able to do that yeah if you do peep install streamlit install stream leads you'll be able to you know run this and start i have installed it already so after going through this process all requirement has been certified that is why you know i i have it on my system okay so back here i'm gonna i'm importing it the next thing here is to load my model i want to load my model so i'll call a variable called model because this is where i'm on picking the you know pico file so if you're going to use pico as well pico dot load open bracket then i'm gonna open and open under bracket here i'm gonna put the directory of my v or my my model where's that guy so if i come back here this is the guy random forest model but if i click here i can copy the directory now i've been able to copy director i can come back to this code you can also set it to take it from default direct i just want to use this to show us then i'm going to paste that here you need to make it a forward slash and not backward slash so i'm going to put forward slash here forward slash turn these guys to forward slash okay and of course after this guy i forward slash and what is the name of the model which is a random underscore for rest underscore mode dot pkl of course what mode am i opening it i'm going to open a read mode read binary meaning i want to read the object i'm not writing we have the wb which is the right binary if you are opening it up so that i can hard hardly but i'm not doing that i'm really reading from it or for stream leads we're going to define our main you know uh main method that's the one method that is unique most that's the main method and that's all i'm going to define here um div define main then first thing to do after okay so the first thing to do after this is is choose st st.ty2 it has a lot of you know object or function that i can call within within streamline but this is title and i'm going to just call it car pricing prediction solution so kaplan prediction solution which is what i have here then go to new line then i can i can pass a comment here which is input variable so let's create our variables input variables what we're then writing is okay when i go into that web address just give me first the title which is comprising prediction then after that show me all the variables that i need to input and the model will then run so to define the input variable similar to what we did in the previous video where all the variables we have in our model we need to create them here and collect input because we need them for the prediction i'm going to just do for here then follow i'm just going to fast forward it for other variables yeah i have here equals to i'm going to use st dot we have different type of function but i'm going to use test impute we have no american people i'm going to use type test input you're just taking the value in as text then the variable what issue show is here so this is what we see on the front end but this is also the variable that i'm actually collecting that i need in my model so let's fast forward it to other variables right now i am done declaring the variables as you can see these are all the inputs that i need in my model the next thing here is i'm going to put a comment a prediction so this is the code i'm going to use to run my prediction and is to add a button so we're going to have a button now i'm going to put a condition if st remember that's extremely dot button so this will type in the button and we type what we want the button what the text should be on the button let it be pd so this is the button they will press press 3d button and what happens to the condition to if condition then let's create a variable make prediction so make prediction is where we're going to start the entire prediction and then going to column my model here model dot predict i'm going to present all my variables in a list and that's what i have this array here i'm going to put that again so it's two arrays so that i can eliminate this then i will type all the variables they are all here year present value and the rest so i can start typing here put a comma and i will continue like that today i'll exhaust everything so let me fast forward it okay so i'm done with that the next thing is to say okay the output of this is going to be in several decimal places so i want to convert it so i'm going to say output because you run my output just what we did in the previous video try to check it out whatever you have in my prediction you know um the value is actually in this array so zero then put it to the index just to pick the first value that is predicting and then whatsoever you pick it up then round it off to the nearest two decimal places and lastly yeah we're going to have the sd success button so if that thing is successful what should happen then if you you know output something which is this you can say you can sell your car for what you have here you can sell your car for i'm going to put this curly bracket here open a close calling bracket and that is going to take a variable whatsoever value i put there if you take it and put dots format so i'm using a format here and i'm going to open a bracket where i'm going to put output so it will take whatever value that is coming from this output it's going to put it here and this allows us to format it right just to finalize on this we're going to go back here to the beginning all right if the normal way we did the other time if name is equals to main if name is javier is equals to main what should happen you should run the menu all right so with what we have now okay the equal sign should be double cosine equals equals all right so i can save this and i mean it's really less than 30 lines of code and this will do for us okay so for you to run this uh unlike in you will kill this termina unlike in part in um in flask you just have to put uh just i'll click on this button and it will run so when when i click on this button to run in terminal let's see what happens here for it to run it will not run so for you to run it you come to this terminal and say streamlit round what is the name of the file that i want to run which is my stream leads api dot py this is when it can run now it's taking some seconds but right now you see if we put a url then load in my browser automatically open up my browser then load come and see the magic all right i should see something uh okay i don't know why so let's go back to this code something okay this if condition should actually be outside of that it should be outside okay so let me save it also save every time now that i make these changes now if i come back here we see that something has happened i'm going to run okay fantastic you see by these simple lines of code just less than this we already have an interface where you can interact with so let's provide values i was the year of the car let's say the car is too tight and then i can click on the predator button and it's running now after you complete the button okay i have error code here x are some features but it's interesting it features uh could this be in my code i have it here we are passing the predict here one two three four five six seven oh okay so there's one missing owner that's the owner so your owner is after kms back review i can see i can re-run just to update the model mostly time is updated i click on preview button now this will work all right you can set your car for and eight point 2808.9 two dollars i didn't put it right there but this is it you see how it works perfectly well by writing just few lines of code there are ways you can always go back to documentation and see how well you can never use streaming this was the simplest implementation of stream lit you can really do much with it okay right thank you and bye for now
Info
Channel: TheOyinbooke
Views: 6,129
Rating: undefined out of 5
Keywords: datascience, data science, machine learning, model deployment using flask, how to, theoyinbooke, data analysis, python programming, data science for beginners, how to deploy machine learning model, flask framework, flask deployment, how to deploy a machine learning model, streamlit, streamlit framework, streamlit deployment, deploy model using streamlit, hot to deploy model using streamlit
Id: DqpIeYdwkzA
Channel Id: undefined
Length: 12min 4sec (724 seconds)
Published: Mon Jan 03 2022
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.