File size: 1,714 Bytes
3b2a8b5
9cf599c
 
eba5a08
 
 
f6c038a
9cf599c
f6c038a
9cf599c
3b2a8b5
 
9cf599c
 
3b2a8b5
f6c038a
3b2a8b5
 
9cf599c
3b2a8b5
eba5a08
 
 
 
 
f6c038a
3b2a8b5
 
f6c038a
eba5a08
9cf599c
f6c038a
 
 
 
3b2a8b5
eba5a08
3b2a8b5
 
eba5a08
 
 
9cf599c
f6c038a
 
 
 
9cf599c
 
 
 
 
3b2a8b5
 
eba5a08
 
9cf599c
3b2a8b5
9cf599c
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
55
56
57
58
59
60
# Optimized Dockerfile for Hugging Face Spaces - Reduced size
FROM python:3.10-slim

# Create non-root user
RUN useradd -m -u 1000 user

# Set working directory and permissions
WORKDIR /app
RUN chown -R user:user /app

# Install system dependencies for OpenCV (minimal)
RUN apt-get update && apt-get install -y --no-install-recommends \
    libgl1 \
    libglib2.0-0 \
    wget \
    ca-certificates \
    && rm -rf /var/lib/apt/lists/* \
    && apt-get clean

# Copy requirements first for better caching
COPY --chown=user:user requirements.txt ./

# Switch to user before installing Python packages
USER user
ENV PATH="/home/user/.local/bin:$PATH"
ENV HOME=/home/user

# Install Python dependencies with optimizations
RUN pip install --no-cache-dir --user -r requirements.txt && \
    pip cache purge

# Download model checkpoint from Google Drive (with retries)
RUN pip install --no-cache-dir --user gdown && \
    gdown --fuzzy --id 1ftzxTJUnlxpQFqPlaUozG_JUbl1Qi5tQ -O /app/model_checkpoint.ckpt && \
    ls -lh /app/model_checkpoint.ckpt && \
    pip uninstall -y gdown && \
    pip cache purge

# Copy application files
COPY --chown=user:user app.py inference_core.py ./
COPY --chown=user:user scripts/ ./scripts/
COPY --chown=user:user configs/ ./configs/

# Create output directories with proper permissions
RUN mkdir -p /app/api_inference_pred_masks_pipeline && \
    mkdir -p /app/api_inference_filtered_pipeline && \
    mkdir -p /app/api_inference_labeled_boxes_pipeline

# Expose port for Hugging Face Spaces
EXPOSE 7860

# Set environment variables
ENV PYTHONUNBUFFERED=1 \
    PORT=7860 \
    PYTHONDONTWRITEBYTECODE=1 \
    MPLCONFIGDIR=/tmp/matplotlib

# Start Flask app
CMD ["python", "app.py"]