File size: 1,439 Bytes
21b66ec
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# Customs Compass — Hugging Face Spaces Docker image
# Bundles Ollama + Streamlit + the llama3.2:1b model so the deployed app
# has full LLM features (not just template fallback).

FROM python:3.11-slim

# ---- System dependencies ----
RUN apt-get update && apt-get install -y --no-install-recommends \
        curl \
        ca-certificates \
        bash \
        procps \
    && rm -rf /var/lib/apt/lists/*

# ---- Install Ollama ----
RUN curl -fsSL https://ollama.com/install.sh | sh

# ---- Set up the app ----
WORKDIR /app

# Install Python dependencies first (better Docker layer caching)
COPY requirements.txt /app/requirements.txt
RUN pip install --no-cache-dir --upgrade pip \
    && pip install --no-cache-dir -r /app/requirements.txt

# Pre-pull the model at build time so the container starts fast for users.
# llama3.2:1b is ~1.3 GB — small enough for HF Spaces free tier and fast
# enough on CPU to give responses in 10-25s instead of 60-90s.
RUN ollama serve & \
    OLLAMA_PID=$! && \
    sleep 5 && \
    ollama pull llama3.2:1b && \
    kill $OLLAMA_PID || true

# Copy the rest of the application
COPY . /app

# Make sure the entrypoint is executable
RUN chmod +x /app/entrypoint.sh

# Hugging Face Spaces expects the app on port 7860
ENV PORT=7860
ENV OLLAMA_HOST=0.0.0.0
ENV OLLAMA_URL=http://localhost:11434
ENV OLLAMA_MODEL=llama3.2:1b
ENV OLLAMA_KEEP_ALIVE=15m

EXPOSE 7860

ENTRYPOINT ["/app/entrypoint.sh"]