guardrails-final / Dockerfile
zazaman's picture
Replace llama-cpp-python with pre-built llama.cpp binary for Qwen translator
c26a471
raw
history blame
1.48 kB
FROM python:3.10-slim
# Set working directory
WORKDIR /app
# Install system dependencies for PDF processing and other requirements
# Note: llama.cpp binary is downloaded at runtime, no compilation needed
RUN apt-get update && apt-get install -y \
gcc \
g++ \
git \
unzip \
&& rm -rf /var/lib/apt/lists/*
# Create a user to avoid running as root
RUN useradd -m -u 1000 user
USER user
# Set environment variables for Hugging Face cache and performance optimization
ENV HOME=/home/user \
PATH="/home/user/.local/bin:$PATH" \
HF_HOME=/home/user/.cache/huggingface \
TRANSFORMERS_CACHE=/home/user/.cache/huggingface/transformers \
TORCH_HOME=/home/user/.cache/torch
# Set environment variables for performance optimization
ENV TORCH_COMPILE_DISABLE=1 \
TORCHDYNAMO_DISABLE=1 \
TF_ENABLE_ONEDNN_OPTS=0 \
TF_CPP_MIN_LOG_LEVEL=3 \
TOKENIZERS_PARALLELISM=false \
OMP_NUM_THREADS=1
# Create cache directories with proper permissions
RUN mkdir -p /home/user/.cache/huggingface/transformers \
&& mkdir -p /home/user/.cache/torch \
&& mkdir -p /tmp/uploads
# Copy requirements first for better Docker layer caching
COPY --chown=user requirements.txt .
# Install Python dependencies
RUN pip install --no-cache-dir --user -r requirements.txt
# Copy the application code
COPY --chown=user . .
# Expose the port that HF Spaces expects
EXPOSE 7860
# Set the default command to run the Flask app
CMD ["python", "app.py"]