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.")