File size: 1,147 Bytes
677d337
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
30
31
32
33
34
35
36
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.")