Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save VioletVivirand/386ef6c1d7525f93e27b73d1587b9a7e to your computer and use it in GitHub Desktop.
Save VioletVivirand/386ef6c1d7525f93e27b73d1587b9a7e to your computer and use it in GitHub Desktop.
Revision list for Qwiklabs Lab: Classify Text into Categories with the Natural Language API (https://google.qwiklabs.com/focuses/1749?parent=catalog)
Revision list for Qwiklabs Lab: Classify Text into Categories with the Natural Language API (https://google.qwiklabs.com/focuses/1749?parent=catalog)
# Execute these otherwise it won't work
# Install Pip
sudo apt-get update && sudo apt-get install python3-pip
# Install Virtualenv
python3 -m pip install virtualenv
# Create a new virtual environment with Virtualenv
python3 -m virtualenv -p python3 venv
# Activate the new virtual environment
source ./venv/bin/activate
# Install dependencies
pip install google-cloud google-cloud-storage google-cloud-language google-cloud-bigquery
# Update this function with the following lines
def classify_text(article):
response = nl_client.classify_text(
document=language.types.Document(
content=article,
type="PLAIN_TEXT"
)
)
return response
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment