-
Set up a project in google cloud using GCP console
- Create a new project
- Enable Google NL API
- Create a service account
- Download a private key as JSON
More infomation about GCP project https://cloud.google.com/resource-manager/docs/creating-managing-projects
-
Open Terminal and set the environment variable GOOGLE_APPLICATION_CREDENTIALS to downloaded JSON file's path.
For Linux or Mac
export GOOGLE_APPLICATION_CREDENTIALS="[PATH]"
For Windows
env:GOOGLE_APPLICATION_CREDENTIALS="[PATH]"
Change
[PATH]
with JSON file's location -
Install Pre-req libraries
pip install google-cloud-language
sometimes more based on other installed libraries. -
Run the
sample.py
in python environment opened from the terminal of step 2
Use bellow mentioned code to get the sentiment score of a txt file
python sentiment-analysis.py positive-sample.txt