bert-sentiment-classifier / sentiment_analysis.py
santit96's picture
Now if model doesnt exist it is downloaded from huggingface. Update readme for huggingface deployment
1eb51e0
"""
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()