簡體   English   中英

有沒有辦法將 TextBlob 語料庫下載到 Google Cloud Run?

[英]Is there a way to download TextBlob corpora to Google Cloud Run?

我正在使用 Python 和 TextBlob 進行情緒分析。 我想使用 Google Cloud Build(不使用 Docker)將我的應用程序(在 Plotly Dash 中構建)部署到 Google Cloud Run。 在我的虛擬環境上本地使用時一切正常,但在將其部署到雲上后,不會下載語料庫。 查看 requriements.txt 文件,也沒有對這個語料庫的引用。

我嘗試將python -m textblob.download_corpora添加到我的 requriements.txt 文件中,但在部署時它沒有下載。 我也嘗試添加

import textblob
import subprocess
cmd = ['python','-m','textblob.download_corpora']
subprocess.run(cmd)

import nltk
nltk.download('movie_reviews')

到我的腳本(callbacks.py,我正在使用 Plotly Dash 來制作我的應用程序),但都沒有成功。

有沒有辦法將此語料庫添加到我的 requirements.txt 文件中? 還是有另一種解決方法來下載這個語料庫? 我怎樣才能解決這個問題?

提前致謝!

維傑

由於 Cloud Run 根據流量級別的需要創建和銷毀容器,您需要將語料庫嵌入到預構建的容器中,以確保快速冷啟動時間(而不是在容器啟動時下載它)

最簡單的方法是在 docker 文件中添加另一行,該文件在構建時下載並安裝語料庫,如下所示:

RUN python -m textblob.download_corpora 

這是一個完整的 docker 文件供您參考:

# Python image to use.
FROM python:3.8

# Set the working directory to /app
WORKDIR /app

# copy the requirements file used for dependencies
COPY requirements.txt .

# Install any needed packages specified in requirements.txt
RUN pip install --trusted-host pypi.python.org -r requirements.txt
RUN python -m textblob.download_corpora

# Copy the rest of the working directory contents into the container at /app
COPY . .

# Run app.py when the container launches
ENTRYPOINT ["python", "app.py"]

祝你好運,喬什

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM