File size: 1,157 Bytes
ab26b91
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
FROM python:3.10-slim

# 安装系统依赖(CLIP 需要 git)
RUN apt-get update && apt-get install -y \
    git \
    build-essential \
    wget \
    && rm -rf /var/lib/apt/lists/*

WORKDIR /app

# 复制并安装 Python 依赖
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt

# 预下载 CLIP 模型(减少首次启动时间)
RUN python -c "import clip; clip.load('ViT-B/32', device='cpu')"

# 复制应用代码和数据
COPY api_server.py config.py llm.py rag.py ./
COPY amazon_multimodal_clean.csv .
COPY frontend/ ./frontend/

# 创建必要的目录
RUN mkdir -p images chromadb_store

# 在 Docker 构建时预先构建索引(避免每次启动都重建)
RUN python rag.py --build --csv amazon_multimodal_clean.csv

# 暴露 Hugging Face Spaces 端口
EXPOSE 7860

# 设置环境变量
ENV PYTHONUNBUFFERED=1
ENV API_HOST=0.0.0.0
ENV API_PORT=7860

# 健康检查(启动等待 120 秒给索引构建时间)
HEALTHCHECK --interval=30s --timeout=10s --start-period=120s --retries=3 \
    CMD wget --no-verbose --tries=1 --spider http://localhost:7860/health || exit 1

# 启动 FastAPI
CMD ["python", "-u", "api_server.py"]