# Read the doc: https://huggingface.co/docs/hub/spaces-sdks-docker # Dockerfile for Qwen-VL PicExam API with CPU inference optimization FROM python:3.10-slim # 安装系统依赖 RUN apt-get update && apt-get install -y \ git \ wget \ curl \ build-essential \ && rm -rf /var/lib/apt/lists/* # 创建用户 RUN useradd -m -u 1000 user USER user ENV PATH="/home/user/.local/bin:$PATH" # 设置工作目录 WORKDIR /app # 设置环境变量优化内存使用 ENV PYTORCH_CUDA_ALLOC_CONF=max_split_size_mb:512 ENV TOKENIZERS_PARALLELISM=false ENV OMP_NUM_THREADS=4 ENV MKL_NUM_THREADS=4 # 复制并安装 Python 依赖 COPY --chown=user ./requirements.txt requirements.txt RUN pip install --no-cache-dir --upgrade pip && \ pip install --no-cache-dir --upgrade -r requirements.txt # 复制应用代码 COPY --chown=user . /app # 暴露端口 EXPOSE 7860 # 启动命令,增加内存和超时配置 CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860", "--timeout-keep-alive", "300", "--workers", "1"]