|
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': |
|
|
|
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}%") |
|
st.write(f"๐ฟ Sadness level: {sad:.2f}%") |
|
|
|
|
|
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) |
|
|
|
|
|
words = word_tokenize(text) |
|
if len(words) < 5: |
|
st.write("Isn't your story a bit too short?") |
|
rep_ratio = get_repetitions(words) |
|
if rep_ratio < 0.7: |
|
st.write("Seems too repetitive!") |
|
st.write(f"Repetition ratio: {rep_ratio:.2f}") |
|
|