Spaces:
Sleeping
Sleeping
File size: 1,273 Bytes
ec8c511 c27d1a4 ec8c511 c27d1a4 ec8c511 c27d1a4 ec8c511 c27d1a4 ec8c511 c27d1a4 ec8c511 c27d1a4 ec8c511 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 | FROM python:3.11-slim
# Create a non-root user for Hugging Face Spaces (UID 1000)
RUN useradd -m -u 1000 user
USER user
ENV HOME=/home/user \
PATH=/home/user/.local/bin:$PATH \
PYTHONPATH=/home/user/app \
PYTHONDONTWRITEBYTECODE=1 \
PYTHONUNBUFFERED=1
WORKDIR $HOME/app
# Install system dependencies (must be done as root)
USER root
RUN apt-get update && apt-get install -y --no-install-recommends \
build-essential \
curl \
&& rm -rf /var/lib/apt/lists/*
USER user
# Copy requirements first for better caching
COPY --chown=user requirements.txt .
# Install dependencies
RUN pip install --no-cache-dir --upgrade pip && \
pip install --no-cache-dir -r requirements.txt
# Copy application code
COPY --chown=user server/ ./server/
COPY --chown=user inference.py .
COPY --chown=user models.py .
COPY --chown=user client.py .
COPY --chown=user openenv.yaml .
COPY --chown=user README.md .
# Expose port for HF Spaces
EXPOSE 7860
# Health check (matching reference project pattern)
HEALTHCHECK --interval=30s --timeout=30s --start-period=5s --retries=3 \
CMD curl -f http://localhost:7860/health || exit 1
# Default command: run the FastAPI app (for HF Spaces)
CMD ["uvicorn", "server.app:app", "--host", "0.0.0.0", "--port", "7860"]
|