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

# Load the sentiment analysis pipeline from Hugging Face
nlp = pipeline("sentiment-analysis", model="distilbert-base-uncased-finetuned-sst-2-english")

# Streamlit app layout
st.title("Simple Sentiment Analysis")
st.write("This app uses a pre-trained model from Hugging Face to perform sentiment analysis on user input.")

# User input
user_input = st.text_area("Enter some text to analyze:", value="", height=150, max_chars=500)

if user_input:
    # Perform sentiment analysis on the user input
    result = nlp(user_input)

    # Display the sentiment analysis result
    sentiment = result[0]["label"]
    confidence = result[0]["score"]

    st.write(f"Sentiment: {sentiment}")
    st.write(f"Confidence: {confidence:.2f}")
else:
    st.write("Please enter some text to analyze.")