File size: 920 Bytes
bdd8447
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import streamlit as st
from transformers import pipeline

# Initialize the sentiment analysis pipeline
sentiment_pipeline = pipeline("sentiment-analysis")

# Streamlit app
st.title("Sentiment Analysis with Hugging Face")

# Text input
user_input = st.text_area("Enter text for sentiment analysis:", "I love this product!")

if st.button("Analyze Sentiment"):
    # Perform sentiment analysis
    result = sentiment_pipeline(user_input)[0]
    
    # Display results
    st.write(f"Sentiment: {result['label']}")
    st.write(f"Confidence: {result['score']:.4f}")

    # Visualize the sentiment
    if result['label'] == 'POSITIVE':
        st.success(f"Positive Sentiment (Score: {result['score']:.4f})")
    else:
        st.error(f"Negative Sentiment (Score: {result['score']:.4f})")

# Add some information about the model
st.info("This app uses the default sentiment analysis model from Hugging Face Transformers.")