Step 5: Packaging the model as an API
In the previous section, we learned how to create the code that will be able to extract the number from a given licence plate. But of course we cannot use a notebook directly like this in a production environment.
So now we will learn how to package this code as an API that you can directly query from other applications.
Some explanations first:
-
The code that we wrote in the notebook has been repackaged as a single Python file,
prediction.py
. Basically, it’s just the code that was in all the cells of the notebook that was put together inside a single file. -
To use this code as a function you can call, we just added a function called
predict
that takes a string as an input, the name of the picture, does the recognition, and sends back the result. Open the file directly in JupyterLab, see for yourself, you should recognize our previous code, with this new function added. -
There are other files in the folder that are used to provide functions to launch a web server that will be used to serve our API.
After these explanations, you are ready to open the file 03_LPR_run_application.ipynb
, and follow the instructions directly in the notebook!
You’ll first launch the Server:
Now, to test, open the file 04_LPR_test_application.ipynb
and follow the instructions.
Query the API:
Once you’re finished, you can come back here and head to the next section.
Navigation
- Red Hat OpenShift Data Science Workshop - Licence plate recognition
- Step 1: Starting a Jupyter environment
- Step 2: The Jupyter environment
- Step 3: Notebooks
- Step 4: Licence plate recognition
- Step 5: Packaging the model as an API<– you are here
- Step 6: Packaging our application
- Step 7: Testing the application
- Conclusion