FROM python:3.10-slim # Install system dependencies for OpenCV RUN apt-get update && apt-get install -y --no-install-recommends \ libglib2.0-0 \ libsm6 \ libxext6 \ libxrender1 \ libgomp1 \ libgl1 \ && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* /var/cache/apt/* WORKDIR /app # Copy and install requirements COPY requirements.txt . RUN pip install --no-cache-dir --upgrade pip setuptools wheel && \ pip install --no-cache-dir --default-timeout=1000 -r requirements.txt # Copy model files (changes less frequently) COPY trainedmodels/ ./trainedmodels/ # Copy application code (changes most frequently) COPY app.py inference.py ./ # Environment optimizations ENV PYTHONUNBUFFERED=1 \ PYTHONDONTWRITEBYTECODE=1 EXPOSE 7860 # Optimized for HuggingFace Spaces CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860", "--log-level", "info", "--timeout-keep-alive", "75"]