File size: 3,195 Bytes
218b189
18d079d
82c0793
6524e7a
1814d30
8ac32f5
214f9f9
 
 
af4e571
18d079d
 
af4e571
82c0793
 
 
 
 
18d079d
 
82c0793
 
 
18d079d
2100d80
8ac32f5
e4bd7d6
214f9f9
 
 
18d079d
83b4d0c
 
214f9f9
 
 
 
 
82c0793
83b4d0c
930ea76
214f9f9
 
 
 
930ea76
e4bd7d6
00d15ff
214f9f9
e4bd7d6
214f9f9
 
 
00d15ff
214f9f9
2100d80
00d15ff
 
 
 
214f9f9
 
 
 
 
 
 
00d15ff
83b4d0c
214f9f9
00d15ff
214f9f9
 
 
 
 
 
 
 
00d15ff
214f9f9
00d15ff
 
 
 
2100d80
 
 
00d15ff
a9e2eb1
00d15ff
cd4d433
 
00d15ff
a9e2eb1
 
 
 
214f9f9
 
2100d80
214f9f9
 
 
a4167ed
4a1aacb
214f9f9
 
 
 
 
930ea76
25b5a41
83b4d0c
0b9a79d
 
1814d30
 
18d079d
7ebe63e
a9e2eb1
25b5a41
214f9f9
a9e2eb1
83b4d0c
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
FROM ubuntu:20.04

ENV DEBIAN_FRONTEND=noninteractive

# Install system dependencies
RUN apt-get update && apt-get install -y \
    python3.8 \
    python3.8-dev \
    python3.8-distutils \
    git \
    wget \
    curl \
    build-essential \
    libssl-dev \
    libffi-dev \
    libxml2-dev \
    libxslt1-dev \
    zlib1g-dev \
    libsm6 \
    libxext6 \
    libxrender-dev \
    libgl1-mesa-glx \
    libglib2.0-0 \
    libgomp1 \
    ninja-build \
    && rm -rf /var/lib/apt/lists/*

# Set python3.8 as default
RUN update-alternatives --install /usr/bin/python python /usr/bin/python3.8 1 && \
    update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.8 1

# Install pip for Python 3.8 specifically
RUN curl https://bootstrap.pypa.io/pip/3.8/get-pip.py -o get-pip.py && \
    python get-pip.py && \
    rm get-pip.py

# Upgrade pip and install build tools
RUN python -m pip install --upgrade pip==23.0.1 setuptools==59.5.0 wheel cython

# Create user for HF Spaces
RUN useradd -m -u 1000 user
USER user
ENV HOME=/home/user \
    PATH=/home/user/.local/bin:$PATH

WORKDIR /app

# Install PyTorch 1.9 CPU first
RUN pip install --user torch==1.9.0+cpu torchvision==0.10.0+cpu -f https://download.pytorch.org/whl/torch_stable.html

# Install numpy first (required for other packages)
RUN pip install --user numpy==1.21.6

# Install core dependencies in order
RUN pip install --user \
    Pillow==8.3.2 \
    opencv-python==4.5.5.64

# Install scientific computing dependencies
RUN pip install --user \
    scipy==1.7.3 \
    scikit-image==0.19.3 \
    scikit-learn==1.0.2

# Install detectron2 for PyTorch 1.9 CPU
RUN pip install --user detectron2 -f https://dl.fbaipublicfiles.com/detectron2/wheels/cpu/torch1.9/index.html

# Install pycocotools separately to avoid compilation issues
RUN pip install --user pycocotools --no-build-isolation

# Install ML dependencies
RUN pip install --user \
    timm==0.4.12 \
    einops==0.6.1 \
    h5py==3.7.0 \
    shapely==1.8.5 \
    tqdm==4.64.1 \
    imutils==0.5.4

# Install web framework dependencies with compatible versions
RUN pip install --user \
    httpx==0.23.0 \
    httpcore==0.15.0 \
    anyio==3.6.1 \
    starlette==0.19.1 \
    fastapi==0.78.0 \
    uvicorn==0.18.2

# Install Gradio and HuggingFace Hub with compatible versions
# These versions are compatible with each other and the rest of the stack
RUN pip install --user \
    huggingface_hub==0.17.3 \
    gradio==3.50.2

# Try to install NATTEN (optional)
RUN pip install --user natten==0.14.6 -f https://shi-labs.com/natten/wheels/cpu/torch1.9/index.html || \
    echo "NATTEN installation failed - continuing without it"

# Install remaining dependencies
RUN pip install --user \
    PyYAML==5.4.1 \
    matplotlib==3.5.3 \
    regex==2022.10.31 \
    ftfy==6.1.1 \
    wandb \
    diffdist \
    inflect==6.0.4 \
    gdown==4.5.4 \
    wget==3.2

# Copy application files
COPY --chown=user:user . /app

# Set environment variables for CPU-only operation
ENV CUDA_VISIBLE_DEVICES=""
ENV FORCE_CUDA="0"
ENV OMP_NUM_THREADS=4
ENV MKL_NUM_THREADS=4
ENV PYTHONUNBUFFERED=1

# Expose port for Gradio
EXPOSE 7860

# Run the application
CMD ["python", "app.py"]