Spaces:
Sleeping
Sleeping
| FROM python:3.10-slim | |
| # Set working directory | |
| WORKDIR /app | |
| # Create a non-root user | |
| RUN useradd -m -u 1000 appuser | |
| # Install system dependencies | |
| RUN apt-get update && apt-get install -y \ | |
| curl \ | |
| gcc \ | |
| python3-dev \ | |
| libpython3-dev \ | |
| && rm -rf /var/lib/apt/lists/* | |
| # Set up cache directory for Hugging Face | |
| ENV HF_HOME=/app/.cache/huggingface | |
| RUN mkdir -p /app/.cache/huggingface && \ | |
| chown -R appuser:appuser /app | |
| # Copy only necessary files | |
| COPY --chown=appuser:appuser requirements.txt ./ | |
| COPY --chown=appuser:appuser app/ ./app/ | |
| COPY --chown=appuser:appuser README.md ./ | |
| # Switch to non-root user | |
| USER appuser | |
| # Install dependencies | |
| ENV PATH="/home/appuser/.local/bin:${PATH}" | |
| RUN pip install --no-cache-dir --upgrade pip && \ | |
| pip install --no-cache-dir --verbose torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cpu && \ | |
| pip install --no-cache-dir -r requirements.txt && \ | |
| pip install --no-cache-dir uvicorn | |
| # Expose default dev port | |
| EXPOSE 7860 | |
| # Healthcheck | |
| HEALTHCHECK --interval=30s --timeout=5s --start-period=10s --retries=3 \ | |
| CMD curl --fail http://localhost:${PORT:-7860} || exit 1 | |
| # Start app (use HF-provided PORT if set) | |
| CMD uvicorn app.app:app --host 0.0.0.0 --port ${PORT:-7860} | |