Spaces:
Build error
Build error
File size: 1,282 Bytes
19f763f | 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 53 54 55 | # Use Python 3.9 slim image for better performance
FROM python:3.11-slim
# Set environment variables
ENV PYTHONUNBUFFERED=1
ENV PYTHONDONTWRITEBYTECODE=1
ENV HF_HOME=/tmp/huggingface
ENV TRANSFORMERS_CACHE=/tmp/huggingface/transformers
ENV TORCH_HOME=/tmp/torch
# Create a non-root user (required for HF Spaces)
RUN useradd -m -u 1000 user
USER user
ENV HOME=/home/user
ENV PATH=/home/user/.local/bin:$PATH
# Set working directory
WORKDIR $HOME/app
# Install system dependencies (as root)
USER root
RUN apt-get update && apt-get install -y \
build-essential \
curl \
git \
&& rm -rf /var/lib/apt/lists/*
# Switch back to user
USER user
# Copy requirements and install Python dependencies
COPY --chown=user requirements.txt .
RUN pip install --no-cache-dir --upgrade pip
RUN pip install --no-cache-dir --upgrade -r requirements.txt
# Download spaCy model
RUN python -m spacy download en_core_web_sm
# Copy application code
COPY --chown=user . .
# Create cache directories
RUN mkdir -p /tmp/huggingface/transformers
RUN mkdir -p /tmp/torch
# Expose port
EXPOSE 7860
# Health check
HEALTHCHECK --interval=30s --timeout=30s --start-period=5s --retries=3 \
CMD curl -f http://localhost:7860/ || exit 1
# Run the Flask application
CMD ["python", "app.py"]
|