# 使用官方 Python 镜像作为基础镜像 (需要 Python >= 3.10) FROM python:3.12-slim # 设置工作目录 WORKDIR /app # 复制 requirements.txt 并安装依赖 (这步会利用缓存,如果 requirements.txt 未变则不会重新安装) COPY requirements.txt . RUN pip install --no-cache-dir -r requirements.txt # 复制整个项目 (这步在依赖安装之后,项目文件变化不会影响依赖缓存) COPY . /app # 暴露 FastAPI 应用运行的端口 # HF Spaces 会自动设置 PORT 环境变量,这里使用 7860 作为默认或示例端口 EXPOSE 7860 # 定义启动命令 CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "7860", "--workers", "2"]