File size: 897 Bytes
eea8335
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import streamlit as st
from transformers import pipeline

st.set_page_config(page_title="Sentiment Analyzer", page_icon="💬")

# Load sentiment analysis pipeline
@st.cache_resource
def load_model():
    return pipeline("sentiment-analysis")

sentiment_analyzer = load_model()

st.title("💬 Sentiment Analysis App")
st.write("Enter some text and the model will predict its sentiment.")

# User input
user_input = st.text_area("Enter your text here:", height=150)

# Button to analyze sentiment
if st.button("Analyze Sentiment"):
    if user_input.strip() == "":
        st.warning("⚠️ Please enter some text.")
    else:
        with st.spinner("Analyzing..."):
            result = sentiment_analyzer(user_input)[0]
            label = result['label']
            score = result['score']
            st.success(f"**Sentiment:** {label}")
            st.info(f"**Confidence:** {score:.2f}")