-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.py
52 lines (40 loc) · 1.51 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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
"""
Emotion Detection Web Application
This modules creates a Flask web application that provides a user interface
for detecting emotions in text. The application uses the `emotion_detector`
function from the `EmotionDetection` package to analyze the input text and
returns the score of each emotion and the dominated emotion.
To run the application:
Run this script, and the Flask server will start on host `0.0.0.0` and port `5000`.
"""
from flask import Flask, render_template, request
from EmotionDetection.emotion_detection import emotion_detector
app = Flask("Emotion Detection")
def run_app():
"""
Main function to run the application.
"""
app.run(host="0.0.0.0", port=5000)
@app.route("/")
def render_index_page():
"""
Renders the index page of the web app.
"""
return render_template('index.html')
@app.route("/emotionDetector")
def get_emotion_detection():
"""
Analyzes the input text and return the results.
"""
text_to_analyze = request.args.get('textToAnalyze')
response = emotion_detector(text_to_analyze)
if response['dominant_emotion'] is None:
return 'Invalid text! Please try again!'
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']}."
)
if __name__ == '__main__':
run_app()