-
Notifications
You must be signed in to change notification settings - Fork 1
/
service.py
42 lines (37 loc) · 995 Bytes
/
service.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
from pathlib import Path
from typing import Annotated
import bentoml
import joblib
import numpy as np
import pandas as pd
from bentoml.validators import DataframeSchema
artifacts_path = Path("./artifacts")
@bentoml.service(
resources={"cpu": "1"},
traffic={"timeout": 10},
)
class CarPricePrediction:
def __init__(self) -> None:
self.pipeline = joblib.load(artifacts_path / "car_price_model.pkl")
@bentoml.api
def predict(
self,
input_records: Annotated[
pd.DataFrame,
DataframeSchema(
orient="records",
columns=[
"make",
"model",
"fuel",
"gear",
"offerType",
"mileage_log",
"hp",
"age",
],
),
],
) -> np.ndarray:
result = self.pipeline.predict(input_records)
return result