
We then score a record against the model using the predict method. We load the trained model using joblib, e.g., load(‘svc_model.model’).
#Pip how to install curl in docker code
If you tried the previous tutorials, some of this code should look familiar to you. INPUT_ARRAY = ] logging.basicConfig(level=logging.DEBUG)Ĭlf = load( 'svc_model.model' ) def hello_world (): clf = load( 'svc_model.model' ) preds = clf.predict(INPUT_ARRAY) ( " Inputs: " + str(INPUT_ARRAY)) ( " Prediction: " + str(preds)) return str(preds) Replace app.py with the following code: import logging from joblib import load from flask import Flask If you just want to get to the Docker and Kubernetes goodness, skip ahead. If you want to learn a little bit more about Flask, try this out. We aren’t here to build a website, we want to build an API.īelow is an intermediate example of just loading the model in the Flask App. Now, let’s add our model to our Flask App. Shut off your Flask app by typing “CTRL C” in your terminal. It just returns “Hello, World!” but hey, you did it. You can also enter localhost:8080 as well.Ĭongratulations - you have successfully built your first web application. Copy that URL and paste it into your web browser. Do not use it in a production deployment. Then navigate to localhost:8080 in your browser. Now let’s run this file via python app.py. And for this basic example, it is just “Hello, World!” So whomever or whatever visits our homepage gets whatever is returned in our return statement. And in this case, using we are telling Flask what we want to return to a visitor at our base domain (“/”) route. This is just to make sure Flask is installed and working correctly.Ĭreate a file called app.py and paste in the following code: from flask import FlaskĪpp = def hello_world (): return 'Hello, World!' With Flask installed, let’s now create a “hello world” Flask application.
#Pip how to install curl in docker install
We can do this with pip: pip install flask If you’re following along with me that would mean: $ cp. Let’s also copy our existing model svc_model.model into our serve directory. From the serve directory, the command is: $ source. mkdir serve cd serveĪs before, ensure that you’ve activated your virtual code environment. Just as we used scikit-learn to train ML models without needing to know linear algebra, Flask lets us quickly build web applications with some high level methods.įollowing the convention of the previous tutorials, I’ll make a new directory for our serving code. Flask is a web framework, which is a fancy way of saying a library with a bunch of helper tools for building web applications. We’ll begin by creating a basic REST API.


This is intentional -I want you to focus on learning Docker and Kubernetes. The machine learning presented in this blog tutorial is quite basic. In our case, the input (data) will be the record we want to be scored and the output (data) will be the actual prediction. Computers don’t care about pretty colors, they just want to share data. Rather than have text, images, pretty colors, and reactive design, APIs are simply endpoints that accept some sort of input and return some sort of output. APIs are for computers that want to talk with other computers. So if GUIs are for humans talking to computers, what about when computers want to talk to other computers? Bingo. GUIs exist to let humans work with computers. When you use an application on your phone or laptop, you typically interact with some sort of GUI, e.g., a mobile app or website. That would be GUIs or Graphical User Interface. Let’s start with the sibling of the API, something that everyone is familiar with. If that sounds a little confusing, have no fear. API 101ĪPI stands for Application Programming Interface. In order to do that, we will deploy our model as a REST API. Now, we want to return predictions in real time. We created a batch job to get predictions periodically.

In the previous tutorial, we used a saved version of our model to score records. By the way, if you want to go faster, I conclude this post by showing two simple steps to deploy the model as a REST API with Docker and Kubernetes in Dataiku. We’ll build a basic REST API with Python, test it locally with Docker, and deploy our API with Kubernetes. This tutorial provides a basic, step-by-step example of real-time serving a machine learning (ML) model as a REST API with Python, Docker, and Kubernetes.
