File size: 1,203 Bytes
93109de
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
"""
Sentiment analysis streamlit webpage
"""
import streamlit as st
from sentiment_classificator import classify_sentiment


def get_representative_emoji(sentiment: str) -> str:
    """
    From a sentiment return the representative emoji
    """
    if sentiment == 'positive':
        return "πŸ˜ƒ"
    elif sentiment == 'negative':
        return "😞"
    else:
        return "😐"


def main() -> None:
    """
    Build streamlit page for sentiment analysis
    """
    st.title("Sentiment Classification")

    # Initialize session state variables
    if 'enter_pressed' not in st.session_state:
        st.session_state.enter_pressed = False

    # Input text box and button
    input_text = st.text_input("Enter your text here:")
    button_clicked = st.button("Classify Sentiment")

    if button_clicked or st.session_state.enter_pressed:
        # Process the input text with the sentiment classifier
        sentiment = classify_sentiment(input_text)

        # Get the representative emoji
        emoji = get_representative_emoji(sentiment)

        # Show the response and emoji
        st.write(f"Sentiment: {sentiment.capitalize()} {emoji}")


if __name__ == "__main__":
    main()