# 1. Use an official lightweight Python base image FROM python:3.11-slim # 2. Set the working directory inside the container WORKDIR /app # 3. Install system dependencies # This is required by opencv-python-headless (a dependency of rembg) RUN apt-get update && apt-get install -y \ libgl1 \ && rm -rf /var/lib/apt/lists/* # 4. Copy requirements file first to leverage Docker layer caching COPY requirements.txt . # 5. Install Python dependencies # --no-cache-dir keeps the image size smaller RUN pip install --no-cache-dir --upgrade pip && \ pip install --no-cache-dir -r requirements.txt # 7. Copy your application code into the container COPY main.py . # 8. Expose the port your app runs on # Hugging Face Spaces automatically uses port 7860 EXPOSE 7860 # 9. The command to run your FastAPI server CMD ["python", "-m", "uvicorn", "main:app", "--host", "0.0.0.0", "--port", "7860"]