add stats & joy/sadness level
Browse files
app.py
CHANGED
@@ -1,7 +1,7 @@
|
|
1 |
import streamlit as st
|
2 |
-
# from emoji import get_emoji
|
3 |
from emotions import get_emotion, get_sentiment_arc_evaluation
|
4 |
-
from
|
|
|
5 |
import nltk
|
6 |
nltk.download('punkt')
|
7 |
|
@@ -9,14 +9,35 @@ st.title("I don't even know what this is yet")
|
|
9 |
|
10 |
name = st.text_input('Who are you?', 'Right, who am I?')
|
11 |
text = st.text_area('Submit your stories', '''Words and symbols are meant to be here''')
|
12 |
-
emotion_result = get_emotion(text)
|
13 |
-
st.write(f"Overall emotion of your story: {emotion_result[0]['label']}")
|
14 |
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
20 |
|
21 |
-
|
22 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import streamlit as st
|
|
|
2 |
from emotions import get_emotion, get_sentiment_arc_evaluation
|
3 |
+
from stats import get_repetitions
|
4 |
+
from nltk.tokenize import sent_tokenize, word_tokenize
|
5 |
import nltk
|
6 |
nltk.download('punkt')
|
7 |
|
|
|
9 |
|
10 |
name = st.text_input('Who are you?', 'Right, who am I?')
|
11 |
text = st.text_area('Submit your stories', '''Words and symbols are meant to be here''')
|
|
|
|
|
12 |
|
13 |
+
if text != 'Words and symbols are meant to be here':
|
14 |
+
# emotions
|
15 |
+
emotion_result = get_emotion(text)
|
16 |
+
st.write(f"Overall emotion of your story: {emotion_result[0]['label']}")
|
17 |
+
joy, sad = 0, 0
|
18 |
+
for emo in emotion_result:
|
19 |
+
if emo['label'] == 'joy':
|
20 |
+
if emo['score'] > joy:
|
21 |
+
joy = emo['score']
|
22 |
+
elif emo['label'] == 'love':
|
23 |
+
if emo['score'] > joy:
|
24 |
+
joy = emo['score']
|
25 |
+
elif emo['label'] == 'sadness':
|
26 |
+
sad = emo['score']
|
27 |
+
st.write(f"Joy level: {joy:.2f}%\nSadness level: {sad:.2f}%")
|
28 |
|
29 |
+
# emotional arcs
|
30 |
+
sents = sent_tokenize(text)
|
31 |
+
emo_arc = []
|
32 |
+
for sent in sents:
|
33 |
+
emo_arc.append(emotion_result[0]['label'])
|
34 |
+
sentiment_arc_eval = get_sentiment_arc_evaluation(emo_arc)
|
35 |
+
st.write(f"Emotional arc of your story: {' - '.join(emo_arc)}")
|
36 |
+
st.write(sentiment_arc_eval)
|
37 |
+
|
38 |
+
# simple statistics
|
39 |
+
words = word_tokenize(text)
|
40 |
+
if len(words) < 5:
|
41 |
+
st.write("Isn't your story a bit too short?")
|
42 |
+
rep_ratio = get_repetitions(words)
|
43 |
+
st.write(f"Repetition ratio: {rep_ratio}")
|
stats.py
ADDED
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
1 |
+
def get_repetitions(words):
|
2 |
+
words = [w.lower() for w in words]
|
3 |
+
ratio = len(set(words))/len(words)
|
4 |
+
return ratio
|