FROM python:3.10-slim # Install system dependencies RUN apt-get update && apt-get install -y --no-install-recommends \ git gcc g++ libglib2.0-0 libsm6 libxext6 libxrender-dev \ build-essential curl && \ rm -rf /var/lib/apt/lists/* # Create user RUN useradd -m -u 1000 user USER user ENV PATH="/home/user/.local/bin:$PATH" WORKDIR /app # Copy requirements first for better caching COPY --chown=user requirements.txt ./ # Install dependencies with proper NumPy version RUN pip install --upgrade pip && \ pip install --no-cache-dir packaging ninja wheel setuptools # Force install NumPy 1.x first to avoid compatibility issues RUN pip install --no-cache-dir --force-reinstall "numpy<2.0" # Install PyTorch CPU version (compatible with NumPy 1.x) RUN pip install --no-cache-dir torch==2.2.2+cpu torchvision==0.17.2+cpu torchaudio==2.2.2+cpu \ --index-url https://download.pytorch.org/whl/cpu # Install transformers and related packages RUN pip install --no-cache-dir \ "transformers>=4.37.0" \ datasets \ Pillow \ accelerate \ scipy # Install FastAPI and related packages RUN pip install --no-cache-dir \ fastapi \ "uvicorn[standard]" \ python-multipart # Install other dependencies (skip problematic ones) RUN pip install --no-cache-dir \ opencv-python-headless # Try to install qwen-vl-utils (if it fails, continue) RUN pip install --no-cache-dir qwen-vl-utils || echo "qwen-vl-utils installation failed, continuing..." # Copy all application files COPY --chown=user . . # Set environment variables for better compatibility ENV TRANSFORMERS_CACHE=/tmp/transformers_cache ENV HF_HOME=/tmp/hf_home ENV PYTHONUNBUFFERED=1 # Expose port EXPOSE 7860 # Health check HEALTHCHECK --interval=30s --timeout=30s --start-period=60s --retries=3 \ CMD curl -f http://localhost:7860/health || exit 1 CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860", "--timeout-keep-alive", "120"]