Spaces:
Sleeping
Sleeping
File size: 1,128 Bytes
c3aef13 909d9bf 0a6cb95 909d9bf 0a6cb95 c3aef13 0a6cb95 c3aef13 909d9bf |
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 |
FROM python:3.9-slim
# Set environment variables
ENV PYTHONUNBUFFERED=1
ENV TRANSFORMERS_CACHE=/app/cache
ENV HF_HOME=/app/cache
ENV PYTORCH_CUDA_ALLOC_CONF=garbage_collection_threshold:0.6,max_split_size_mb:128
# Optimize for multiple large models
ENV TRANSFORMERS_OFFLINE=0
ENV HF_HUB_ENABLE_HF_TRANSFER=1
ENV TOKENIZERS_PARALLELISM=false
# Reduce memory fragmentation
ENV MALLOC_TRIM_THRESHOLD_=100000
# Install system dependencies for better performance
RUN apt-get update && apt-get install -y \
build-essential \
&& rm -rf /var/lib/apt/lists/*
# Create non-root user
RUN useradd -m -u 1000 user
USER user
ENV HOME=/home/user \
PATH=/home/user/.local/bin:$PATH
# Set working directory
WORKDIR /app
# Copy requirements and install dependencies
COPY --chown=user requirements.txt .
RUN pip install --no-cache-dir --upgrade pip && \
pip install --no-cache-dir -r requirements.txt && \
pip install --no-cache-dir hf_transfer
# Copy application code
COPY --chown=user . .
# Create cache directory
RUN mkdir -p /app/cache
# Expose port
EXPOSE 7860
# Run the application
CMD ["python", "-u", "app.py"] |