aab / app.py
Balnur26's picture
added code
f931fb4
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!")
# Initialize the model
@st.cache_resource
def load_sentiment_model():
return pipeline("sentiment-analysis", model="distilbert-base-uncased-finetuned-sst-2-english")
# Load the model
model = load_sentiment_model()
# Perform analysis if input is provided
if st.button("Analyze"):
if user_input.strip():
with st.spinner("Analyzing sentiment..."):
result = model(user_input)
st.success("Analysis complete!")
# Extracting the label and score
label = result[0]['label']
score = result[0]['score']
# Display the result
st.write(f"**Label:** {label}")
st.write(f"**Confidence Score:** {score:.2f}")
else:
st.error("Please enter some text!")