File size: 1,262 Bytes
df78000
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
f13132c
 
 
 
 
df78000
 
f4ca9de
df78000
7708334
 
 
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
FROM python:3.12-slim

ENV PYTHONUNBUFFERED=1
ENV PYTHONDONTWRITEBYTECODE=1

WORKDIR /app

# Install system dependencies needed for compiling and sqlite
RUN apt-get update && apt-get install -y --no-install-recommends \
    gcc g++ make cmake wget sqlite3 \
    && rm -rf /var/lib/apt/lists/*

RUN pip install --no-cache-dir llama-cpp-python --extra-index-url https://abetlen.github.io/llama-cpp-python/whl/cpu

# Install python packages (using the prebuilt CPU index to keep it fast)
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt --extra-index-url https://abetlen.github.io/llama-cpp-python/whl/cpu

# Create a models directory and pull the 350MB Qwen model from Hugging Face
RUN mkdir -p /app/models && \
    wget -O /app/models/qwen.gguf https://huggingface.co/Qwen/Qwen2.5-0.5B-Instruct-GGUF/resolve/main/qwen2.5-0.5b-instruct-q4_k_m.gguf

COPY . .

RUN mkdir -p /app/database
RUN useradd -m -u 1000 user && chown -R user:user /app

USER user

RUN python init_db.py

EXPOSE 7860

# Increase timeout to 5 minutes (--timeout 300) to allow slow CPU loading, 
# and use a single sync worker (-k sync) to avoid C-level thread conflicts.
CMD ["sh", "-c", "gunicorn -w 1 -k sync --timeout 300 --reload -b 0.0.0.0:${PORT:-7860} app:app"]