# Use official lightweight Python image FROM python:3.10-slim # Set working directory WORKDIR /app # Install system dependencies (needed for OpenCV + mediapipe + torch) RUN apt-get update && apt-get install -y \ build-essential \ cmake \ libglib2.0-0 \ libsm6 \ libxext6 \ libxrender-dev \ ffmpeg \ git \ && rm -rf /var/lib/apt/lists/* # Copy requirements first (for caching) COPY requirements.txt . # Install Python dependencies RUN pip install --no-cache-dir -r requirements.txt # ------------------------------- # Fix cache + permissions # ------------------------------- RUN mkdir -p /app/cache/matplotlib /app/cache/huggingface/transformers ENV MPLCONFIGDIR=/app/cache/matplotlib ENV HF_HOME=/app/cache/huggingface ENV TRANSFORMERS_CACHE=/app/cache/huggingface/transformers # ------------------------------- # (Optional) Pre-download DistilBERT model + tokenizer # ------------------------------- RUN python -c "from transformers import DistilBertModel, DistilBertTokenizer; \ DistilBertModel.from_pretrained('distilbert-base-uncased', cache_dir='/app/models/distilbert'); \ DistilBertTokenizer.from_pretrained('distilbert-base-uncased', cache_dir='/app/models/distilbert')" # Copy the rest of the code COPY . . # Expose FastAPI port EXPOSE 7860 # Start FastAPI (for Hugging Face Spaces / Docker) CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "7860"]