[英]Is there a way to download TextBlob corpora to Google Cloud Run?
I am using Python with TextBlob for sentiment analysis.我正在使用 Python 和 TextBlob 进行情绪分析。 I want to deploy my app (build in Plotly Dash) to Google Cloud Run with Google Cloud Build (without using Docker).
我想使用 Google Cloud Build(不使用 Docker)将我的应用程序(在 Plotly Dash 中构建)部署到 Google Cloud Run。 When using locally on my virtual environment all goes fine, but after deploying it on the cloud the corpora is not downloaded.
在我的虚拟环境上本地使用时一切正常,但在将其部署到云上后,不会下载语料库。 Looking at the requriements.txt file, there was also no reference to this corpora.
查看 requriements.txt 文件,也没有对这个语料库的引用。
I have tried to add python -m textblob.download_corpora
to my requriements.txt file but it doesn't download when I deploy it.我尝试将
python -m textblob.download_corpora
添加到我的 requriements.txt 文件中,但在部署时它没有下载。 I have also tried to add我也尝试添加
import textblob
import subprocess
cmd = ['python','-m','textblob.download_corpora']
subprocess.run(cmd)
and和
import nltk
nltk.download('movie_reviews')
to my script (callbacks.py, I am using Plotly Dash to make my app), all without success.到我的脚本(callbacks.py,我正在使用 Plotly Dash 来制作我的应用程序),但都没有成功。
Is there a way to add this corpus to my requirements.txt file?有没有办法将此语料库添加到我的 requirements.txt 文件中? Or is there another workaround to download this corpus?
还是有另一种解决方法来下载这个语料库? How can I fix this?
我怎样才能解决这个问题?
Thanks in advance!提前致谢!
Vijay维杰
Since Cloud Run creates and destroys containers as needed for your traffic levels you'll want to embed your corpora in the pre-built container to ensure a fast cold start time (instead of downloading it when the container starts)由于 Cloud Run 根据流量级别的需要创建和销毁容器,您需要将语料库嵌入到预构建的容器中,以确保快速冷启动时间(而不是在容器启动时下载它)
The easiest way to do this is add another line inside of a docker file that downloads and installs the corpora at build time like so:最简单的方法是在 docker 文件中添加另一行,该文件在构建时下载并安装语料库,如下所示:
RUN python -m textblob.download_corpora
Here's a full docker file for your reference:这是一个完整的 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"]
Good luck, Josh祝你好运,乔什
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.