-
Notifications
You must be signed in to change notification settings - Fork 0
/
predict.py
26 lines (19 loc) · 863 Bytes
/
predict.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
from typing import Optional
from fastapi import FastAPI
from CPT import CPT
import pickle
from pydantic import BaseModel
model_file = './model.pkl'
my_cpt = pickle.load(open(model_file, 'rb'))
app = FastAPI()
class Request(BaseModel):
context: str # Additional information to increase model performance
steps: list # sequence to predict next steps
k: Optional[int] = 10 # keep only the last k items of the sequence
n: Optional[int] = 2 # max number of predictions to return
p: Optional[int] = 1 # do not consider leaves with Count <= p
coef: Optional[float] = 2 # Increased weight for predecessors
@app.post("/")
def read_root(request: Request):
result = my_cpt.predict([request.steps], k=request.k, n=request.n, p=request.p, coef=request.coef)
return {"Result": result}