Slackbot
12/21/2022, 11:43 AMJiang
12/21/2022, 12:28 PMSarthak Verma
12/21/2022, 12:29 PMSarthak Verma
12/21/2022, 12:29 PMJiang
12/21/2022, 12:29 PMSarthak Verma
12/21/2022, 12:29 PMSarthak Verma
12/21/2022, 12:29 PMSarthak Verma
12/21/2022, 12:29 PMservice: "service.py:svc" # Same as the argument passed to bentoml
labels:
owner: Sarthak
stage: development
include:
- "*.py" # A pattern for matching which files to include in the bento
python:
packages: # Additional pip packages required by the service
- scikit-learn
- numpy
- pandas
- pydantic
Sarthak Verma
12/21/2022, 12:29 PMSarthak Verma
12/21/2022, 12:29 PMimport numpy as np
import pandas as pd
from fastapi import FastAPI
from pydantic import BaseModel
import json
import typing
import bentoml
from <http://bentoml.io|bentoml.io> import JSON
from <http://bentoml.io|bentoml.io> import NumpyNdarray
BENTO_MODEL_TAG = "iris_clf:3byq2muajs7tt6e6"
iris_classifier_runner = bentoml.sklearn.get(BENTO_MODEL_TAG).to_runner()
svc = bentoml.Service("iris_classifier_pydantic", runners=[iris_classifier_runner])
class IrisFeatures(BaseModel):
sepal_len:float
sepal_width:float
petal_len:float
petal_width:float
#Optional Field
request_id:typing.Optional[int]
class Config:
extra="forbid"
input_spec=JSON(pydantic_model=IrisFeatures)
@svc.api(input=input_spec,output=NumpyNdarray())
async def classify(input_data:IrisFeatures)->np.ndarray:
if input_data.request_id is not None:
print("Received request Id :" ,input_data.request_id)
input_df=pd.DataFrame([input_data.dict(exclude={"request_id"})])
return await iris_classifier_runner.predict.async_run(input_df)
Sarthak Verma
12/21/2022, 12:30 PMSarthak Verma
12/21/2022, 12:52 PMJiang
12/21/2022, 12:53 PMJiang
12/21/2022, 12:54 PMSarthak Verma
12/21/2022, 12:55 PMJiang
12/21/2022, 1:02 PMbentoml
from my patch branch. (note: this branch is just a temporary fix. It will not persist for long time)
pip install git+<https://github.com/bojiang/bentoml.git@fix-containerize-windows>
Sarthak Verma
12/21/2022, 1:02 PMSarthak Verma
12/21/2022, 1:03 PMSarthak Verma
12/21/2022, 1:03 PMJiang
12/21/2022, 1:04 PMSarthak Verma
12/21/2022, 1:04 PMSarthak Verma
12/21/2022, 1:04 PMSarthak Verma
12/21/2022, 1:09 PMnivas gopi
12/22/2022, 6:55 AMAaron Pham
12/23/2022, 12:55 AMSarthak Verma
12/23/2022, 3:26 AMAaron Pham
12/23/2022, 7:34 PM