philipobiorah's picture
Update Dockerfile
dca576e verified
raw
history blame
1.3 kB
# Use an official Python runtime as a parent image
FROM python:3.9-slim
# Set the working directory to /app
WORKDIR /app
# Install system dependencies for machine learning and data processing libraries
RUN apt-get update && apt-get install -y \
build-essential \
libopenblas-dev \
libomp-dev \
&& rm -rf /var/lib/apt/lists/*
# Create writable cache directories within /tmp
RUN mkdir -p /tmp/huggingface_cache /tmp/matplotlib
# Set environment variables for Hugging Face Transformers and Matplotlib
ENV HF_HOME=/tmp/huggingface_cache
ENV MPLCONFIGDIR=/tmp/matplotlib
# Copy requirements.txt first to leverage Docker caching
COPY requirements.txt /app/requirements.txt
# Install Python dependencies
RUN pip install --no-cache-dir -r requirements.txt
# Install PyTorch separately to ensure compatibility with the correct architecture
RUN pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cpu
# Copy the rest of the application code, including the local model file
COPY . /app
# Ensure that bert_imdb_model.bin exists
RUN if [ ! -f "/app/bert_imdb_model.bin" ]; then echo "Error: Model file not found in container"; exit 1; fi
# Expose port 7860 for Hugging Face Spaces
EXPOSE 7860
# Command to run your Flask app
CMD ["python", "main.py"]