Home Artificial Intelligence Using Google Cloud from Colab πŸ“¦οΈ Install dependencies πŸ”‘ Authenticate πŸ”“ Enable APIs 🀯 Use Google Cloud services πŸ“Š Profit from notebook advanced features ✨ Test it out πŸ‘‹ Have a good time!

Using Google Cloud from Colab πŸ“¦οΈ Install dependencies πŸ”‘ Authenticate πŸ”“ Enable APIs 🀯 Use Google Cloud services πŸ“Š Profit from notebook advanced features ✨ Test it out πŸ‘‹ Have a good time!

0
Using Google Cloud from Colab
πŸ“¦οΈ Install dependencies
πŸ”‘ Authenticate
πŸ”“ Enable APIs
🀯 Use Google Cloud services
πŸ“Š Profit from notebook advanced features
✨ Test it out
πŸ‘‹ Have a good time!

Google Colab is an incredible tool for Pythonistas. It may be used for a wide range of tasks, from quickly experimenting with Python code to sharing extensive data processing notebooks with the world. Colab runs on Google Cloud, which supplies you a lift when accessing cloud services because your code is running inside Google’s high performance network, and likewise offers an easy option to use Google Cloud services, letting you run powerful cloud workloads out of your browser.

Colab comes with a whole lot of preinstalled packages, including pandas, numpy, matplotlib, Flask, Pillow, tensorflow, and pytorch. You may install additional required dependencies as needed.

For instance, to research text with the ability of machine learning using the Natural Language API, install the google-cloud-language client library:

!pip install google-cloud-language>=2.9.1

To authenticate along with your Google Cloud account throughout the Colab notebook, use the authenticate_user method. A recent parameter helps you to specify your project ID:

from google.colab import auth

PROJECT_ID = "" # @param {type:"string"}

auth.authenticate_user(project_id=PROJECT_ID)

After this step:

  • πŸ‘ You might be authenticated for gcloud CLI commands.
  • πŸ‘ You might be also authenticated when using Google Cloud Python client libraries. Note that .
  • πŸ‘ Your default project is ready.
  • πŸ‘ Your notebook may also access your Google Drive, letting you ingest or generate your personal files.

Ensure required APIs are enabled. In our example, that’s the service language.googleapis.com:

!gcloud services enable language.googleapis.com

That’s it! You may now directly use the service by calling its Python client library:

from google.cloud import language

def analyze_text_sentiment(text: str) -> language.AnalyzeSentimentResponse:
client = language.LanguageServiceClient()
document = language.Document(
content=text,
type_=language.Document.Type.PLAIN_TEXT,
)
return client.analyze_sentiment(document=document)

# Input
text = "Python is a really readable language, ..." # @param {type:"string"}

# Send a request to the API
response = analyze_text_sentiment(text)

# Use the outcomes
print(response)

Colab is hosting a Jupyter notebook. I personally depict Colab because the β€œGoogle Drive of notebooks”. As notebooks have additional superpowers, this helps you to nicely process and visualize your data, comparable to tables, images, or charts.

In our example, the function show_text_sentiment gathers leads to a pandas DataFrame, which renders as a table:

Screencast showing successive text sentiment analyses with results displayed in a table

In these examples, click the β€œOpen in Colab” link:

πŸ’‘ You may directly create a recent notebook by opening the colab.recent URL.

LEAVE A REPLY

Please enter your comment!
Please enter your name here