Spaces:
Runtime error
Runtime error
File size: 1,893 Bytes
e13aa67 0fe05d3 7b18e74 44a1a12 e13aa67 33a77e9 e13aa67 2f0747a c551a32 1aafd1c 44a1a12 9338082 e13aa67 9338082 e13aa67 1790f92 e937133 e13aa67 cc0ef8d e13aa67 4ced94a e13aa67 cc0ef8d e13aa67 7b18e74 33a77e9 e13aa67 |
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 |
# Use a slim Python 3.9 base image
FROM python:3.9-slim-buster@sha256:320a7a4250aba4249f458872adecf92eea88dc6abd2d76dc5c0f01cac9b53990
# Set environment variables
ENV PYTHONDONTWRITEBYTECODE=1 \
PYTHONUNBUFFERED=1 \
HF_HOME=/app/cache \
HUGGINGFACE_HUB_DISABLE_XET=1 \
PIP_NO_CACHE_DIR=1
# Set working directory
WORKDIR /app
# Install system dependencies
RUN apt-get update && apt-get install -y --no-install-recommends \
build-essential \
gcc \
g++ \
&& rm -rf /var/lib/apt/lists/*
# Upgrade pip to the latest version
RUN pip install --upgrade pip
# Copy requirements first for better caching
COPY requirements.txt .
# Install dependencies from requirements.txt
RUN pip install --no-cache-dir -r requirements.txt || { echo "Failed to install requirements"; exit 1; }
# Pre-download models
RUN python -c "from sentence_transformers import SentenceTransformer; SentenceTransformer('all-MiniLM-L6-v2', cache_folder='/app/cache')" || { echo "Failed to pre-download SentenceTransformer model"; exit 1; }
RUN python -c "from transformers import AutoModelForCausalLM, AutoTokenizer; AutoModelForCausalLM.from_pretrained('distilgpt2', cache_dir='/app/cache'); AutoTokenizer.from_pretrained('distilgpt2', cache_dir='/app/cache')" || { echo "Failed to pre-download transformer model"; exit 1; }
# Verify cache contents
RUN ls -l /app/cache && \
find /app/cache -type f || { echo "Cache verification failed"; exit 1; }
# Create directories, user, and set permissions
RUN mkdir -p /app/data /app/cache && \
useradd -m myuser && \
chown -R myuser:myuser /app && \
chmod -R u+rw /app/data
# Copy all project files
COPY . .
# Set non-root user
USER myuser
# Expose port for Gunicorn
EXPOSE 8000
# Start Gunicorn with a single worker to reduce memory usage
CMD ["gunicorn", "--bind", "0.0.0.0:8000", "--workers", "1", "--timeout", "120", "app:app"] |