| # Use Python 3.10 for compatibility | |
| FROM python:3.10-slim | |
| # Set working directory | |
| WORKDIR /app | |
| # Install system dependencies | |
| RUN apt-get update && apt-get install -y \ | |
| build-essential \ | |
| libopenblas-dev \ | |
| libomp-dev \ | |
| && rm -rf /var/lib/apt/lists/* | |
| # Create cache directories on /data and matplotlib config dir | |
| RUN mkdir -p \ | |
| /data/.huggingface \ | |
| /data/.cache/huggingface/datasets \ | |
| /data/.cache/huggingface/transformers \ | |
| /tmp/matplotlib \ | |
| && chmod -R 777 /data /tmp/matplotlib | |
| # Clean any old Hugging Face caches (defensive) | |
| RUN rm -rf \ | |
| /root/.cache/huggingface \ | |
| /root/.cache/huggingface_hub \ | |
| /root/.cache/huggingface/datasets || true | |
| # Set cache environment variables to point at /data | |
| ENV HF_HOME=/data/.huggingface | |
| ENV HF_HUB_CACHE=/data/.cache/huggingface/hub | |
| ENV HF_DATASETS_CACHE=/data/.cache/huggingface/datasets | |
| ENV TRANSFORMERS_CACHE=/data/.cache/huggingface/transformers | |
| ENV MPLCONFIGDIR=/tmp/matplotlib | |
| # Copy requirements file | |
| COPY requirements.txt /app/requirements.txt | |
| # Install dependencies | |
| RUN pip install --upgrade pip && pip install --no-cache-dir -r requirements.txt | |
| # Install PyTorch separately for compatibility | |
| RUN pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cpu | |
| # Copy application files | |
| COPY . /app | |
| # Expose Flask app port | |
| EXPOSE 7860 | |
| # Run the application | |
| CMD ["python", "main.py"] | |