Spaces:
Running
Running
File size: 1,444 Bytes
0e92f07 f20e646 d30125c 6df633f 0e92f07 6df633f 0e92f07 6df633f 0e92f07 6df633f f20e646 |
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.11-slim
WORKDIR /app
# Install system dependencies
RUN apt-get update && apt-get install -y \
build-essential \
git \
&& rm -rf /var/lib/apt/lists/*
# Copy and install requirements
COPY requirements.txt .
RUN pip install --no-cache-dir --upgrade pip
RUN pip install --no-cache-dir -r requirements.txt
RUN pip install --no-cache-dir torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cpu
# β
Install accelerate (fixes distilgpt2 loading with device_map)
RUN pip install --no-cache-dir accelerate
# β
Set environment variables to a writable path
ENV HF_HOME=/app/cache
ENV TRANSFORMERS_CACHE=/app/cache
ENV TOKENIZERS_PARALLELISM=false
ENV OMP_NUM_THREADS=1
# β
Create cache directory with proper permissions
RUN mkdir -p /app/cache && chmod -R 777 /app/cache
# Copy application
COPY . .
# β
Pre-download the model during build (optional but recommended)
RUN python -c "from transformers import AutoTokenizer, AutoModelForCausalLM; \
AutoTokenizer.from_pretrained('distilgpt2', cache_dir='/app/cache'); \
AutoModelForCausalLM.from_pretrained('distilgpt2', cache_dir='/app/cache')" || echo "Model download failed, will retry at runtime"
# β
Ensure cache directory is writable after model download
RUN chmod -R 777 /app/cache
# β
Expose correct port
EXPOSE 7860
# β
Run app
CMD ["gunicorn", "--bind", "0.0.0.0:7860", "--workers", "1", "--timeout", "120", "app:app"]
|