Qwen3.5-0.8B-Chatbot / Dockerfile
Dhanrajtz5rt's picture
Upload Dockerfile
866751c verified
Raw History Blame Contribute Delete
2.34 kB
# ════════════════════════════════════════════════════════════
# Qwen AI Chatbot β€” Docker Image for HuggingFace Spaces CPU
# Base: Python 3.11 slim | Port: 7860
# ════════════════════════════════════════════════════════════
FROM python:3.11-slim
# System dependencies
RUN apt-get update && apt-get install -y --no-install-recommends \
git \
ffmpeg \
libsm6 \
libxext6 \
libgl1-mesa-glx \
build-essential \
curl \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*
# Create non-root user (required by HF Spaces)
RUN useradd -m -u 1000 user
USER user
ENV HOME=/home/user \
PATH=/home/user/.local/bin:$PATH
WORKDIR /home/user/app
# Install PyTorch CPU first (avoids downloading CUDA version)
RUN pip install --no-cache-dir --upgrade pip && \
pip install --no-cache-dir \
torch==2.4.1+cpu \
torchvision==0.19.1+cpu \
torchaudio==2.4.1+cpu \
--extra-index-url https://download.pytorch.org/whl/cpu
# Install other Python dependencies
COPY --chown=user requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
# Copy application code
COPY --chown=user . .
# Create necessary directories
RUN mkdir -p uploads static
# Pre-download the model during build (optional β€” comment out to download at runtime)
# This adds ~2GB to image size but avoids cold-start download time
# RUN python -c "from transformers import AutoModelForCausalLM, AutoTokenizer; \
# AutoTokenizer.from_pretrained('Qwen/Qwen3.5-0.8B', trust_remote_code=True); \
# AutoModelForCausalLM.from_pretrained('Qwen/Qwen3.5-0.8B', torch_dtype='float16', trust_remote_code=True)"
# Set environment variables
ENV PYTHONUNBUFFERED=1 \
TRANSFORMERS_CACHE=/home/user/.cache/huggingface \
HF_HOME=/home/user/.cache/huggingface \
TOKENIZERS_PARALLELISM=false \
OMP_NUM_THREADS=4 \
MKL_NUM_THREADS=4
# Expose port (HF Spaces requires 7860)
EXPOSE 7860
# Health check
HEALTHCHECK --interval=30s --timeout=30s --start-period=120s --retries=3 \
CMD curl -f http://localhost:7860/api/info || exit 1
# Launch server
CMD ["python", "app.py"]