'build'
This commit is contained in:
7
.gitignore
vendored
Normal file
7
.gitignore
vendored
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
app.egg-info
|
||||||
|
*.pyc
|
||||||
|
.mypy_cache
|
||||||
|
.coverage
|
||||||
|
htmlcov
|
||||||
|
.cache
|
||||||
|
.venv
|
||||||
14
docker-compose.yml
Normal file
14
docker-compose.yml
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
services:
|
||||||
|
bentoml-serve:
|
||||||
|
build: ./
|
||||||
|
container_name: bentoml_serve
|
||||||
|
ports:
|
||||||
|
- "3000:3000"
|
||||||
|
networks:
|
||||||
|
- traefik-public
|
||||||
|
- default
|
||||||
|
|
||||||
|
networks:
|
||||||
|
traefik-public:
|
||||||
|
# Allow setting it to false for testing
|
||||||
|
external: false
|
||||||
9
dockerfile
Normal file
9
dockerfile
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
FROM python:3.10
|
||||||
|
|
||||||
|
WORKDIR /app/
|
||||||
|
|
||||||
|
COPY ./src /app/
|
||||||
|
|
||||||
|
RUN pip install --no-cache-dir scikit-learn bentoml -i https://mirrors.aliyun.com/pypi/simple/
|
||||||
|
|
||||||
|
CMD ["bentoml", "serve"]
|
||||||
BIN
src/models/logistic_model_0810.pkl
Normal file
BIN
src/models/logistic_model_0810.pkl
Normal file
Binary file not shown.
BIN
src/models/vectorizer_0810.pkl
Normal file
BIN
src/models/vectorizer_0810.pkl
Normal file
Binary file not shown.
33
src/service.py
Normal file
33
src/service.py
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
import bentoml
|
||||||
|
import joblib
|
||||||
|
|
||||||
|
my_image = bentoml.images.Image(python_version="3.10") \
|
||||||
|
.python_packages("scikit-learn", "numpy")
|
||||||
|
|
||||||
|
@bentoml.service(
|
||||||
|
image=my_image
|
||||||
|
)
|
||||||
|
|
||||||
|
class NewsClassifierService:
|
||||||
|
model_logistic_path = "./models/logistic_model_0810.pkl"
|
||||||
|
model_vectorizer_path = "./models/vectorizer_0810.pkl"
|
||||||
|
|
||||||
|
def __init__(self) -> None:
|
||||||
|
self.model_logistic = joblib.load(self.model_logistic_path)
|
||||||
|
self.model_vectorizer = joblib.load(self.model_vectorizer_path)
|
||||||
|
|
||||||
|
@bentoml.api
|
||||||
|
def classify(self,text: str) -> dict:
|
||||||
|
categories = ['Competition News','financial news','Medical news','sports news']
|
||||||
|
token_text =self.model_vectorizer.transform([text])
|
||||||
|
prediction = self.model_logistic.predict(token_text)
|
||||||
|
print(f"Prediction: {prediction}")
|
||||||
|
predict = categories[prediction[0]]
|
||||||
|
|
||||||
|
json_response = {
|
||||||
|
"text": text,
|
||||||
|
"predict": predict
|
||||||
|
}
|
||||||
|
|
||||||
|
return json_response
|
||||||
|
|
||||||
Reference in New Issue
Block a user