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.")