Cropiee / Dockerfile
Novadotgg
Fix: Bake transformers models into Docker image to avoid start-up curl/DNS issues
614eab9
# Use the official Python 3.9 image
FROM python:3.9-slim
# Install system dependencies required for building native extensions (like spacy/blis)
RUN apt-get update && apt-get install -y --no-install-recommends \
build-essential \
gcc \
g++ \
&& rm -rf /var/lib/apt/lists/*
# Create a working directory
WORKDIR /app
# Copy the requirements file into the container
COPY requirements.txt .
# Install the Python dependencies (using pip upgrade for speed)
RUN pip install --no-cache-dir spacy==3.8.11 --only-binary=:all: || true && \
pip install --no-cache-dir -r requirements.txt
# Install waitress, a production-grade WSGI server
RUN pip install waitress
# Bake NLP models into the image during BUILD to avoid STARTUP download errors
RUN python -m spacy download en_core_web_sm
RUN python -c "from transformers import pipeline; pipeline('text-classification', model='distilbert-base-uncased'); pipeline('sentiment-analysis'); pipeline('text-generation', model='gpt2')"
# Copy the rest of the project files into the container
COPY . /app
# Change the working directory to where app.py is located
WORKDIR /app/executable_code
# Expose port 7860, which is the default port used by Hugging Face Spaces
EXPOSE 7860
# Run the application using waitress
CMD ["waitress-serve", "--port=7860", "app:app"]