Responsible-AI-Models / Dockerfile
FROM python:3.9-slim
# Set environment variables to force Hugging Face to use a fresh cache directory
ENV TRANSFORMERS_CACHE=/tmp/transformers_cache
ENV HF_HOME=/tmp/huggingface_cache
# Install dependencies
RUN apt-get update && apt-get install -y git wget
# Create and use a non-root user
RUN useradd -m -u 1000 user
# Create the directory for the repository and give the non-root user access to it
RUN mkdir /Responsible-Ai-Moderation-Models && chown -R user:user /Responsible-Ai-Moderation-Models
USER user
# Update PATH to include the user's local bin directory
ENV PATH="/home/user/.local/bin:$PATH"
# Install Hugging Face dependencies and other packages
RUN pip install --user huggingface_hub transformers git+https://github.com/huggingface/transformers.git
RUN pwd
# Clone the repository
RUN git clone https://huggingface.co/InfosysResponsibleAiToolKit/Responsible-Ai-Moderation-Models /Responsible-Ai-Moderation-Models
RUN git clone https://huggingface.co/spaces/InfosysResponsibleAiToolKit/torch /Responsible-Ai-Moderation-Models/torch
RUN mv /Responsible-Ai-Moderation-Models/torch/torch-2.2.0+cu118-cp39-cp39-linux_x86_64.whl /Responsible-Ai-Moderation-Models/
COPY --chown=user . .
RUN ls -la
COPY --chown=user . /Responsible-Ai-Moderation-Models
WORKDIR /Responsible-Ai-Moderation-Models
RUN ls -la
RUN pip install --no-cache-dir /Responsible-Ai-Moderation-Models/privacy-2.0.8-py3-none-any.whl
RUN pip install --no-cache-dir /Responsible-Ai-Moderation-Models/en_core_web_lg-3.5.0-py3-none-any.whl
RUN pip install torch==2.2.0
RUN pip install transformers==4.41.0
RUN pip install diffusers==0.27.2
RUN echo "git install====" > /dev/null
# RUN pip install torch==2.2.0+cu118 torchaudio==2.2.0+cu118 --extra-index-url https://download.pytorch.org/whl/cu118
# RUN pip install torchvision --extra-index-url https://download.pytorch.org/whl/cu118
# RUN pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu118
# RUN pip install --no-cache-dir /Responsible-Ai-Moderation-Models/torch-2.2.0+cu118-cp39-cp39-linux_x86_64.whl
# RUN pip install --user spacy
# RUN python -m spacy download en_core_web_lg
RUN pip install --upgrade pip
# Install privacy .whl file and other dependencies
# RUN pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu118
# Install additional requirements from requirements.txt
RUN pip install --user --no-cache-dir -r requirements/requirement.txt
RUN pip list
WORKDIR /Responsible-Ai-Moderation-Models/src
# Expose the port used by Hugging Face Spaces (7860)
EXPOSE 7860
# command
CMD ["python", "main.py"]