FROM python:3.10-slim # Set working directory WORKDIR /app # Install system dependencies RUN apt-get update && apt-get install -y \ git \ curl \ && rm -rf /var/lib/apt/lists/* # Copy requirements first for better Docker layer caching COPY requirements.txt . # Install Python dependencies RUN pip install --no-cache-dir --upgrade pip && \ pip install --no-cache-dir -r requirements.txt # Copy app source code COPY app.py . # Expose port 7860 (required by HF Spaces) EXPOSE 7860 # Set environment variables ENV PORT=7860 ENV HOST=0.0.0.0 ENV PYTHONUNBUFFERED=1 # HuggingFace cache dir (Spaces uses /data for persistent storage, fallback to /tmp) ENV HF_HOME=/tmp/hf_cache ENV TRANSFORMERS_CACHE=/tmp/hf_cache # Run the FastAPI app with uvicorn CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]