File size: 1,563 Bytes
4e8a148
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
FROM python:3.11-slim AS builder

# Install build dependencies
RUN apt-get update && apt-get install -y \
    git cmake clang build-essential wget curl \
    && rm -rf /var/lib/apt/lists/*

# Clone bitnet.cpp
RUN git clone --recursive https://github.com/microsoft/BitNet.git /opt/BitNet

# Install BitNet Python deps (needed for setup_env.py)
RUN pip install --no-cache-dir -r /opt/BitNet/requirements.txt

# Build bitnet.cpp with i2_s kernel support
# setup_env.py does the cmake build and downloads the GGUF model
RUN cd /opt/BitNet && python setup_env.py \
    --hf-repo microsoft/bitnet-b1.58-2B-4T-gguf \
    -q i2_s

# ─── Runtime stage ───────────────────────────────────────────────────────────
FROM python:3.11-slim

RUN apt-get update && apt-get install -y \
    libgomp1 curl \
    && rm -rf /var/lib/apt/lists/*

# Create non-root user (required by HF Spaces)
RUN useradd -ms /bin/bash user
WORKDIR /home/user/app

# Copy built binaries and model from builder
COPY --from=builder /opt/BitNet/build/bin /home/user/app/bin
COPY --from=builder /opt/BitNet/models /home/user/app/models

# Install Python app dependencies
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt

# Copy app files
COPY app.py .
COPY start.sh .
RUN chmod +x start.sh

# Fix permissions
RUN chown -R user:user /home/user/app

USER user

EXPOSE 7860

ENV GRADIO_SERVER_NAME="0.0.0.0"
ENV GRADIO_SERVER_PORT="7860"

CMD ["./start.sh"]