import streamlit as st from transformers import pipeline # Page settings st.set_page_config(page_title="Sentiment Analysis App", page_icon="đŸ’Ŧ", layout="centered") # Custom CSS for styling st.markdown(""" """, unsafe_allow_html=True) # Load model @st.cache_resource def load_model(): return pipeline("sentiment-analysis") nlp = load_model() # Main container with st.container(): st.markdown("
", unsafe_allow_html=True) st.markdown("
đŸ’Ŧ Sentiment Analysis
", unsafe_allow_html=True) st.markdown("
Discover the sentiment behind your words!
", unsafe_allow_html=True) text = st.text_area("Enter your text here:", height=150, placeholder="Type your sentence...") if st.button("✨ Analyze Sentiment"): if not text.strip(): st.warning("Please enter some text to analyze.") else: with st.spinner("Analyzing..."): result = nlp(text) label = result[0]['label'] score = result[0]['score'] st.markdown("
", unsafe_allow_html=True) if label == "POSITIVE": st.markdown(f"🙂 Positive Sentiment
Confidence: {score:.2f}", unsafe_allow_html=True) elif label == "NEGATIVE": st.markdown(f"â˜šī¸ Negative Sentiment
Confidence: {score:.2f}", unsafe_allow_html=True) else: st.markdown(f"😐 Neutral Sentiment
Confidence: {score:.2f}", unsafe_allow_html=True) st.markdown("
", unsafe_allow_html=True) st.markdown("
", unsafe_allow_html=True)