|
import streamlit as st |
|
from transformers import pipeline |
|
|
|
st.title("Text Sentiment Analysis App") |
|
st.write("Analyze whether a given text is positive or negative using a Hugging Face model.") |
|
|
|
user_input = st.text_area("Enter your text:", placeholder="For example: I love this product!") |
|
|
|
|
|
@st.cache_resource |
|
def load_sentiment_model(): |
|
return pipeline("sentiment-analysis", model="distilbert-base-uncased-finetuned-sst-2-english") |
|
|
|
|
|
model = load_sentiment_model() |
|
|
|
|
|
if st.button("Analyze"): |
|
if user_input.strip(): |
|
with st.spinner("Analyzing sentiment..."): |
|
result = model(user_input) |
|
st.success("Analysis complete!") |
|
|
|
|
|
label = result[0]['label'] |
|
score = result[0]['score'] |
|
|
|
|
|
st.write(f"**Label:** {label}") |
|
st.write(f"**Confidence Score:** {score:.2f}") |
|
|
|
else: |
|
st.error("Please enter some text!") |
|
|