Spaces:
Running
Running
更新 Dockerfile,安装 Spacy 及其模型;在 preprocess.py 中添加模型下载处理
Browse files- Dockerfile +6 -0
- preprocess.py +7 -1
Dockerfile
CHANGED
@@ -10,6 +10,8 @@ COPY . /app
|
|
10 |
# 安装所需的 Python 包
|
11 |
RUN pip install --no-cache-dir --upgrade -r /app/requirements.txt
|
12 |
|
|
|
|
|
13 |
|
14 |
# 公开 Gradio 默认的端口 7860
|
15 |
EXPOSE 7860
|
@@ -29,6 +31,10 @@ WORKDIR $HOME/app
|
|
29 |
COPY --chown=user . $HOME/app
|
30 |
|
31 |
|
|
|
|
|
|
|
|
|
32 |
# Get secret EXAMPLE and output it to /test at buildtime
|
33 |
RUN --mount=type=secret,id=HF_Token,mode=0444,required=true \
|
34 |
cat /run/secrets/HF_Token > $HOME/HF_Token
|
|
|
10 |
# 安装所需的 Python 包
|
11 |
RUN pip install --no-cache-dir --upgrade -r /app/requirements.txt
|
12 |
|
13 |
+
# 安装必要依赖
|
14 |
+
RUN pip install --no-cache-dir spacy
|
15 |
|
16 |
# 公开 Gradio 默认的端口 7860
|
17 |
EXPOSE 7860
|
|
|
31 |
COPY --chown=user . $HOME/app
|
32 |
|
33 |
|
34 |
+
# 下载 Spacy 模型
|
35 |
+
RUN python -m spacy download en_core_web_md
|
36 |
+
|
37 |
+
|
38 |
# Get secret EXAMPLE and output it to /test at buildtime
|
39 |
RUN --mount=type=secret,id=HF_Token,mode=0444,required=true \
|
40 |
cat /run/secrets/HF_Token > $HOME/HF_Token
|
preprocess.py
CHANGED
@@ -34,7 +34,13 @@ from us_stock import *
|
|
34 |
#spacy.require_gpu()
|
35 |
|
36 |
# 加载模型
|
37 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
38 |
|
39 |
# 检查是否使用 GPU
|
40 |
print("Is NPL GPU used Preprocessing.py:", spacy.prefer_gpu())
|
|
|
34 |
#spacy.require_gpu()
|
35 |
|
36 |
# 加载模型
|
37 |
+
try:
|
38 |
+
nlp = spacy.load("en_core_web_md")
|
39 |
+
except OSError:
|
40 |
+
print("Downloading model 'en_core_web_md'...")
|
41 |
+
from spacy.cli import download
|
42 |
+
download("en_core_web_md")
|
43 |
+
nlp = spacy.load("en_core_web_md")
|
44 |
|
45 |
# 检查是否使用 GPU
|
46 |
print("Is NPL GPU used Preprocessing.py:", spacy.prefer_gpu())
|