File size: 1,837 Bytes
9b8ba0e
107d15e
057e447
 
91f3fdd
107d15e
9b8ba0e
fa8f5a8
9b8ba0e
fad8b51
fa8f5a8
9b8ba0e
057e447
 
 
f6d175c
057e447
 
 
 
 
 
 
 
 
 
fad8b51
 
9b8ba0e
057e447
 
 
 
f6d175c
057e447
 
f6d175c
 
057e447
 
 
 
 
904421a
 
 
 
 
 
 
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
import streamlit as st
from emotions import get_emotion, get_sentiment_arc_evaluation
from stats import get_repetitions
from nltk.tokenize import sent_tokenize, word_tokenize
import nltk
nltk.download('punkt')

st.title("Strange Story Critique service")

# name = st.text_input('Who are you?', 'Right, who am I?')
text = st.text_area("Submit your story and I'll tell you my unprofessional opinion", '''Words and symbols are meant to be here''')

if text != 'Words and symbols are meant to be here':
    # emotions
    emotion_result = get_emotion(text)
    st.write(f"๐Ÿ”ฎ Overall emotion of your story: {emotion_result[0]['label']}")
    joy, sad = 0, 0
    for emo in emotion_result:
        if emo['label'] == 'joy':
            if emo['score'] > joy:
                joy = emo['score']
        elif emo['label'] == 'love':
            if emo['score'] > joy:
                joy = emo['score']
        elif emo['label'] == 'sadness':
            sad = emo['score']
    st.write(f"๐Ÿ˜ธ Joy level: {joy*100:.2f}%")
    st.write(f"๐Ÿ˜ฟ Sadness level: {sad*100:.2f}%")

    # emotional arcs
    sents = sent_tokenize(text)
    emo_arc = []
    for sent in sents:
        emotion_result = get_emotion(sent)
        emo_arc.append(emotion_result[0]['label'])
    sentiment_arc_eval = get_sentiment_arc_evaluation(emo_arc)
    st.write(f"๐Ÿ“ˆ Emotional arc of your story: {' - '.join(emo_arc)}")
    st.write('๐Ÿ“ˆ ' + sentiment_arc_eval)

    # simple statistics
    words = word_tokenize(text)
    if len(words) < 5:
        st.write("Isn't your story a bit too short?")
    if len(words) > 0:
        rep_ratio = get_repetitions(words)
        if rep_ratio < 0.7:
            st.write("Seems too repetitive!")
        st.write(f"Repetition ratio: {rep_ratio:.2f}")
    else:
        st.write("A story with no words? Interesting choice.")