# Use Python 3.10 slim for smaller image but full Python support FROM python:3.10-slim # Set working directory WORKDIR /app # Set environment variables ENV PYTHONDONTWRITEBYTECODE=1 \ PYTHONUNBUFFERED=1 \ PYTHONPATH=/app # Install minimal system dependencies RUN apt-get update && apt-get install -y --no-install-recommends \ libgl1 \ libglib2.0-0 \ libsm6 \ libxext6 \ libxrender-dev \ libgomp1 \ curl \ libffi-dev \ libclang-dev \ libstdc++6 \ libmagic1 \ && rm -rf /var/lib/apt/lists/* # Copy requirements first for better caching COPY requirements.txt . # Upgrade pip and install dependencies RUN pip install --no-cache-dir --upgrade pip setuptools wheel && \ pip install --no-cache-dir -r requirements.txt # Copy application code COPY . . # Create uploads directory RUN mkdir -p uploads # Expose the API port EXPOSE 7860 # Health check HEALTHCHECK --interval=30s --timeout=30s --start-period=5s --retries=3 \ CMD python -c "import requests; requests.get('http://localhost:7860/api/health')" || exit 1 # Run the FastAPI app using uvicorn CMD ["uvicorn", "app_hf:app", "--host", "0.0.0.0", "--port", "7860", "--workers", "1"]