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

# Load the sentiment analysis pipeline
pipe = pipeline("text-classification", model="finiteautomata/bertweet-base-sentiment-analysis")

# Define a function to perform sentiment analysis
def analyze_sentiment(text):
    results = pipe(text)
    sentiment = results[0]['label']
    confidence = results[0]['score']
    return sentiment, confidence

# Create a Streamlit app
st.title("Sentiment Analysis App")

# Get the user input
text = st.text_input("Enter text for sentiment analysis")

# Perform sentiment analysis
sentiment, confidence = analyze_sentiment(text)

# Display the output
if sentiment == "POSITIVE":
    st.success(f"Sentiment: Positive, Confidence: {confidence:.2f}")
elif sentiment == "NEGATIVE":
    st.error(f"Sentiment: Negative, Confidence: {confidence:.2f}")
else:
    st.info(f"Sentiment: Neutral, Confidence: {confidence:.2f}")