Aniruddha7 commited on
Commit
4546914
·
1 Parent(s): de36225

fix: remove Ollama+model from image, shrink from 4GB to 500MB for HF stability

Browse files
Files changed (2) hide show
  1. Dockerfile +6 -31
  2. start_hf.sh +6 -39
Dockerfile CHANGED
@@ -1,16 +1,16 @@
1
- # Dockerfile for Hugging Face Spaces
 
 
2
  FROM python:3.11-slim
3
 
4
  # Prevent Python from writing pyc files and buffering stdout/stderr
5
  ENV PYTHONDONTWRITEBYTECODE=1
6
  ENV PYTHONUNBUFFERED=1
7
- ENV USE_HF_CLOUD=1
8
 
9
- # Pre-set Ollama model directory so the build-time pull goes to the right place
10
- ENV OLLAMA_MODELS=/app/ollama_models
11
- ENV HOME=/app
12
 
13
- # Install system dependencies
14
  RUN apt-get update && apt-get install -y \
15
  curl \
16
  zstd \
@@ -20,31 +20,6 @@ RUN apt-get update && apt-get install -y \
20
  libpq-dev \
21
  && rm -rf /var/lib/apt/lists/*
22
 
23
- # Install latest Ollama via official install script
24
- # (replaces the pinned v0.5.11 which cannot pull qwen3.5:2b)
25
- RUN curl -fsSL https://ollama.ai/install.sh | sh
26
-
27
- # Pre-bake qwen3.5:2b vision model into the image at build time.
28
- # The model will be stored in /app/ollama_models and available
29
- # immediately when the container starts — no runtime pull needed.
30
- RUN mkdir -p /app/ollama_models && \
31
- OLLAMA_MODELS=/app/ollama_models ollama serve > /tmp/ollama_build.log 2>&1 & \
32
- OLLAMA_PID=$! && \
33
- echo "[BUILD] Waiting for Ollama to start (PID=$OLLAMA_PID)..." && \
34
- for i in $(seq 1 30); do \
35
- if curl -s http://localhost:11434/api/tags > /dev/null 2>&1; then \
36
- echo "[BUILD] Ollama is ready."; break; \
37
- fi; \
38
- echo "[BUILD] Waiting... ($i/30)"; \
39
- sleep 2; \
40
- done && \
41
- echo "[BUILD] Pulling qwen3.5:2b into image layers..." && \
42
- OLLAMA_MODELS=/app/ollama_models ollama pull qwen3.5:2b && \
43
- echo "[BUILD] Model pull complete. Stopping build-time Ollama..." && \
44
- kill $OLLAMA_PID 2>/dev/null || true && \
45
- wait $OLLAMA_PID 2>/dev/null || true && \
46
- echo "[BUILD] qwen3.5:2b pre-baked successfully."
47
-
48
  WORKDIR /app
49
 
50
  # Install Python dependencies
 
1
+ # ☁️ Dockerfile for Hugging Face Spaces — Cloud-Only (Lightweight)
2
+ # Image size: ~500MB (no Ollama, no local models)
3
+ # All LLM inference is handled by Groq API and HF Inference API via USE_HF_CLOUD=1
4
  FROM python:3.11-slim
5
 
6
  # Prevent Python from writing pyc files and buffering stdout/stderr
7
  ENV PYTHONDONTWRITEBYTECODE=1
8
  ENV PYTHONUNBUFFERED=1
 
9
 
10
+ # Cloud mode: all LLM calls go to Groq / HF Inference — no local Ollama needed
11
+ ENV USE_HF_CLOUD=1
 
12
 
13
+ # Install system dependencies (Tesseract for OCR fallback only)
14
  RUN apt-get update && apt-get install -y \
15
  curl \
16
  zstd \
 
20
  libpq-dev \
21
  && rm -rf /var/lib/apt/lists/*
22
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
23
  WORKDIR /app
24
 
25
  # Install Python dependencies
start_hf.sh CHANGED
@@ -1,45 +1,10 @@
1
  #!/bin/bash
2
 
3
- # Cloud-Optimized Startup Script for Hugging Face Spaces
4
- # Model is pre-baked into the image — no runtime pull needed.
 
5
 
6
- # 0. Start Ollama server
7
- echo "[HF-INIT] Starting Ollama server..."
8
- export HOME=/app
9
- export OLLAMA_HOST=0.0.0.0:11434
10
- export OLLAMA_MODELS=/app/ollama_models
11
-
12
- ollama serve > /app/ollama.log 2>&1 &
13
-
14
- # Wait for Ollama to be ready
15
- echo "[HF-INIT] Waiting for Ollama to start..."
16
- for i in {1..20}; do
17
- if curl -s http://localhost:11434/api/tags > /dev/null 2>&1; then
18
- echo "[HF-INIT] Ollama is ready."
19
- break
20
- fi
21
- if [ $i -eq 10 ]; then
22
- echo "[HF-INIT] Still waiting — Ollama log:"
23
- cat /app/ollama.log
24
- fi
25
- echo "[HF-INIT] Waiting... ($i/20)"
26
- sleep 2
27
- done
28
-
29
- # Verify the pre-baked model is present before starting the app.
30
- # If it is missing for any reason, pull it now (blocking, so app waits).
31
- echo "[HF-INIT] Verifying qwen3.5:2b is available..."
32
- if ollama list 2>/dev/null | grep -q "qwen3.5:2b"; then
33
- echo "[HF-INIT] qwen3.5:2b confirmed present."
34
- else
35
- echo "[HF-INIT] WARNING: qwen3.5:2b not found in pre-baked layers. Pulling now..."
36
- ollama pull qwen3.5:2b
37
- if [ $? -eq 0 ]; then
38
- echo "[HF-INIT] Pull succeeded."
39
- else
40
- echo "[HF-INIT] ERROR: Pull failed. Vision Q&A will not work."
41
- fi
42
- fi
43
 
44
  # 1. Start Backend Worker
45
  echo "[HF-INIT] Starting Backend Worker on port 8700..."
@@ -53,5 +18,7 @@ python -m uvicorn "Agent.mcp_server:app" --host 0.0.0.0 --port 8701 &
53
  echo "[HF-INIT] Starting Web UI on port 7860..."
54
  python -m uvicorn "web.app:app" --host 0.0.0.0 --port 7860 &
55
 
 
 
56
  # Keep the container alive
57
  wait
 
1
  #!/bin/bash
2
 
3
+ # ☁️ Cloud-Only Startup Script for Hugging Face Spaces
4
+ # All LLM calls are routed to Groq and HF Inference APIs via USE_HF_CLOUD=1
5
+ # Ollama is NOT used — image is kept lightweight to prevent HF storage purges.
6
 
7
+ echo "[HF-INIT] ===== Application Startup at $(date -u '+%Y-%m-%d %H:%M:%S') ====="
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8
 
9
  # 1. Start Backend Worker
10
  echo "[HF-INIT] Starting Backend Worker on port 8700..."
 
18
  echo "[HF-INIT] Starting Web UI on port 7860..."
19
  python -m uvicorn "web.app:app" --host 0.0.0.0 --port 7860 &
20
 
21
+ echo "[HF-INIT] All services started. Container is live."
22
+
23
  # Keep the container alive
24
  wait