Sign inSign up

putuwaw/mammates-model-serving

By putuwaw

Updated almost 3 years ago

Serving Services for All ML Model

Image
0

2.1K

putuwaw/mammates-model-serving repository overview

ml-model-serving

FastAPI Docker LICENSE BUILD Docker Version Docker Pulls

Serving Services for All ML Model using FastAPI and Docker.

ML Model 🤖

Here is the list of ML Model that we use in this project:

Features 💡

Using ML Model Serving, you can:

  • Get prediction from our ML model for predicting food category, rating, and price.
  • Get food recommendation from our ML model by given user_id.
  • Get status and metadata from our ML model.

Prerequisites 📋

Usage ✨

Actually, if you already have Docker and Docker Compose, you just need the compose.yml file.

  • You can run this app with Docker Compose.
docker compose up

Development 💻

If you want to develop the model serving, you can follow this step:

  • Clone the repository:
git clone https://github.com/MamMates/ml-model-serving.git
  • Create and activate virtual environment:
python -m venv venv
source venv/bin/activate
  • Install dependencies:
pip install -r requirements.txt
  • To develop the FastAPI services, you can modify the compose.yml file, change the image in app services to build:
- image: putuwaw/mammates-model-serving
+ build: .
  • Run the app:
docker compose up --build
pytest

API Endpoints 📡

List of available endpoints:

GET
GET / - Get hello world.
Response
{
  "status": true,
  "code": 200,
  "message": "OK",
  "data": {
    "message": "Hello World"
  }
}
GET /recommendation - Get food recommendation (top 5).
NameParamsRequiredTypeDescription
user_idQueryrequiredintegerThe id of user. Example 14

Response

{
  "status": true,
  "code": 200,
  "message": "OK",
  "data": {
    "food_id": [13, 14, 12, 2, 18]
  }
}
GET /model/{model_name} - Get status and metadata from model.
NameParamsRequiredTypeDescription
model_namePathrequiredstringThe name of model. Example food_clf

Response

{
  "status": true,
  "code": 200,
  "message": "OK",
  "data": {
    "status": {
      "model_version_status": [
        {
          "version": "1",
          "state": "AVAILABLE",
          "status": {
            "error_code": "OK",
            "error_message": ""
          }
        }
      ]
    },
    "metadata": {
      "model_spec": {
        "name": "food_clf",
        "signature_name": "",
        "version": "1"
      },
      "metadata": {
        "signature_def": {
          "signature_def": {
            "serving_default": {
              "inputs": {
                "input_2": {
                  "dtype": "DT_FLOAT",
                  "tensor_shape": {
                    "dim": [
                      {
                        "size": "-1",
                        "name": ""
                      },
                      {
                        "size": "150",
                        "name": ""
                      },
                      {
                        "size": "150",
                        "name": ""
                      },
                      {
                        "size": "3",
                        "name": ""
                      }
                    ],
                    "unknown_rank": false
                  },
                  "name": "serving_default_input_2:0"
                }
              },
              "outputs": {
                "dense": {
                  "dtype": "DT_FLOAT",
                  "tensor_shape": {
                    "dim": [
                      {
                        "size": "-1",
                        "name": ""
                      },
                      {
                        "size": "10",
                        "name": ""
                      }
                    ],
                    "unknown_rank": false
                  },
                  "name": "StatefulPartitionedCall:0"
                }
              },
              "method_name": "tensorflow/serving/predict",
              "defaults": {}
            },
            "__saved_model_init_op": {
              "inputs": {},
              "outputs": {
                "__saved_model_init_op": {
                  "dtype": "DT_INVALID",
                  "tensor_shape": {
                    "dim": [],
                    "unknown_rank": true
                  },
                  "name": "NoOp"
                }
              },
              "method_name": "",
              "defaults": {}
            }
          }
        }
      }
    }
  }
}
POST
POST /predict - Predict category, rating, and price of image.
NameParamsRequiredTypeDescription
provinceQueryrequiredstringThe province of seller. Example Bali
environmentQueryoptionalstringThe environment of seller. Default campus.
nameQueryoptionalstringThe name of food. Default null. Example donat ubi mawar
imageBodyrequiredfileThe image to predict

Response

{
  "status": true,
  "code": 200,
  "message": "OK",
  "data": {
    "category": 2,
    "rating": 3,
    "price": 10000
  }
}

License 📝

This project is licensed under the MIT License. See the LICENSE file for details.

Tag summary

Content type

Image

Digest

sha256:5b123b6b8

Size

847.5 MB

Last updated

almost 3 years ago

docker pull putuwaw/mammates-model-serving