Hanxiaofeng123 commited on
Commit
e4dca24
·
verified ·
1 Parent(s): f623da8

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +19 -21
Dockerfile CHANGED
@@ -1,18 +1,11 @@
1
- FROM python:3.10 # 使用完整版本,不是 slim
2
 
3
  # 安装系统依赖
4
  RUN apt-get update && apt-get install -y \
5
  build-essential \
6
- curl \
7
- git \
8
- file \
9
  && rm -rf /var/lib/apt/lists/*
10
 
11
- # 安装 Git LFS
12
- RUN curl -s https://packagecloud.io/install/repositories/github/git-lfs/script.deb.sh | bash && \
13
- apt-get install -y git-lfs && \
14
- git lfs install
15
-
16
  # 安装 PyTorch
17
  RUN pip install torch==2.5.1 torchvision==0.20.1 --index-url https://download.pytorch.org/whl/cpu
18
 
@@ -24,15 +17,20 @@ RUN pip install -r requirements.txt
24
  COPY . /app
25
  WORKDIR /app
26
 
27
- # 初始化 Git 仓库并拉取 LFS 文件
28
- RUN git init && \
29
- git lfs install --local && \
30
- git add . && \
31
- git lfs pull
32
-
33
- # 验证文件
34
- RUN ls -la checkpoint/ && \
35
- ls -lh checkpoint/final_model_K_30.pth
36
-
37
- # 入口
38
- CMD ["python", "app.py"]
 
 
 
 
 
 
1
+ FROM python:3.10-slim
2
 
3
  # 安装系统依赖
4
  RUN apt-get update && apt-get install -y \
5
  build-essential \
6
+ wget \
 
 
7
  && rm -rf /var/lib/apt/lists/*
8
 
 
 
 
 
 
9
  # 安装 PyTorch
10
  RUN pip install torch==2.5.1 torchvision==0.20.1 --index-url https://download.pytorch.org/whl/cpu
11
 
 
17
  COPY . /app
18
  WORKDIR /app
19
 
20
+ # 创建 checkpoint 目录
21
+ RUN mkdir -p checkpoint
22
+
23
+ # 下载模型文件的脚本
24
+ RUN echo '#!/bin/sh\n\
25
+ if [ ! -f "checkpoint/final_model_K_30.pth" ]; then\n\
26
+ echo "下载模型文件..."\n\
27
+ wget -O checkpoint/final_model_K_30.pth \\\n\
28
+ "https://huggingface.co/spaces/Hanxiaofeng123/Deepcube/blob/main/checkpoint/final_model_K_30.pth"\n\
29
+ else\n\
30
+ echo "模型文件已存在"\n\
31
+ ls -lh checkpoint/final_model_K_30.pth\n\
32
+ fi' > /download_model.sh && \
33
+ chmod +x /download_model.sh
34
+
35
+ # 入口(先下载模型,再运行应用)
36
+ CMD ["sh", "-c", "/download_model.sh && python app.py"]