Serving with Flask
Serving the PyTorch model in Python itself is the easiest way of serving your model in production. But before going into explaining how it can be done, let's have a quick look at what Flask is. Explaining Flask completely is out of the scope of this chapter, but we'll still go through the most fundamental concepts of Flask.
Introduction to Flask
Flask is a microframework that's been used in production by several big companies in the Python world. Even though Flask comes up with a template engine that can be used to push the UI to the client, we are not using that; instead, we will make a RESTful backend that serves APIs.
Flask can be installed using pip
, just like any other Python package:
pip install Flask
This will install the additional dependencies Werkzeug (the Python interface between the application and the server), Jinga (as the template engine), itsdangerous (for securely signing the data), and Click (as the CLI builder).
Once installed...