File size: 2,207 Bytes
d2bb954
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
# ── Hugging Face Spaces β€” Docker Runtime ─────────────────────────────────────
# Python 3.11 slim keeps the image lean while supporting all crewai deps.
FROM python:3.11.9-slim

# Prevent .pyc files and force unbuffered stdout/stderr (crucial for HF logs)
ENV PYTHONDONTWRITEBYTECODE=1 \
    PYTHONUNBUFFERED=1

WORKDIR /app

# ── System deps required by crewai / grpc / tiktoken ─────────────────────────
RUN apt-get update && apt-get install -y --no-install-recommends \
    build-essential \
    curl \
    git \
    libffi-dev \
    && rm -rf /var/lib/apt/lists/*

# ── Python deps (cached layer β€” only rebuilds when requirements.txt changes) ──
COPY requirements.txt .
RUN pip install --no-cache-dir --upgrade pip \
 && pip install --no-cache-dir -r requirements.txt

# ── Application files ─────────────────────────────────────────────────────────
COPY app.py .
COPY index.html .

# ── Memory file: pre-create so the container can write to it immediately ──────
# On HF Spaces the filesystem is ephemeral, but this ensures the file exists
# on first boot without any code-level FileNotFoundError.
RUN echo "[]" > /app/memory.json

# ── Hugging Face Spaces REQUIRES port 7860 ────────────────────────────────────
ENV PORT=7860
EXPOSE 7860

# ── Gunicorn config ───────────────────────────────────────────────────────────
# 1 worker + 8 threads  β†’ ideal for HF single-instance Spaces
# timeout 300           β†’ multi-agent CrewAI runs can take 2-4 min
# graceful-timeout 10   β†’ clean shutdown on redeploy
CMD exec gunicorn \
    --bind "0.0.0.0:7860" \
    --workers 1 \
    --threads 8 \
    --timeout 300 \
    --graceful-timeout 10 \
    --log-level info \
    --access-logfile - \
    --error-logfile - \
    app:app