I trained an XGBoost model(version 1.5.0) for regression problem.
Then I successfully built a docker and I tried to run it but nothing happens:
Deployment docker run --rm -p 80:80 gehalt-bench:no-batch
INFO: Started server process [1]
INFO: Waiting for application startup
So after “Waiting for application startup” nothing happens.
Here is my code for server file:
import pickle
import numpy as np
from fastapi import FastAPI
from pydantic import BaseModel
app = FastAPI(title="Salary")
class Salary(BaseModel):
attr1: float
attr2: int
attr3: int
attr4: int
attr5: int
attr6: int
attr7: int
attr8: int
#function run at the startup of the server
@app.on_event('startup')
def load_model():
with open('/app/model.pkl','rb') as file:
global model
model = pickle.load(file)
@app.post('/predict')
def predict(sal:Salary):
data_point = np.array(
[
[
sal.attr1,
sal.attr2,
sal.attr3,
sal.attr4,
sal.attr5,
sal.attr6,
sal.attr7,
sal.attr8
]
]
)
pred = model.predict(data_point).tolist()
pred = pred[0]
print(pred)
return {'Prediction':pred}
my requirements.txt file:
fastapi
uvicorn
scikit-learn==0.24.1
xgboost==1.5.0
Docker File:
FROM frolvlad/alpine-miniconda3:python3.7
COPY requirements.txt .
RUN pip install -r requirements.txt && \
rm requirements.txt
EXPOSE 80
COPY ./app /app
CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "80"]
How can I fix a problem? It might be, that version of xgboost might be a problem…
WIth other sklearn models everything works fine.