File size: 651 Bytes
f339f2c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import streamlit as st
from transformers import pipeline

# Load a pretrained sentiment-analysis model from Hugging Face
@st.cache_resource
def load_model():
    return pipeline("sentiment-analysis")

model = load_model()

# Streamlit UI
st.title("🧠 Sentiment Analysis App")
st.write("Type a sentence and find out if it’s Positive or Negative!")

user_input = st.text_area("Enter your text here 👇")

if st.button("Analyze Sentiment"):
    if user_input.strip():
        result = model(user_input)[0]
        st.success(f"**Label:** {result['label']} | **Score:** {result['score']:.2f}")
    else:
        st.warning("Please enter some text!")