-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.py
More file actions
47 lines (37 loc) · 1.54 KB
/
Copy pathserver.py
File metadata and controls
47 lines (37 loc) · 1.54 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
42
43
44
45
46
47
"""
Emotion Detection Server
This script runs a Flask application that provides a web interface
for analyzing the emotions conveyed in a given text string.
"""
from flask import Flask, render_template, request
from EmotionDetection.emotion_detection import emotion_detector
app = Flask("Emotion Detection")
@app.route("/emotionDetector")
def sent_detector():
"""
Analyze the emotion of the provided text.
Retrieves the 'textToAnalyze' parameter from the GET request,
passes it to the emotion_detector function, and returns a formatted
string containing the emotion scores and dominant emotion.
"""
# Retrieve the text to analyze from the request arguments
text_to_analyze = request.args.get('textToAnalyze')
# Pass the text to the emotion_detector function and store the response
response = emotion_detector(text_to_analyze)
if response['dominant_emotion'] is None:
return "Invalid text! Please try again!"
# Return a formatted string with the emotion scores and dominant emotion
return (
f"For the given statement, the system response is 'anger': {response['anger']}, "
f"'disgust': {response['disgust']}, 'fear': {response['fear']}, "
f"'joy': {response['joy']} and 'sadness': {response['sadness']}. "
f"The dominant emotion is {response['dominant_emotion']}."
)
@app.route("/")
def render_index_page():
"""
Render the main application page.
"""
return render_template('index.html')
if __name__ == "__main__":
app.run(host="0.0.0.0", port=5000)