File size: 1,853 Bytes
401aaf2
 
148396a
 
 
401aaf2
 
 
 
 
 
 
 
 
20e1b5d
 
 
401aaf2
 
2ea70af
 
3e1a5d9
2ea70af
 
 
401aaf2
 
3808a54
 
 
 
 
 
6777e8b
 
3808a54
2f3e9c6
401aaf2
 
 
20e1b5d
 
 
 
401aaf2
7186eb1
20e1b5d
 
401aaf2
7186eb1
 
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
FROM python:3.11-slim

# Ensure build logs flush immediately (helps when HF shows “BUILDING” with no output)
ENV PYTHONUNBUFFERED=1

# System dependencies for OpenCV and image processing
RUN apt-get update && apt-get install -y --no-install-recommends \
    libgl1 \
    libglib2.0-0 \
    libsm6 \
    libxext6 \
    libxrender1 \
    && rm -rf /var/lib/apt/lists/*

# Create non-root user (required by Hugging Face Spaces)
RUN useradd -m -u 1000 appuser

WORKDIR /app

# Build-time info + cache-bust:
# Changing APP_BUILD forces Docker to re-run subsequent layers (including pip install).
ARG APP_BUILD=20
ENV APP_BUILD=${APP_BUILD}
RUN echo "Docker build start: APP_BUILD=${APP_BUILD}" && python -V

# Install Python dependencies
COPY requirements.txt .
RUN pip install --no-cache-dir --disable-pip-version-check --default-timeout=300 -U pip setuptools wheel
RUN pip install --no-cache-dir --disable-pip-version-check --default-timeout=300 --prefer-binary -r requirements.txt -v

# Pre-download the AdaptFormer model so cold starts are instant
ENV HF_HOME=/app/.hf_cache
RUN python -c "from transformers import AutoImageProcessor, AutoModel; \
    AutoImageProcessor.from_pretrained('deepang/adaptformer-LEVIR-CD', cache_dir='/app/.hf_cache', trust_remote_code=True); \
    AutoModel.from_pretrained('deepang/adaptformer-LEVIR-CD', cache_dir='/app/.hf_cache', trust_remote_code=True); \
    print('Model pre-downloaded successfully')"

# Copy application code
COPY . .

# Create data directories with correct permissions
RUN mkdir -p data/overlays && chown -R appuser:appuser /app

USER appuser

# HF Spaces generally uses 7860, but binding to $PORT is safer.
ENV PORT=7860
EXPOSE 7860

# Bind to runtime PORT so health checks always reach the server.
CMD ["sh", "-c", "uvicorn app.main:app --host 0.0.0.0 --port ${PORT:-7860} --log-level info"]