File size: 1,623 Bytes
c9cfbec a4c15ce c9cfbec b95b23e c9cfbec 2a77b32 3c369e2 539d2b8 3c369e2 2a77b32 3c369e2 539d2b8 b95b23e c9cfbec 2a77b32 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 | FROM python:3.10-slim
WORKDIR /app
# Install system dependencies
RUN apt-get update && apt-get install -y \
build-essential \
curl \
git \
libfaiss-dev \
&& rm -rf /var/lib/apt/lists/*
# Copy requirements file first (as root) for better caching
COPY requirements.txt .
# Install Python dependencies as root
RUN pip install --no-cache-dir --upgrade pip && \
pip install --no-cache-dir -r requirements.txt && \
pip install --no-cache-dir langchain-huggingface
# Create a non-root user
RUN useradd --create-home --shell /bin/bash --uid 1000 appuser
# Set environment variables for HuggingFace models and cache
ENV HF_HOME=/home/appuser/.cache/huggingface
ENV HF_HUB_CACHE=/home/appuser/.cache/huggingface/hub
ENV TRANSFORMERS_CACHE=/home/appuser/.cache/transformers
ENV SENTENCE_TRANSFORMERS_HOME=/home/appuser/.cache/sentence_transformers
# Force Python to run in unbuffered mode for real-time logs in HF Spaces
ENV PYTHONUNBUFFERED=1
# Create cache directories in the user's home directory
RUN mkdir -p /home/appuser/.cache/huggingface/hub \
/home/appuser/.cache/transformers \
/home/appuser/.cache/sentence_transformers \
/app/uploads && \
chown -R appuser:appuser /home/appuser/.cache /app && \
chmod -R 755 /home/appuser/.cache /app
# Copy application code and set ownership
COPY --chown=appuser:appuser . .
# Switch to non-root user
USER appuser
# Expose port 7860
EXPOSE 7860
# Run the application with unbuffered output for Hugging Face Spaces logging
# -u flag ensures Python runs in unbuffered mode (logs appear in real-time)
CMD ["python", "-u", "app.py"] |