e-hossam96's picture
changed classifier model
e17517b
## the base or builder stage commands
# decide on the python version
FROM python:3.12.10-slim-bookworm AS base
# get the build essential tools
RUN apt-get update && apt-get install --no-install-recommends -y \
curl ca-certificates && \
apt-get clean && rm -rf /var/lib/apt/lists/* ~/.cache/
# download the latest version of uv
ADD https://astral.sh/uv/0.7.3/install.sh /install.sh
RUN chmod -R 655 /install.sh && /install.sh && rm /install.sh
# add uv to path
ENV PATH="/root/.local/bin:${PATH}"
# define work directory
WORKDIR /app
# copy the env setup file only
COPY pyproject.toml ./pyproject.toml
RUN uv sync --no-cache-dir --compile-bytecode \
--no-install-project --verbose
# add app env var to path
ENV PATH="/app/.venv/bin:$PATH"
# model export to onnx
RUN optimum-cli export onnx \
--opset 14 --task text-classification \
--framework pt --dtype fp32 --device cpu \
--model mrm8488/bert-tiny-finetuned-sms-spam-detection \
bert-tiny-finetuned-sms-spam-detection-onnx
# model quantization
RUN optimum-cli onnxruntime quantize --avx512_vnni --per_channel \
--onnx_model bert-tiny-finetuned-sms-spam-detection-onnx \
-o bert-tiny-finetuned-sms-spam-detection-onnx-quantized
# ------------------------------------------------------- #
## the main or production stage commands
# same python version as base / builder stage
FROM python:3.12.10-slim-bookworm AS main
# create a non-root user
RUN useradd --create-home app_user
USER app_user
# define work directory
WORKDIR /app
# copy env files from base to main image
COPY --from=base /app/.venv ./.venv
COPY --from=base /app/bert-tiny-finetuned-sms-spam-detection-onnx-quantized \
./bert-tiny-finetuned-sms-spam-detection-onnx-quantized
# add app env var to path
ENV PATH="/app/.venv/bin:$PATH"
# copy project folders and files into image
COPY main.py ./main.py
COPY static ./static
# expose the port
EXPOSE 7860
# start the application
CMD ["uvicorn", "main:app", "--log-level", "info", "--host", "0.0.0.0" , "--port", "7860", "--workers", "1"]