Dhanrajtz5rt commited on
Commit
866751c
Β·
verified Β·
1 Parent(s): 8a825e9

Upload Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +68 -0
Dockerfile ADDED
@@ -0,0 +1,68 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # ════════════════════════════════════════════════════════════
2
+ # Qwen AI Chatbot β€” Docker Image for HuggingFace Spaces CPU
3
+ # Base: Python 3.11 slim | Port: 7860
4
+ # ════════════════════════════════════════════════════════════
5
+
6
+ FROM python:3.11-slim
7
+
8
+ # System dependencies
9
+ RUN apt-get update && apt-get install -y --no-install-recommends \
10
+ git \
11
+ ffmpeg \
12
+ libsm6 \
13
+ libxext6 \
14
+ libgl1-mesa-glx \
15
+ build-essential \
16
+ curl \
17
+ && apt-get clean \
18
+ && rm -rf /var/lib/apt/lists/*
19
+
20
+ # Create non-root user (required by HF Spaces)
21
+ RUN useradd -m -u 1000 user
22
+ USER user
23
+ ENV HOME=/home/user \
24
+ PATH=/home/user/.local/bin:$PATH
25
+
26
+ WORKDIR /home/user/app
27
+
28
+ # Install PyTorch CPU first (avoids downloading CUDA version)
29
+ RUN pip install --no-cache-dir --upgrade pip && \
30
+ pip install --no-cache-dir \
31
+ torch==2.4.1+cpu \
32
+ torchvision==0.19.1+cpu \
33
+ torchaudio==2.4.1+cpu \
34
+ --extra-index-url https://download.pytorch.org/whl/cpu
35
+
36
+ # Install other Python dependencies
37
+ COPY --chown=user requirements.txt .
38
+ RUN pip install --no-cache-dir -r requirements.txt
39
+
40
+ # Copy application code
41
+ COPY --chown=user . .
42
+
43
+ # Create necessary directories
44
+ RUN mkdir -p uploads static
45
+
46
+ # Pre-download the model during build (optional β€” comment out to download at runtime)
47
+ # This adds ~2GB to image size but avoids cold-start download time
48
+ # RUN python -c "from transformers import AutoModelForCausalLM, AutoTokenizer; \
49
+ # AutoTokenizer.from_pretrained('Qwen/Qwen3.5-0.8B', trust_remote_code=True); \
50
+ # AutoModelForCausalLM.from_pretrained('Qwen/Qwen3.5-0.8B', torch_dtype='float16', trust_remote_code=True)"
51
+
52
+ # Set environment variables
53
+ ENV PYTHONUNBUFFERED=1 \
54
+ TRANSFORMERS_CACHE=/home/user/.cache/huggingface \
55
+ HF_HOME=/home/user/.cache/huggingface \
56
+ TOKENIZERS_PARALLELISM=false \
57
+ OMP_NUM_THREADS=4 \
58
+ MKL_NUM_THREADS=4
59
+
60
+ # Expose port (HF Spaces requires 7860)
61
+ EXPOSE 7860
62
+
63
+ # Health check
64
+ HEALTHCHECK --interval=30s --timeout=30s --start-period=120s --retries=3 \
65
+ CMD curl -f http://localhost:7860/api/info || exit 1
66
+
67
+ # Launch server
68
+ CMD ["python", "app.py"]