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 authPROJECT_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 languagedef 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:
In these examples, click the βOpen in Colabβ link:
π‘ You may directly create a recent notebook by opening the colab.recent URL.