How to deploy Model using Docker Container | #modeldeployment #mlops #docker #machinelearning

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello guys so welcome back to my channel and today we'll be talking about how to deploy machine learning model using Docker container so these are the steps which we are going to discuss so starting with model training uh so I'll be training the model uh for Irish data set and then we'll create an API using python flask so once we are done with this to these two steps then we'll start deployment process so here we'll create a Docker file so we'll be talking about like each and every line of the docker file what it means basically and once the docker file is ready then we'll build it to generate the image so the movement image is generated then of course we can create and run the containers using that image but of course to achieve these two steps so basically so the prerequisite is like you need to have a Docker desktop running in your local system so if you don't have Docker desktop then make sure you download the docker desktop from the official website and install it so it won't create any problem it's just normal software installation okay but still if you face any problem then just let me know using the comment and once this container is up and running then our API will be running inside that container then we can do the testing of that API by sending the request HTTP request so using https request we will be testing that one and then of course we'll be testing again using the kernel request so for different use cases you could have a different scenario so we can test both using both the method okay and then at the end we will also look inside the Container Terminal and see certain things there so let's say start basically so let me open uh Anaconda prompt so for a basic model training so as I said I'm not going to spend much time uh there in model training because uh that is not the scope basically so I assume we all know like uh how to do the model training and all so let me uh go inside and then CD yeah so I have created this folder so let me activate the contact environment also okay so I have explained also how to create the conda environment so you can refer that video if you are new here and then inside that icon open the Jupiter notebook so it will open uh in the browser yeah it is opening here so let me bring back it here okay so now if you see here uh it has opened this uh browser so now here I have kept uh three four uh three things basically one is the data folder and one is like flask API so this I'm going to explain in a moment and then let's start with Iris classifier so here uh basically I'll be using uh this file so this this contains the data of Iris uh flower different flower categories basically there are three categories so ideas like to create a classifier which classify this data into three different categories okay so here I have created certain methods so I'll not go much deeper in here but let's quickly have a look like prepare data so it will read a data from the git repository and just do some uh basic pre-processing not the deeper one and then we'll have a trend test split and so let me run through uh run it as well so let me change the kernel so that we have all dependencies installed there okay so let me quickly run this part and then we have train basic classifiers here I'll be using the logistic regression so normal machine learning uh training word okay so this say you train and then we have certain method to predict basically and then predict probability if you are interested to know the probabilities and then get Matrix okay so let me uh run all the steps in one sort so restart and then all so let me do that thing and then it will run it so the moment it is running so let me show this so inside data we don't have anything so this is just now created and some other other file also will get created as this completes so now if I go here so let me refresh this yeah so now we have model file available we have X test data available Trend it available so these are already utilized for model training okay so now we got the model.pkl file model pickle file okay so now the thing is like how to create the API and deploy this using Docker container okay so I have not spent much time till here because I assume you all are very famous familiar with this machine learning model training part okay so now uh let's open uh vs code quickly and here uh from the file menu we can again open the same folder basically so inside my project folder so I'm opening this inside that I have the python flask API so this folder exist okay so now I opened that folder so here basically um don't get confused so if you are doing along with me so then for you it would be an empty folder so just create so create few folder inside this flask API so don't get confused.vs code so this is the runtime it gets created during runtime so it won't be there for you so just ignore that one and create a static folder so it is empty so basically if you are working with python flask it has some predefined structure it has two folder and one is static another is like templates and then one app.py file this is the bare minimum python flask structure okay so inside static we keep all the CSS or jQuery related JavaScript related files okay for the everything on the client side and then inside templates we have like HTML files more specifically the ginger template okay so don't get confused with these heavy words like ginger just uh think like this is normal HTML and then we have a app.py file okay and I copied this model.pkl which just now created from jupyter notebook okay so now from the top let's create a terminal so here I am creating a terminal basically and then I need to again to have this episode don't uh look into this for a moment I am going to explain every line okay so hold for a second so what you need to basically do basically so to run a flask application a flask API you need to have a flask installed so for that what you can do using python hyphen m v e and B and any environment name so you hit enter so or you can just go to the command from the Power Cell give some time it means we have basically okay so same thing python hyphen m v e and V and give any environment name okay so this is the user defined name and before that everything is syntax okay so the moment you hit enter it will create a new uh environment uh by named EnV name in this directory itself because we are inside this directory okay so you can create a fresh environment but I already have an environment exist two folder back so I'm going to folder back okay and then here I have virtual environment exist foreign exist and then this is how you can activate it okay so now you see our for me virtually normal got activated okay so let me do this thing so that comes everything comes in one line and now uh so in once you have environment created and then this is how you can activate this environment in the Windows machine but if you are using a Linux machine you can simply do source and then Define these things it will get activated okay so no worries now uh you can install certain uh dependencies mainly you need to install python if you install flask and then you need to install a job live then you need to install pandas and then this is the only thing we need as of now okay so if you don't have installed then you install but of course if by running if you see okay any dependencies not installed then you can install like this it will everything will get installed install inside virtual environment folder okay so this is the thing and now let's talk about app.pi so this is the first file we need basically to create the API so here at the very top if you see like uh I'm importing flask so you're using from flask import flask and then request for https request and then render templates will be rendering certain HTML template and will be converting certain data to Json performance so for that purpose we need all these things okay and then using jobly we'll be like saving or loading the model and then pandas for certain uh processing steps and then here I am creating the app name so flask app names using this app is equal to flask and name so you can create a app name in the flask and then here I am defining the very first route okay so here uh the moment you run the I will be showing in a moment like how to on it basically but the moment you run the application the basic landing page the very first page it opens so that is recognized by this slash okay so by this slash it understands okay it has to uh call this home method for the landing page and then here I have index.html defined forget about all these next steps I am coming back so here we have uh we are at rendering index.html now let's see what is the content of index.html okay so inside because see when uh so when this API will be running so this API will be expecting um a CSV file the data file basically on which it has to do the prediction right so how to input that CSV file so that is the Define in the HTML file so here in HTML we need to have a certain uh JavaScript method like Ajax call so for that we need to have a JS defined here so for that I am importing this JS here normal import okay so using script so this is how you can import and then this is a basic HTML form created so here using so I'm just defining the form ID and install so that it is aligned on the center in HTML okay and then I have one input and one button basically okay so what input does basically it will create a browse button so using that browse button you can like import the CSV file on which you want to perform the prediction and then we have a submit button basically on top of submit button I am calling get reader JavaScript method so using that I can call this a further method a predict so I will come here in a moment so now let's see here what is get result defined so here inside get result I have so this is a very simple guys very um easy thing so don't get confused so from there the moment you hit submit button it will call this get result and then here I'm just reading the form data so form data is nothing but I will be uploading the CSV file and then we have a simple Ajax call so Ajax call basically it will take this form data and it will hit the this route this predict route because I have defined here predict slash predict so whatever you define here so it will just call the same method in app.py file okay and this is because we are posting it so we have defined the type as a post okay and this is the form data basically and and content time and no need to specify anything basically and cases of all so that second time you run so it takes the firstly okay and that's it and whatever you would return from this method basically so I'm coming in a moment what is this basically so but let me explain so what you are returning here whatever you will return so it will be accepted it will come here as a data so whatever you define here and then you can simply print in so inside this ID so in dollar ad so this is HTML part Rd ID so here I've defined One D basically so whatever result I want to show so I will be showing here okay so this is one thing basically guys but using curl request it will simply show you the output in the command line so whatever this DF is it will be printed as it is so we'll see both the part now comes to your predict function so in predict function basically what I am defining I am accepting uh CSV file so using request.files I can get whatever file you are posting uh from the browser so in upload file so it will come as a binary so you can just uh pass this file in the pd.red CSV so it will be converted to data frames okay and then if you have if you want to again process this data frame by certain data validation steps then of course you can create those data validation so here because as I said my uh today's session scope is not to explain the complete machine learning life cycle so that's where I'm just not Define anything but suppose you got the data and you want to process it you want to prepare it for a model uh purpose okay then you can define those things here and then return the data frame here okay so again I'm just returning here so I'm just showing the steps okay so now our whether the data is ready to be predicted and now we need to load the model so what you can do with openmodel.pkl so you can Define wherever your model file exists here so I have just kept it here so you just read it like this and then you can load the classifier using job you do upload you can give this file names here in this classifier this model will be loaded now you can simply do the predict classified or predict so whatever machine learning framework basically you are using I am using scikit-learn so that's where here in the classify dot predict will work but if you are using any other machine learning framework then whatever uh predict function exists there you need to use that one okay but steps remain same so now here uh you classify dot predict it will uh you return the prediction result and those will be stored here and that you can so what I am doing basically here so we have a data frame so inside data frame I'm creating a new column so basically if you just for a moment you just see this Excel okay so this is a DF DF contains this whole things okay so not all the records but whatever in the test file okay so this contains this whole thing but here I am adding a new column to your data frame using predicted flower type like here okay so new column will be added here and those predicted classes will be printed here so this is what I am doing in this so basically just adding new column here and then this converting this whole data from to the Json format so that this Json format can be returned here and now this Json data will be written here and this will be printed in the HTML so that will that result will show here basically okay so here you will see the result so this is a whole thing basically whole cycle so now I hope you understood and the next thing is like what to run this application you need to do one more thing at the very end basically so like in see we have a main method to uh start the program okay so just the program is starting point so here also in the flask we have something like this you need to Define like that app.run if you are running in debug mode then you make it debug is equal to true so that every like debug statements will be visible here in the command line and you can Define the port like in which Port it will be running so now you have done with all these steps and then let me quickly run this application so for that to run this python app so what you need to do you need to write Python and then app.py because our logic existing app file and then just let me hit enter so now it will start running uh if everything fine yeah it is running now let me go to this URL and it will be opening here now you see here so this is the content of basic index.html so guys I have not done a very beautiful designing because here that is not the scope to explain you how HTML or css works here very basic thing so I have a like now I can just I can explain you why correlating these things right so now if you go to index.html so here at the very top we have a form here and then in the form we have input type is file right so this is the browse button coming from this line of code and then using this button we have this submit button right the moment I only browse this button and then submit then this will be coming here in the predict function because in that Summit I am calling this predict and here the request dot file this file will be read okay so let me browse it so from browse I can just do X test because this X test I have created from that jupyter notebook right so in that we have prepared data method so now I'm reading x test and with that X test let me sum it and you can see the output in a moment here yeah so here we see the output so here basically as I said here uh in this app.p wise I have converted this data frame to Json basically okay so here it looks like a Json so now here what columns we have say pal and simple with petal and petal with and then predicted flower type so for this we are predicting and this thing because in the X test we don't have a class type because this class we are predicting and then I am just adding this predicted flower type as a class category okay so now here uh these are the indexes basically so this is also not useful and now here we have the data in the Json format so let me just copy here and quickly so in the notepad plus plus so that you can understand this properly and let me Define the language as Json so here it is Json okay and then somewhere I can format it all so so do you know how to format I think from View and from view word wrap right so yeah exactly so now here you see the uh so here if I just enter this thing and then here we have like this data right so this is like this is how every record looks like so for first recorded it is predicting as I reset Osa and all for this also and for this record for example it is predicting as Iris virginica okay so now this uh our application is running locally yes so here it is running locally if you see here if you come here so where is our terminals here here you see 1.127.0.0.1 right it is running locally so now how to create a Docker container for this whole thing okay so now this is the import now the important part coming here so now let me stop so I just did Ctrl C so it is it is stopped running and now uh create a Docker file for this whole thing okay so in vs code we have a very uh nice uh thing existing so if you just do control shift and P okay then it will open this dialog so it so guys I'm repeating it again so if you do control shift and P then it will open this dialog and then for me add Docker file to the work it is showing at the very top because I will I was doing certain experiment with Docker but for you if it is not visible at the top what you can do add Docker the moment you type this then it will come here so add so you need to select add Docker files to the workspace you select this then it will have further options like what kind of Docker file you are creating I mean for what application of course I am creating for flask you just select flask and then what is your app files we have app dot UI if you have certain other name like main.pics you have to select that one okay so app.pi you need to define the application Port so here I am using 5002 so you can Define for that one two and then hit enter and then it is asking whether you want to include the docker compose file as well so see we are just learning so we are in the very beginning phase so so don't go with Docker compost we'll do a step by step okay next lecture where you can talk about Docker compose so just do no so though you don't get confused with any other file gets created okay so now um it is asking uh it already exists so just do all right so now we have a Docker file here so now it got created okay so let me do this thing okay so now let's see uh what it has done basically for us so basically um it is um so the very first line it is doing like uh it is create uh starting with the base image from python 3.10 slim okay so it is so from where this image it will fix it will pick from docker.io so Docker report public repository from where this image will be picked so basically uh inside a country container so what is container logic basically guys right so you might have heard a very famous line okay the application is running in my system and it is not running in other system so that's the very basic idea or basic but important idea why we want to go with containerized application so in container every dependency every requirement is packaged and grouped together and put inside that container and that then container gets running so that whatever it needs to run that application it gets everything packaged inside the container okay so that's where the very first like base image based python image we need but in our application we did 3.9 so I will just write 3.9 you can change anything you want okay and what is an airport so here the second thing that you need to expose the port on which your application will be running inside Docker container so that is the port number okay so it should be same as you give here okay so you define this 5002 if you define some other Port then it will take that one okay it will take this one okay fine so uh this is the this is the second thing and then these things you can ignore at the beginning but let me explain what it is doing basically but if you are very very uh beginner to the docker container you can ignore this part as well okay but what it is doing basically it keeps python from generating dot pyc file in the container because see it has a created Docker ignore file as well if you want to commit this code in the GitHub repository then you don't want to commit uh each and every file generated like some binary files or some dot pyc files for that purpose this is the thing okay and then turn off buffering for easier container login for these two so I'm just removing these two things so that because as as this point of time these are not required okay and then let me copy this thing uh first because first we need to define the working directory so inside container so see inside container also like a file kind of structure exists so you just think there is a folder inside container inside that I'm creating the app folder okay and that and I'm making as a working directory okay inside slash app I'm creating and in that I'm defining as a working directory and then I'm copying whatever so wherever we so right now in my system I am inside this folder so that's what dot represents so whatever inside this folder content that will be copied to this app folder okay that that that's what this is representing and then inside requirement.txt so by default because this Docker file I have created from the vs code thing so that's where it has created the requirement.txt automatically but what you can also do basically guys you can do fifth freeze okay and then rec.txt okay so if you run this then it will also create a requirement.txt and it will have each and every uh package uh available here okay but some package comes as a part of flask but here they have like divided into individual label okay so that's where like you don't get confused with all those things just simply go here and here so just look into the app.py and here what we need we need flask we need jobly we need pandas right so that's where you define those things in the requirement.txt so we don't have joblips adjustments in joblift we don't have Panda adjustments and Panda that's it so this is the only thing we need okay and we don't need this thing so I'll delete this but with that also you can go okay so don't worry okay so now we have this uh requirement.txt area and we have this Docker file so here what I need to do we need to copy this requirement.txt file inside this uh container so that's what we are doing here requirement.txt inside this container file okay and see here I am just copying this inside this dot but what you can also do you can also copy inside this app directory but then you have to Define this dot slash app here okay this is the thing so wherever you keep your file see inside container also there is a folder like structure so wherever you keep your requirement.txt file you need to give that complete path okay so you can just play around these things basically there is no problem so just a minute I have just copied this here okay yeah so now uh so we have uh yeah I was explaining this yeah so I was telling like just you can copy your requirement.txt either inside this app folder or you can copy also inside this so don't worry you can just uh uh experiment by doing both the things it won't make any difference okay so now we have requirement.txt ready so what you need to do basically you have all the requirement defined inside requirement dot text what you need to do so you need to write a python hyphen ampipe install hyphen R requirement.txt so what you can do you can remove this python hyphen name not required you can simply do pip install hyphen R requirement.txt okay so these are the normal process we follow basically but if you write that python hyphen M so that will also work so no need to worry that that's where I say guys so in programming words you learn by experimenting different things and if you get error then you get to know okay what is exactly happening so that's fair so you need to experiment multiples if you have any doubt then just run with that command and then see how it is behaving but okay let me tell you that will also work okay so no need to worry so that is one thing and then here simply it is inside the container it is trying to create a user so at this level we don't need but let me explain you what it is doing basically it is creating not root user with an explicit you user ID and adds permission to if that app folder okay so using add user so this is the command but as I said like we are the beginner here so let me we don't let's no don't go to the like uh very uh Advanced thing so I'm just creating very basic Docker file okay so now here we have a basic image python 3.9 we have a port exposed we have working directory inside that working directory I have copied everything and then I'm copying the requirement.txt also and then running this command so these steps will be executed sequently and then finally we have gunicon there's a pro as in production we want to run using the good Nikon as a web server and then here I'm just exposing this like 0.0.0 IP and then inside 5.2 Port because it's the same port okay and then I've defined the app whatever my app file if you are using main dot UI then need to Define your main okay so our Docker file is ready now the next thing is like we need to run this Docker file to generate the image so further before running make sure you have a Docker desktop running so you need to open Docker desktop so let me open so now my Docker desktop is opening here uh at the beginning you don't you see there is no image inside this image and there is no container running because I have removed everything so that I can show you freshly okay so let me minimize it and so I have copied all the command here so I will just give this file to you as well okay so that you can run so let me do one thing so sometime if you have the capital letter then it gives you problems so let me do this thing so I'm just building that image so here let me run this okay Docker build hypnt ml Docker image you can Define any name basically guys okay and then you can Define the version also if you don't want to define the version then just remove this much part okay and then dot means it will create here and then hit enter so now you guys see here it is it started building so if you just closely follow these steps so it it will uh start this in sequential manner okay so first so let me by the time it is doing so see so uh first it is doing like uh so second like a working directory so that is the second okay of course it will expose that port and it will first download this python3.10 from that Docker IO Docker Hub and then uh okay so it is executing basically and then let me quickly show you okay so see here so we it is copying creating the working directory then as a third step it is copying everything inside that app and then copying requirement.txt into the root folder and then running pip install hyphen are requirement.txt okay and then it is exporting the image and then writing the image here so now here it has registered this image into inside docker.io if you go inside this URL then you will see this file exist okay because I'm not restricted anything and I also removed that user PSN part right so this is publicly available image so you can get in doc.io also okay and then it will also be available in my uh this Docker desktop now you see here ml Docker image version one this is simply just now got created okay now the next thing as I was explaining here see here what we have achieved we have created a doc of course we have done these two things and we have also seen how our application is running so now we I have done a Docker file we have created we have built this Docker file next like creating the dinner running it so how we can do so we have a command for that so no need to worry I'll explain this command as well so here let me keep because we have this image okay so like this and then let me copy this and then here let me paste it here okay so now let me explain you what is happening here so here uh if you see so let me just do this thing okay so that is properly visible so now here Docker run okay so this is the basic command and then what hyphen DP is doing The Hyphen dim is a detached mode so that it won't look like in running mode in your terminal so that your terminal will be free for other work okay that is the mean way detach mode and Pim is defining a port so this eight zero eight one is the external Port which is mapped with the five zero zero two of uh application Port that application running inside the container so the application which is running inside the container that is referring the portal 5002 but here like outside this a the container will expose on API so that will accept HTTP request on this 8081 Port okay so that is the meaning of this and then we have TI and then basic other things I can name some name means it related you can Define the container name here if you are not defining a any container name here then it will create some random named container okay so it will some it will generate some random string and it will create a container with that name and then here after that you can Define the image name whatever image you have created in the previous step so if you have defined the version then of course give it the version if you have not defined the version then don't give it the version and now the moment I am going to hit enter it will um so now before hitting enter let me show you if you go to Docker desktop then here inside the container there is no container running okay so there are two ways to run this container you can come to this image you can just hit this run button then all then also it will start running the container or like by using this command so any way you can do this thing okay so let me hit enter and if everything is right we are lucky then our container will be up okay all the best yeah now let's see so as you see here one more thing so it now our terminal is free for other we can do any other work here okay so that's the advantage of using D here and now let's come to this container and now see it is up and running here okay so now it is running just 12 second ago we have run so now you can open this localhost 8081 port and see if our application is right now very good it is running right so we can close this local one and this is running right so now same thing guys if you are within any uh server then it will take that server URL but Port whatever we have defined so we have deployed locally using Docker container so steps will be same doesn't matter where you are deploying if you are working everything in a server like in office provided system then everything steps will be same okay so no need to worry now let me browse so X test so and then submit and then if everything is fine then you will see the output here okay something receives some problem okay let's see a problem is coming that's good right we can um do something okay so it is telling okay no module named skill and so it is expecting SK learn also right so we need to install that SQL and so we forget to mention that SQL in our requirement.txt file right so we need a scalan as well so let's mention this and let's build this Docker image again okay with version two so let me stop that so guys that's where here if you come to container and if you go here and view detail inside you can see like what is the problem okay because now it is running inside your container so this log will not be visible in your vs code it will be visible here okay so let's see like it is expecting SK land so let me uh and let me see if it is expecting anything else okay yeah so skill and should suffice so I have defined a scale on here and then let me build the image again so this is the image building uh command and here I'm doing in version two so let me stop it here so unnecessary it's not consuming my memory and let me delete also because this is a buggy so we don't need it okay so let's keep that image that's fine so that I can show you okay two images will be created so now let me hit enter and it is creating another image so now it will install that circuit run as well okay so let's wait so here if you visualize so it is downloading and it is doing everything it will take some fraction of seconds so now if you go to here images so you can keep refreshing here and another image in a moment another image I see now version 2 came here right and now this time let me show you like um we can run this content so of course you can run this container from here as well right we have everything same you can just write version two but let me run this container this time from here okay so see how it is uh we having so now here guys from here we are running the container we have not defined any container a name or anything you can Define the container Ram from here okay and you can Define the port here like I'm going to give 8081 okay and host path leave it it will take by default zero zero zero and contain and I'm not defining so that it will take the ah some random container name and let me hit run okay so now if you come here so see in the container see our container is running here okay and if everything is fine so we'll see the output this time so let me take this and see this and let it seems there is some more bug okay no problem we'll resolve that one okay so it is still saying SQL is not available why but we have done that so whether I have not saved or what just a minute thank you okay so uh for this first side let's let's do one thing so what I was telling guys so here is this thing and see so we have requirement.txt so what you can do so whatever uh so as I was telling you so it will basically create everything so rec.txt okay so it will create a rec.txt and here we'll see like all the dependencies so don't go with the shortcut method like we need only these things otherwise it will give error so just do freeze and it will give you all the dependency what all things we need okay so here uh see here we will be having a cycle so we don't need this Pi win because this is not required okay so this we can remove and here we have circuit learn and everything else so okay so that's fine and let me just turn it and then we have a numpy where is numpy it should be there so just a minute yeah so let me do this 21 version otherwise it's a problem okay and then we don't need this requirement Dot txt and in this Docker file we have 3.9 and then here we need rec.txt Dot txt and then click.txt okay so now you will understand also what is happening basically okay so now let me build the image again so Docker build hyphen T so now we are creating version three okay so let me uh delete these images otherwise it takes some time it takes those references and then it creates a problem so to delete delete this first we need to remove this container and then let me delete this image so that it freshly creates the image okay don't take a dependency from the older images okay so now let me uh build uh the I mean this okay so now it is downloading and it will create the image okay so let's wait for a minute okay so now you see like it has created this image with version three so now if you go here so it will be with version three we have got this new image of course I have deleted previous images so that those you don't see okay so now let me just run this container so what is yeah Docker run hyphen DP 8081 and 5002 and then yeah so this is fine so here we have version three image so we need to Define that version and then yeah hit enter then so your new container will be running up and running so let's see what is happening here and I'm hoping this time everything will be fine so yeah exactly so now we got it right so now with this um is running so now you see guys here in locally I'm not running anything our container is up and it is running okay right so now if you are in the server and if you close this system local system then also this API will be keep on running okay so you don't need to worry that one so now this is how you can do give the HTTP request and in the submit it is calling this methods this app.poi so This predict method right and here we have certain logic to predict basically guys okay now next thing is like let's see how to call this uh like uh um I mean how to do this in the curl request so let me open an account prompt so guys I'm just opening a different uh Anaconda prompt so there is no specific reason you can run this current request here also in this terminal also okay but I just want to show in the separate terminal so that you don't get confused like here everything is linked and it cannot be run in anywhere else okay so that's where let's see if curl is here okay fine okay and now let me run this curl command so for that uh okay okay so yeah yeah so now one thing guys here you need to Define like in which path your file exists access dot CSV right so in instead of defining that path we can go directly to that path or we can Define that path as well here okay so basically here what you need to do you need to define the path where your x dot X test dot CSV is so let me get the path and copy that complete path here okay so here you can copy that path so I just copied and yeah so this is uh this is where my CSV file exists this is how you can define basically guys okay this this thing basically and then here uh this is run so my application is running on eight zero eight one port so that you can Define here 8081 okay and now predict so guys here I am calling the predict function directly because that is our that's where our complete logic is there and that accept this CSV file so indirectly this is our API okay this becomes our API and again again I'm telling if you are running in any server so that this Local Host will take automatically that server URL that server domain that's not a problem and this is how you can pass this CSV file okay and using curve so normally okay and now if I hit enter and if you everything is right then it should give us the same Json result yeah so now you see here same Json result we got and then if you see here from data so we have this prediction for every record so like this is one record and this is the one record so every record we have the prediction okay so now our application is running and now if I stop here I can stop here and then if I just hit the same API it will not give very quick result it will say okay this is not running see I failed to connect to localhost Port um this connection refused and if simply I just restart it here okay then then it will work okay so hit enter it will give me the result yeah see so that's a see here now your Apple API is running using Docker container yes so that's the advantage now here like if you want to see like the outputs like we are getting certain errors so these error will be shown here inside the log and then here we have a terminal guys now here if you in terminal you can see which folder you are so by default you are in the app folder okay and then here you can do LS and you can see what all files exactly guys see here we have copied app.py we have copied a model dot pickle file we have copyright.txt and of course it has copyright requirement.txt also before okay but we don't need these things okay so it our dependency will be installed from here because this is rec.txt we have defined as a Docker file and then a static and templates everything is here right and now guys suppose uh in a template so for example you go to templates folder right and we are inside templates yeah just to make sure and if you do LS here index.html is there okay and there is slight change you want to do in the index for example instead of um that uh submit button we want to rename that submit button then of course you need to uh do uh of course you need to install that here I have to get first you need to do a upgrade update basically I have did update okay so it will update the applicant and then using App get you can install app okay get install movie so you can install the Vim editor because we made it by default doesn't exist and now if you have installed then uh yeah so now using web editor so you can do index dot HTML you can do editing so now and now you press I here you can come here and then submit and you can Define me submit me okay for a nice name and then you just to escape and column WQ and Excellence Cube so now it is uh saved okay so now you just come here and you just stop here you need to restart the terminal okay and now if you restart it again and now if you just open here so it should now see here sum it be so that's what I was telling if you need to change a little bit in somewhere in the text or something right so then you can do uh directly inside going inside the terminal basically okay so guys this is all about for today's lecture so what we have covered just to summarize of course we started with basic model training so I'll be sharing the whole thing uh in a folder a gif folder so that you can run everything together we have trained the model we created API using python flask and then we created a Docker file we understood the content of the docker file we built that Docker file and got the image and then we created and then the container right in detached mode and then we we tested uh using https request and we also tested using curl request right and then we've seen like inside the terminal like how you can install any package directly inside that container and for example you remember we were getting error SQL is not available but what we would have also done directly inside the container we could have installed SK land right so that is also one way but again guys I am telling so this is very risky to do perform any operation inside your container because that might break if you're not the expert right so that's where it's not suggestible to do anything changes there come back update your Docker file and then redeploy because it it's just like 10 to 15 minutes job right so that's the advisable so that's it for today's video I hope you liked the video and whatever we explained together you also executed together so that's all for today today's guys so thank you very much and we'll meet you next time so that's all so thank you and please don't forget to subscribe my channel and share in the ml community so that's all for today thank you very much foreign
Info
Channel: Ashutosh Tripathi
Views: 9,275
Rating: undefined out of 5
Keywords: How to deploy model using docker container, Machine Learning Model Deployment using Docker Container, docker container based model deployment, Ashtutosh Tripathi MLOps, MLOps course by Ashutosh Tripathi, MLOps Model Deployment using docker kubernetes, ml model deployment using docker container, machine learning projects with docker, docker for machine learning, docker tutorial, ml docker, machine learning operations, mlops tutorial, mlops course, docker tutorial for beginners
Id: Pn73iKmD3Cw
Channel Id: undefined
Length: 45min 31sec (2731 seconds)
Published: Mon Mar 13 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.