Spaces:
Sleeping
Sleeping
# Start from an NVIDIA CUDA base image with Python 3 | |
FROM nvidia/cuda:11.8.0-cudnn8-runtime-ubuntu22.04 | |
LABEL org.opencontainers.image.source=https://github.com/protectai/llm-guard | |
LABEL org.opencontainers.image.description="LLM Guard API" | |
LABEL org.opencontainers.image.licenses=MIT | |
# Install Python and other necessary packages | |
RUN apt-get update && apt-get install -y \ | |
python3-pip \ | |
python3-dev \ | |
build-essential \ | |
&& apt-get clean && rm -rf /var/lib/apt/lists/* | |
# Alias python3 to python | |
RUN ln -s /usr/bin/python3 /usr/bin/python | |
# Create a non-root user and set user environment variables | |
RUN useradd -m -u 1000 user | |
USER user | |
ENV HOME=/home/user \ | |
PATH=/home/user/.local/bin:$PATH | |
# ensures that the python output is sent straight to terminal (e.g. your container log) | |
# without being first buffered and that you can see the output of your application (e.g. django logs) | |
# in real time. Equivalent to python -u: https://docs.python.org/3/using/cmdline.html#cmdoption-u | |
ENV PYTHONUNBUFFERED 1 | |
# https://docs.python.org/3/using/cmdline.html#envvar-PYTHONDONTWRITEBYTECODE | |
# Prevents Python from writing .pyc files to disk | |
ENV PYTHONDONTWRITEBYTECODE 1 | |
# Set up a working directory | |
WORKDIR $HOME/app | |
# Copy pyproject.toml and other necessary files for installation | |
COPY --chown=user:user pyproject.toml ./ | |
COPY --chown=user:user app ./app | |
# Install the project's dependencies | |
RUN pip3 install --no-cache-dir --upgrade pip && \ | |
pip3 install --no-cache-dir torch==2.0.1 --extra-index-url https://download.pytorch.org/whl/cu118 && \ | |
pip3 install --no-cache-dir ".[gpu]" | |
RUN python -m spacy download en_core_web_sm | |
COPY --chown=user:user ./config/scanners.yml ./config/scanners.yml | |
# Expose the port the app runs on | |
EXPOSE 7860 | |
# Specify the default command | |
CMD ["llm_guard_api", "/home/user/app/config/scanners.yml"] | |