Skip to content

chuck1z/deploy-model

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Deploy Model

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.

  1. The starting-point branch covers all the basic FastAPI stuffs, how a Rest API code look like using python as its programming language
  2. The FastAPI-using-own-model branch can be used as an example on model "deployment" using FastAPI
  3. 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
  4. The TF-Serving and TF-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

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

Basic REST API using FastAPI

1. Index

Endpoint: GET /
Returns all items data as a dictionary.

2. Query item by id

Endpoint: GET /items/{item_id}
Parameters:

  • item_id: integer representing the id of the item to be queried.
Returns the item corresponding to the provided item_id parameter.
If no item corresponds to the provided item_id, raises a 404 Not Found error.

3. Query item by parameters

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.
Returns the items that match the provided query parameters.
If no item matches the query parameters, returns an empty selection.
If no query parameters are provided, returns all items.

4. Add new item

Endpoint: POST /
Parameters:

  • item: JSON data representing an item to be added.
Adds the provided item to the items data.
If the item ID already exists in the data, raises a 400 Bad Request error.

5. Update item

Endpoint: PUT /update/{item_id}
Path parameter:

  • item_id: integer representing the id of the item to be updated.
Query parameters (all optional):

  • 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.
Updates the attributes of the item with the provided item_id.
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.

6. Delete item

Endpoint: DELETE /delete/{item_id} Parameters:

  • item_id: integer representing the id of the item to be deleted.
Deletes the item with the provided item_id from the data.
If the item with the provided item_id does not exist in the data, raises a 404 Not Found error.

About

Tensorflow Model Deployment

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published