Skip to main content

Deployment

·366 words·2 mins
Alex Haslam
Author
Alex Haslam
I’m an engineer based in London, with expertise in optimisation, machine learning and simulation.
Table of Contents
Coffee Rating Prediction - This article is part of a series.

Background
#

In a previous post in this series, we trained a model which was able to predict how highly rated a coffee would be on CoffeeReview.com based on the following features:

  • Origin
  • Roaster and roasting style
  • Price
  • Flavour profile

I will use this dataset from Kaggle which contains ratings for ~1900 coffees.

Model deployment
#

To allow us to interact with the model, it was deployed to the cloud within a server as shown below. Separating the model like this allows it to be updated independently from other systems which use it. The individual components will be discussed further below.

graph TD E[User]-.->A A[Streamlit Web App]--Request-->B[AWS Lambda] B--Rating-->A B--Features-->D[Model] D--Prediction-->B subgraph Docker container D end

Docker
#

The chosen model was wrapped within a Docker container which contains all dependencies including Python, as well as the required packages using poetry. The image was built locally and then uploaded to Amazon Container Registry. To update the model, we just need to build a new version of the Docker container.

AWS Lambda
#

An AWS Lambda function was then configured to use this Docker container and call the model. This is a serverless product, which means that:

  • We don’t have to maintain any infrastructure
  • We are only billed when the model is actually used

To allow us to interact with the model, an HTTP endpoint was created using a Lambda URL. In order to secure the endpoint and only allow requests from the dashboard, it was authenticated using IAM. When a HTTP request containing the features is received, the data is passed to the model which generates predictions, and the rating is returned in the response.

Interactive dashboard
#

In order to be able to interact the model and predict ratings for arbitrary coffees, I created a Streamlit dashboard which you can access here. The user enters the meta data about the coffee, and the dashboard then generates a dict of the required features.

The dashboard then makes an HTTP request to the server with this dict in the message body, and receives the rating in the response. The predicted rating is then displayed in the dashboard. Have a play and see how your favourite coffee fares!

Streamlit app

Coffee Rating Prediction - This article is part of a series.