Here is an explanation of some of the steps that you need to perform to complete this project, this will help you understand not only what you need to do, but why you need to do it.
What is virtual environment?
We are activating the virtual environment using the following command:
source venv/bin/activate
A virtual environment is a Python environment such that the Python interpreter, libraries and scripts installed into it are isolated from those installed in other virtual environments, and (by default) any libraries installed in a “system” Python, i.e., one which is installed as part of your operating system.
A virtual environment is a directory tree which contains Python executable files and other files which indicate that it is a virtual environment.
The venv
module provides support for creating lightweight “virtual environments” with their own site directories, optionally isolated from system site directories.
What does the requirements.txt file do?
If you have browsed any python projects on Github or elsewhere, you have probably noticed a file called requirements.txt This requirements.txt file is used for specifying what python packages are required to run the project you are looking at. Typically the requirements.txt file is located in the root directory of your project. If you open the requirements.txt file, you will see the following:
Flask==1.0.2
numpy==1.16.2
#Pillow==2.2.1
scikit-learn==0.20.3
pillow==6.0.0
To run this project, we need to install these packages. We have saved them in the requirements.txt file so that they can be installed in one go using the following command:
pip install -r requirements.txt
What are these packages in the requirements.txt file?
We already know about numpy
and scikit-learn
, let’s get to know the rest of them.
Flask
is a micro web framework written in Python. It is classified as a microframework because it does not require particular tools or libraries. It has no database abstraction layer, form validation, or any other components where pre-existing third-party libraries provide common functions.
pillow
is the friendly PIL fork by Alex Clark and Contributors. PIL is the Python Imaging Library by Fredrik Lundh and Contributors.
What does the curl
command do?
The curl
command transfers data to or from a network server, using one of the supported protocols (HTTP, HTTPS, FTP, FTPS, SCP, SFTP, TFTP, DICT, TELNET, LDAP or FILE). Let’s explain the working of the following line:
curl -F 'file=@test-images/7.png' 127.0.0.1:4041/predict
Here we are executing the curl
command to transfer data, which in this case is the 7.png file, to the server at the address 127.0.0.1:4041/predict so that, you guessed it right, the script train_mnist_model.py can predict the image.
How to create a .py file?
To create a .py file from the Jupyter notebook please use through the following steps:
File -> Download as -> Python (.py)
and then save it wherever you want to.