Deploying an ML model may sound scary. We don't learn Tensorflow, model training, or even python as a CC participant.
Through this repo, you can see the many ways you can deploy a model.
- The
starting-point
branch covers all the basic FastAPI stuffs, how a Rest API code look like using python as its programming language - The
FastAPI-using-own-model
branch can be used as an example on model "deployment" using FastAPI - The
Express-TFJS
branch is an example of model "deployment" using nodejs. It requires extra work, you have to convert your model to json and its performance is not as good as native python - The
TF-Serving
andTF-Serving-API
branches are used in tandem for TF Serving implementation. TF Serving is only used to host the model and the API can be used as an example of how to redirect request to a TF Serving backend. You can also ask your MD peer to make a direct request instead of making another API
FastAPI is a modern web framework for building RESTful APIs in Python. It was first released in 2018 and has quickly gained popularity among developers due to its ease of use, speed and robustness. FastAPI is based on Pydantic and type hints to validate, serialize, and deserialize data.
Documentation: https://fastapi.tiangolo.com
Source Code: https://github.com/tiangolo/fastapi
To run this file, do
uvicorn main:app
or
uvicorn main:app --reload
to automatically restart the kernel everytime there's a change saved inside main.py
Endpoint: GET /
Returns all items data as a dictionary.
Endpoint: GET /items/{item_id}
Parameters:
- item_id: integer representing the id of the item to be queried.
If no item corresponds to the provided item_id, raises a 404 Not Found error.
Endpoint: GET /items/
Query parameters:
- name: (optional) string representing the name of the item to be queried.
- price: (optional) float representing the price of the item to be queried.
- count: (optional) integer representing the count of the item to be queried.
- category: (optional) string representing the category of the item to be queried.
If no item matches the query parameters, returns an empty selection.
If no query parameters are provided, returns all items.
Endpoint: POST /
Parameters:
- item: JSON data representing an item to be added.
If the item ID already exists in the data, raises a 400 Bad Request error.
Endpoint: PUT /update/{item_id}
Path parameter:
- item_id: integer representing the id of the item to be updated.
- name: string representing the new name of the item.
- price: float representing the new price of the item.
- count: integer representing the new count of the item.
If the item with the provided item_id does not exist in the data, raises a 404 Not Found error.
If no update parameters are provided, raises a 400 Bad Request error.
Endpoint: DELETE /delete/{item_id}
Parameters:
- item_id: integer representing the id of the item to be deleted.
If the item with the provided item_id does not exist in the data, raises a 404 Not Found error.