-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.py
37 lines (30 loc) · 1.27 KB
/
server.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
from flask import Flask, render_template, request
from SentimentAnalysis.sentiment_analysis import sentiment_analyzer
# Import Flas render_template, request from the flask pramework package : TODO
# Import the sentiment_analyzer function from the package created: TODO
#Initiate the flask app : TODO
app = Flask("Sentiment Analyzer")
@app.route("/sentimentAnalyzer")
def sent_analyzer():
''' This code receives the text from the HTML interface and
runs sentiment analysis over it using sentiment_analysis()
function. The output returned shows the label and its confidence
score for the provided text.
'''
# TODO
text_to_analyze = request.args.get('textToAnalyze')
response = sentiment_analyzer(text_to_analyze)
label = response['label']
score = response['score']
return "The given text has been identified as {} with a score of {}.".format(label.split('_')[1], score)
@app.route("/")
def render_index_page():
''' This function initiates the rendering of the main application
page over the Flask channel
'''
#TODO
return render_template('index.html')
if __name__ == "__main__":
''' This functions executes the flask app and deploys it on localhost:5000
'''#TODO
app.run(host="0.0.0.0", port=5000)