Created
February 8, 2018 19:51
-
-
Save rinormaloku/42c152cb0f6de666a4be3981f02a0df9 to your computer and use it in GitHub Desktop.
[Python/Falsk controller] Controller that produces polarity for sentences #python #k8smastery
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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