Spaces:
Sleeping
Sleeping
File size: 1,405 Bytes
835854a e071cca 835854a 114b33c e071cca 114b33c e071cca 835854a 4216565 835854a ce9548f 835854a 4216565 ee82723 4216565 ee82723 835854a 4216565 ee82723 835854a 4216565 835854a ee82723 e071cca |
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 47 48 49 50 51 52 53 54 |
FROM python:3.11-slim
# Install system dependencies
RUN apt-get update && apt-get install -y \
git \
ffmpeg \
libgl1 \
libglib2.0-0 \
curl \
&& rm -rf /var/lib/apt/lists/*
# Create non-root user
RUN groupadd -r appuser && useradd -r -g appuser -m appuser
# Set working directory
WORKDIR /app
# Copy requirements and install Python packages
COPY requirements.txt .
RUN pip3 install --no-cache-dir --upgrade pip && \
pip3 install --no-cache-dir -r requirements.txt
# Set Hugging Face cache path for model download
ENV TRANSFORMERS_CACHE=/app/hf-cache
# Pre-download model as root (so the user doesn't need to write later)
RUN python3 -c "\
from transformers import SegformerImageProcessor, AutoModelForSemanticSegmentation; \
SegformerImageProcessor.from_pretrained('mattmdjaga/segformer_b2_clothes'); \
AutoModelForSemanticSegmentation.from_pretrained('mattmdjaga/segformer_b2_clothes')"
# Copy FastAPI app
COPY app.py .
# Fix permissions
RUN mkdir -p /app/logs && \
chown -R appuser:appuser /app
# Set environment variables
ENV HOME=/home/appuser
# Switch to non-root user
USER appuser
# Expose port
EXPOSE 7860
# Health check
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
CMD curl -f http://localhost:7860/health || exit 1
# Run the FastAPI app
CMD ["python3", "-m", "uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]
|