in language/main.py [0:0]
def run_language():
# Create a Cloud Natural Language client
client = language.LanguageServiceClient()
# Retrieve inputted text from the form and create document object
text = request.form['text']
document = types.Document(content=text, type=enums.Document.Type.PLAIN_TEXT)
# Retrieve response from Natural Language API's analyze_entities() method
response = client.analyze_entities(document)
entities = response.entities
# Retrieve response from Natural Language API's analyze_sentiment() method
response = client.analyze_sentiment(document)
sentiment = response.document_sentiment
# Return a Jinja2 HTML template of the homepage and pass the 'text', 'entities',
# and 'sentiment' variables to the frontend. These contain information retrieved
# from the Natural Language API.
return render_template('homepage.html', text=text, entities=entities, sentiment=sentiment)