-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.py
More file actions
41 lines (36 loc) · 1.49 KB
/
server.py
File metadata and controls
41 lines (36 loc) · 1.49 KB
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
38
39
40
41
''' Executing this function initiates the application of sentiment
analysis to be executed over the Flask channel and deployed on
localhost:5000.
'''
from flask import Flask, render_template, request
from EmotionDetection.emotion_detection import emotion_detector
app = Flask("Emotion Analyzer")
@app.route("/emotionDetector")
def sent_analyzer():
''' This code receives the text from the HTML interface and
runs emotion analysis over it using emotion_detector()
function. The output returned shows the label and its confidence
score for the provided text.
'''
text_to_analyze = request.args.get('textToAnalyze')
response = emotion_detector(text_to_analyze)
anger = response['anger']
disgust = response['disgust']
fear = response['fear']
joy = response['joy']
sadness = response['sadness']
dominant_emotion = response['dominant_emotion']
if dominant_emotion is None:
return "Invalid text! Please try again!."
else:
return (f"For the given statement, the system response is 'anger': {anger}, "
f"'disgust': {disgust}, 'fear': {fear}, 'joy': {joy} and 'sadness': {sadness}.")
@app.route("/")
def render_index_page():
''' This function initiates the rendering of the main application
page over the Flask channel
'''
return render_template('index.html')
if __name__ == "__main__":
''' This functions executes the flask app and deploys it on localhost:5000'''
app.run(host="0.0.0.0", port=5002)