muqeet1234's picture
Update app.py
677d337 verified
import streamlit as st
from transformers import pipeline
# Title and description
st.title("Text Sentiment Analyzer")
st.markdown("Analyze the sentiment of your text using a pre-trained Hugging Face model.")
# Load the sentiment analysis pipeline
@st.cache_resource
def load_sentiment_model():
return pipeline("sentiment-analysis")
sentiment_model = load_sentiment_model()
# Input box for user-provided text
user_input = st.text_area("Enter text to analyze sentiment:", placeholder="Type something here...")
# Analyze button
if st.button("Analyze"):
if user_input.strip():
# Perform sentiment analysis
with st.spinner("Analyzing sentiment..."):
result = sentiment_model(user_input)
sentiment = result[0]["label"]
confidence = result[0]["score"]
# Display results
st.write(f"**Sentiment:** {sentiment}")
st.write(f"**Confidence Score:** {confidence:.2f}")
else:
st.warning("Please enter some text to analyze.")
# Footer
st.markdown("---")
st.markdown("Powered by [Hugging Face Transformers](https://huggingface.co/transformers/) and Streamlit.")