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