Spaces:
Sleeping
Sleeping
File size: 1,467 Bytes
d98611c 6d70a1d d98611c | 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 | FROM python:3.9-slim
# Install system dependencies
RUN apt-get update && apt-get install -y --no-install-recommends \
build-essential \
&& rm -rf /var/lib/apt/lists/*
# Create non-root user for Hugging Face Spaces
RUN useradd -m -u 1000 user
USER user
ENV PATH="/home/user/.local/bin:$PATH"
WORKDIR /app
# Copy requirements first for better caching
COPY --chown=user ./requirements.txt requirements.txt
RUN pip install --no-cache-dir --upgrade pip && \
pip install --no-cache-dir -r requirements.txt
# Copy application code and models
COPY --chown=user . /app
# Verify critical files exist (helps debug if files are missing)
RUN ls -la /app/*.py && \
test -f /app/app.py || (echo "ERROR: app.py not found!" && exit 1) && \
test -f /app/preprocessing.py || (echo "ERROR: preprocessing.py not found!" && exit 1) && \
test -f /app/model_utils.py || (echo "ERROR: model_utils.py not found!" && exit 1) && \
echo "All required Python files found!"
# Ensure models directory exists (models should be committed to repo)
RUN mkdir -p /app/models /app/data
# Health check (port 7860 for Hugging Face Spaces)
HEALTHCHECK --interval=30s --timeout=10s --start-period=30s --retries=3 \
CMD python -c "import requests; requests.get('http://localhost:7860/health', timeout=5)" || exit 1
# Expose port 7860 (Hugging Face Spaces default)
EXPOSE 7860
# Run FastAPI application
CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]
|