Spaces:
Sleeping
Sleeping
Update Dockerfile
Browse files- Dockerfile +39 -10
Dockerfile
CHANGED
|
@@ -1,35 +1,64 @@
|
|
| 1 |
# Use an official Python runtime as a parent image
|
| 2 |
FROM python:3.12-slim
|
| 3 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
# Install system dependencies needed to compile BitNet AND process audio (ffmpeg)
|
| 5 |
-
RUN apt-get update && apt-get install -y \
|
| 6 |
cmake \
|
| 7 |
clang \
|
| 8 |
build-essential \
|
| 9 |
git \
|
| 10 |
ffmpeg \
|
|
|
|
| 11 |
&& rm -rf /var/lib/apt/lists/*
|
| 12 |
|
| 13 |
-
# Set up
|
| 14 |
WORKDIR /app
|
| 15 |
|
| 16 |
-
# Clone
|
| 17 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
|
| 19 |
-
# Install
|
| 20 |
RUN pip install --no-cache-dir -r requirements.txt
|
| 21 |
-
RUN pip install --no-cache-dir gradio huggingface_hub "edge-tts>=7.3.1" gTTS transformers
|
| 22 |
|
| 23 |
-
# Pre-download the model into the
|
| 24 |
RUN python3 -c "from huggingface_hub import hf_hub_download; hf_hub_download(repo_id='microsoft/bitnet-b1.58-2B-4T-gguf', filename='ggml-model-i2_s.gguf', local_dir='models/BitNet-b1.58-2B-4T')"
|
| 25 |
|
| 26 |
-
#
|
| 27 |
-
RUN
|
|
|
|
|
|
|
|
|
|
| 28 |
|
| 29 |
# Copy your local app code into the container
|
| 30 |
COPY app.py .
|
| 31 |
|
| 32 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
EXPOSE 7860
|
| 34 |
|
| 35 |
# Run the Gradio interface
|
|
|
|
| 1 |
# Use an official Python runtime as a parent image
|
| 2 |
FROM python:3.12-slim
|
| 3 |
|
| 4 |
+
# Prevent interactive prompts during installation
|
| 5 |
+
ENV DEBIAN_FRONTEND=noninteractive
|
| 6 |
+
ENV PYTHONUNBUFFERED=1
|
| 7 |
+
ENV CC=clang
|
| 8 |
+
ENV CXX=clang++
|
| 9 |
+
# Hugging Face Spaces port configuration
|
| 10 |
+
ENV GRADIO_SERVER_NAME="0.0.0.0"
|
| 11 |
+
ENV GRADIO_SERVER_PORT=7860
|
| 12 |
+
|
| 13 |
# Install system dependencies needed to compile BitNet AND process audio (ffmpeg)
|
| 14 |
+
RUN apt-get update && apt-get install -y --no-install-recommends \
|
| 15 |
cmake \
|
| 16 |
clang \
|
| 17 |
build-essential \
|
| 18 |
git \
|
| 19 |
ffmpeg \
|
| 20 |
+
curl \
|
| 21 |
&& rm -rf /var/lib/apt/lists/*
|
| 22 |
|
| 23 |
+
# Set up working directory
|
| 24 |
WORKDIR /app
|
| 25 |
|
| 26 |
+
# Clone BitNet with submodules and checkout a known stable commit
|
| 27 |
+
# (Prevents broken upstream kernel commits from breaking the build)
|
| 28 |
+
RUN git clone --recursive https://github.com/microsoft/BitNet.git . && \
|
| 29 |
+
git checkout 0b341e582afbf9e1011f24744b554c96a3477eb5 && \
|
| 30 |
+
git submodule update --init --recursive
|
| 31 |
+
|
| 32 |
+
# Install CPU-optimized PyTorch first (saves ~3GB of disk and download time)
|
| 33 |
+
RUN pip install --no-cache-dir torch torchaudio --index-url https://download.pytorch.org/whl/cpu
|
| 34 |
|
| 35 |
+
# Install BitNet requirements followed by app dependencies
|
| 36 |
RUN pip install --no-cache-dir -r requirements.txt
|
| 37 |
+
RUN pip install --no-cache-dir gradio huggingface_hub "edge-tts>=7.3.1" gTTS transformers openai-whisper
|
| 38 |
|
| 39 |
+
# Pre-download the BitNet quantized model into the build layer
|
| 40 |
RUN python3 -c "from huggingface_hub import hf_hub_download; hf_hub_download(repo_id='microsoft/bitnet-b1.58-2B-4T-gguf', filename='ggml-model-i2_s.gguf', local_dir='models/BitNet-b1.58-2B-4T')"
|
| 41 |
|
| 42 |
+
# Pre-download Whisper model so the Space boots instantly without downloading at runtime
|
| 43 |
+
RUN python3 -c "from transformers import pipeline; pipeline('automatic-speech-recognition', model='openai/whisper-base', device=-1)"
|
| 44 |
+
|
| 45 |
+
# Compile the high-performance BitNet kernels
|
| 46 |
+
RUN python3 setup_env.py -md models/BitNet-b1.58-2B-4T -q i2_s
|
| 47 |
|
| 48 |
# Copy your local app code into the container
|
| 49 |
COPY app.py .
|
| 50 |
|
| 51 |
+
# Create HF Spaces user (UID 1000) and grant necessary permissions to /app and cache
|
| 52 |
+
RUN useradd -m -u 1000 user && \
|
| 53 |
+
chown -R user:user /app && \
|
| 54 |
+
mkdir -p /home/user/.cache && \
|
| 55 |
+
chown -R user:user /home/user/.cache && \
|
| 56 |
+
chmod -R 777 /app /tmp
|
| 57 |
+
|
| 58 |
+
# Switch to non-root user for Hugging Face Spaces compatibility
|
| 59 |
+
USER user
|
| 60 |
+
|
| 61 |
+
# Expose standard Hugging Face port
|
| 62 |
EXPOSE 7860
|
| 63 |
|
| 64 |
# Run the Gradio interface
|