Spaces:
Sleeping
Sleeping
| # 使用官方Python 3.10 slim镜像 | |
| FROM python:3.10-slim | |
| # 设置工作目录 | |
| WORKDIR /app | |
| # --- 1. 准备工作:安装git --- | |
| RUN apt-get update && apt-get install -y --no-install-recommends git | |
| # --- 2. 设置环境变量,解决缓存权限问题 --- | |
| ENV HF_HOME=/app/.cache | |
| ENV SENTENCE_TRANSFORMERS_HOME=/app/.cache | |
| # --- 3. 关键步骤:直接克隆到当前工作目录 --- | |
| RUN --mount=type=secret,id=GITHUB_TOKEN \ | |
| git clone --depth 1 https://oauth2access:$(cat /run/secrets/GITHUB_TOKEN)@github.com/leoncool23/ai-pharmacist-crew.git . | |
| # --- 4. 创建运行时需要写入的目录 --- | |
| RUN mkdir -p vector_store/faiss_index | |
| # --- 5. 设置Python环境 --- | |
| RUN pip install --no-cache-dir -r requirements.txt langchain-community langchain-google-genai langchain-huggingface | |
| # --- 6. 预缓存模型 --- | |
| RUN python -c "from sentence_transformers import SentenceTransformer; SentenceTransformer('sentence-transformers/all-MiniLM-L6-v2')" | |
| # --- 7. 关键修正:为所有运行时需要写入的目录赋予完全权限 --- | |
| # 这会一次性解决所有潜在的权限警告和错误 | |
| RUN chmod -R 777 /app/.cache /app/vector_store | |
| # --- 8. 运行应用 --- | |
| # 暴露 Hugging Face Spaces 期望的标准端口 7860 | |
| EXPOSE 7860 | |
| # CMD指令:先运行rag_setup.py创建向量库,然后启动Gradio应用 | |
| CMD python rag_setup.py && python app.py |