Spaces:
Sleeping
Sleeping
| # ---- Build stage ---- | |
| FROM python:3.11-slim AS builder | |
| WORKDIR /app | |
| # Install dependencies into a virtual environment | |
| COPY requirements.txt . | |
| RUN python -m venv /opt/venv && \ | |
| /opt/venv/bin/pip install --upgrade pip && \ | |
| /opt/venv/bin/pip install --no-cache-dir -r requirements.txt | |
| # ---- Runtime stage ---- | |
| FROM python:3.11-slim | |
| # HF Spaces expects the app to listen on port 7860 | |
| ENV PORT=7860 \ | |
| PYTHONUNBUFFERED=1 \ | |
| PYTHONDONTWRITEBYTECODE=1 \ | |
| PATH="/opt/venv/bin:$PATH" | |
| WORKDIR /app | |
| # Copy virtual env from builder | |
| COPY --from=builder /opt/venv /opt/venv | |
| # Copy application code | |
| COPY . . | |
| # Create non-root user (HF Spaces security requirement) | |
| RUN useradd -m -u 1000 appuser && chown -R appuser:appuser /app | |
| USER appuser | |
| EXPOSE 7860 | |
| # Health check | |
| HEALTHCHECK --interval=30s --timeout=10s --start-period=10s --retries=3 \ | |
| CMD python -c "import urllib.request; urllib.request.urlopen('http://localhost:7860/health')" | |
| CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860", "--workers", "1"] | |