Skip to content

Instantly share code, notes, and snippets.

@rinormaloku
Created February 8, 2018 19:51
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 rinormaloku/42c152cb0f6de666a4be3981f02a0df9 to your computer and use it in GitHub Desktop.
Save rinormaloku/42c152cb0f6de666a4be3981f02a0df9 to your computer and use it in GitHub Desktop.
[Python/Falsk controller] Controller that produces polarity for sentences #python #k8smastery
from textblob import TextBlob
from flask import Flask, request, jsonify
app = Flask(__name__) #1
@app.route("/analyse/sentiment", methods=['POST']) #2
def analyse_sentiment():
sentence = request.get_json()['sentence'] #3
polarity = TextBlob(sentence).sentences[0].polarity #4
return jsonify( #5
sentence=sentence,
polarity=polarity
)
if __name__ == '__main__':
app.run(host='localhost', port=5000) #6
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment