StoryTime / app.py
yashkens's picture
some fixes
fad8b51
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.")