File size: 856 Bytes
f4f0513
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 model from Hugging Face
sentiment_analysis = pipeline("sentiment-analysis")

# Function to get sentiment prediction
def predict_sentiment(text):
    result = sentiment_analysis(text)
    label = result[0]['label']
    score = result[0]['score']
    return label, score

# Streamlit web app
def main():
    st.title("Sentiment Analysis App")

    # Input text area
    user_input = st.text_area("Enter text:", "Type or paste your text here...")

    # Button to trigger sentiment prediction
    if st.button("Predict Sentiment"):
        # Display the result
        sentiment_label, sentiment_score = predict_sentiment(user_input)
        st.write(f"Sentiment: {sentiment_label}, Score: {sentiment_score:.4f}")

# Run the app
if __name__ == "__main__":
    main()