sanitiment / app.py
usamaferoz12's picture
Create app.py
f2a367d
raw
history blame
No virus
910 Bytes
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}")