Slackbot
10/08/2022, 10:44 PMChaoyu
10/08/2022, 11:02 PMOluwaseyi Gbadamosi
10/08/2022, 11:06 PMOluwaseyi Gbadamosi
10/08/2022, 11:08 PMJiang
10/09/2022, 4:18 AMsvc
by svc = Service(runners=[...])
?Oluwaseyi Gbadamosi
10/09/2022, 6:56 AMChaoyu
10/09/2022, 7:10 AMbentoml serve
?Chaoyu
10/09/2022, 7:10 AMapp
with something like uvicorn directly?Oluwaseyi Gbadamosi
10/09/2022, 7:11 AMJiang
10/09/2022, 8:18 AMJiang
10/09/2022, 8:19 AMapp
here.Oluwaseyi Gbadamosi
10/09/2022, 8:21 AMJiang
10/09/2022, 8:22 AMJiang
10/09/2022, 8:23 AMThe API here is to mount ASGI App to the BentoML Service, not the other way around.The API here is for mounting an app to a BentoML Service, but it seems that you want to mount bentoml service to a existing FastAPI app.
Jiang
10/09/2022, 8:26 AMJiang
10/09/2022, 8:27 AMOluwaseyi Gbadamosi
10/09/2022, 8:31 AMOluwaseyi Gbadamosi
10/09/2022, 8:33 AM_models_=[demo_model])
svc = bentoml.Service(SERVICE_NAME, _runners_=[model_runner])
app = FastAPI()
svc.mount_asgi_app(app)
@app.get("/metadata")
_def_ metadata():
return {"name": churn_model.tag.name, "version": churn_model.tag.version}
@app.post("/predict/batch/api/v1")
async
_def_ predict_batch(_file_: UploadFile = File(...)):
print(_file_.filename)
# Handle the file only if it is a CSV
if _file_.filename.endswith(".csv"):
# Create a temporary file with the same name as the uploaded
# CSV file to load the data into a pandas Dataframe
with open(_file_.filename, "wb")as f:
f.write(_file_.file.read())
data = pd.read_csv(_file_.filename)
print(data.shape)
os.remove(_file_.filename)
pred = await model_runner.make_prediction.run(data)
# Return a JSON object containing the model predictions
return {
pred
# "Labels": model.predict(data)
}
else:
# Raise a HTTP 400 Exception, indicating Bad Request
# (you can learn more about HTTP response status codes here)
raise HTTPException(_status_code_=400, _detail_="Invalid file format. Only CSV Files accepted.")
Jiang
10/09/2022, 8:33 AMmy_service.py
We could just bentoml serve my_service
The FastAPI app is already included.Oluwaseyi Gbadamosi
10/09/2022, 8:36 AMJiang
10/09/2022, 8:51 AMOluwaseyi Gbadamosi
10/09/2022, 8:52 AM