Soumik Bose commited on
Commit
f8893c3
·
1 Parent(s): eae003d
Files changed (1) hide show
  1. Dockerfile +36 -12
Dockerfile CHANGED
@@ -4,37 +4,61 @@ ENV PYTHONDONTWRITEBYTECODE=1 \
4
  PYTHONUNBUFFERED=1 \
5
  PORT=7860 \
6
  HF_HOME=/app/cache \
 
7
  PATH="/home/user/.local/bin:${PATH}"
8
 
9
  WORKDIR /app
10
 
11
- # Install build dependencies
 
12
  RUN apt-get update && apt-get install -y \
13
  build-essential \
14
  cmake \
15
  curl \
16
  git \
 
17
  && rm -rf /var/lib/apt/lists/*
18
 
19
- # Create user
20
- RUN useradd -m -u 1000 user
21
- RUN mkdir -p /app/cache /app/models && chown -R user:user /app
 
22
 
23
- # Install pip as root
24
  RUN pip install --no-cache-dir --upgrade pip
25
 
 
26
  USER user
27
 
28
- # Build and install llama-cpp-python with proper flags
29
- RUN CMAKE_ARGS="-DGGML_BLAS=OFF -DGGML_NATIVE=OFF" \
30
- pip install --no-cache-dir llama-cpp-python==0.3.2
 
 
 
31
 
32
- # Install other dependencies
33
  COPY --chown=user:user requirements.txt .
34
- RUN pip install --no-cache-dir -r requirements.txt
 
 
35
 
36
- # Copy app
 
37
  COPY --chown=user:user main.py .
 
 
 
 
 
 
 
 
 
 
 
38
 
39
  EXPOSE 7860
40
- CMD ["bash", "-c", "while true; do curl -s https://xce009-ai-chat-api.hf.space/ping > /dev/null || true; sleep 300; done & python -m uvicorn main:app --host 0.0.0.0 --port 7860"]
 
 
 
4
  PYTHONUNBUFFERED=1 \
5
  PORT=7860 \
6
  HF_HOME=/app/cache \
7
+ CPU_THREADS=2 \
8
  PATH="/home/user/.local/bin:${PATH}"
9
 
10
  WORKDIR /app
11
 
12
+ # Install system dependencies
13
+ # Note: We kept build-essential/cmake just in case, but they aren't strictly needed for pre-built wheels
14
  RUN apt-get update && apt-get install -y \
15
  build-essential \
16
  cmake \
17
  curl \
18
  git \
19
+ libgomp1 \
20
  && rm -rf /var/lib/apt/lists/*
21
 
22
+ # Create non-root user
23
+ RUN useradd -m -u 1000 user && \
24
+ mkdir -p /app/cache /app/models && \
25
+ chown -R user:user /app
26
 
27
+ # Upgrade pip as root
28
  RUN pip install --no-cache-dir --upgrade pip
29
 
30
+ # Switch to non-root user
31
  USER user
32
 
33
+ # ---------------------------------------------------------------------------
34
+ # FIX: Use pre-built wheels to avoid "Timed out wheel creation"
35
+ # This installs the latest version compatible with SmolVLM without compiling
36
+ # ---------------------------------------------------------------------------
37
+ RUN pip install --no-cache-dir --upgrade llama-cpp-python \
38
+ --extra-index-url https://abetlen.github.io/llama-cpp-python/whl/cpu
39
 
40
+ # Copy requirements and install dependencies
41
  COPY --chown=user:user requirements.txt .
42
+ # Remove llama-cpp-python from requirements.txt if it's there to prevent re-installation attempts
43
+ RUN sed -i '/llama-cpp-python/d' requirements.txt && \
44
+ pip install --no-cache-dir --user -r requirements.txt
45
 
46
+ # Copy application structure
47
+ COPY --chown=user:user config.py .
48
  COPY --chown=user:user main.py .
49
+ COPY --chown=user:user models/ ./models/
50
+ COPY --chown=user:user services/ ./services/
51
+ COPY --chown=user:user routers/ ./routers/
52
+ COPY --chown=user:user utils/ ./utils/
53
+
54
+ # Create __init__.py files if they don't exist
55
+ RUN touch models/__init__.py services/__init__.py routers/__init__.py utils/__init__.py
56
+
57
+ # Health check
58
+ HEALTHCHECK --interval=30s --timeout=10s --start-period=60s --retries=3 \
59
+ CMD curl -f http://localhost:7860/ping || exit 1
60
 
61
  EXPOSE 7860
62
+
63
+ # Production startup
64
+ CMD ["bash", "-c", "while true; do curl -s http://localhost:7860/ping > /dev/null 2>&1 || true; sleep 300; done & exec python -m uvicorn main:app --host 0.0.0.0 --port 7860 --log-level info"]