简体   繁体   English

有没有办法将 TextBlob 语料库下载到 Google Cloud Run?

[英]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.

相关问题 python -m textblob.download_corpora => 没有名为 textblob 的模块 - python -m textblob.download_corpora => No module named textblob python -m textblob.download_corpora-CERTIFICATE_VERIFY_FAILED - python -m textblob.download_corpora - CERTIFICATE_VERIFY_FAILED 在 Anaconda 环境中安装 textblob.download_corpora 时出错 - Error installing textblob.download_corpora in Anaconda environment 在 AWS Lambda Python function 中运行时,NLTK 语料库下载挂起 - NLTK corpora download is hanging when run in AWS Lambda Python function Python NLP:使用 TextBlob、StanfordNLP 或 Google Cloud 识别句子的时态 - Python NLP: identifying the tense of a sentence using TextBlob, StanfordNLP or Google Cloud 添加后 nltk.download('words') 谷歌云运行 - After adding nltk.download('words') Google Cloud Run 有没有办法使用加载的服务帐户访问 Cloud Run 中的谷歌表格? - Is there a way to use loaded Service Account to access google sheets in Cloud Run? 从 Google Cloud Run 执行日志记录的最简单方法 - Simplest way to perform logging from Google Cloud Run 有没有办法从谷歌云运行已经构建的 python API? - Is there a way to run an already-built python API from google cloud? 在 Google Cloud 上通过自动缩放运行 Python 24/7 脚本的最佳方式 - Best way to run Python 24/7 scripts with autoscaling on Google Cloud
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM