StoryTime / app.py
yashkens's picture
add stats & joy/sadness level
057e447
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("I don't even know what this is yet")
name = st.text_input('Who are you?', 'Right, who am I?')
text = st.text_area('Submit your stories', '''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:.2f}%\nSadness level: {sad:.2f}%")
# emotional arcs
sents = sent_tokenize(text)
emo_arc = []
for sent in sents:
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?")
rep_ratio = get_repetitions(words)
st.write(f"Repetition ratio: {rep_ratio}")