Skip to content

Instantly share code, notes, and snippets.

@brianray
Created June 1, 2019 16:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brianray/9c4ba626f7d66a0ddb419a4554d02646 to your computer and use it in GitHub Desktop.
Save brianray/9c4ba626f7d66a0ddb419a4554d02646 to your computer and use it in GitHub Desktop.
from google.cloud import language
from google.cloud.language import enums
from google.cloud.language import types
def analyze(request):
request_json = request.get_json()
client = language.LanguageServiceClient()
sentance = request_json['content']
document = types.Document(
content=sentance,
type=enums.Document.Type.PLAIN_TEXT)
annotations = client.analyze_sentiment(
document=document)
return str(annotations.document_sentiment.score)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment