import streamlit as st from transformers import pipeline # Initialize the sentiment analysis pipeline sentiment_pipeline = pipeline("sentiment-analysis") # Streamlit app st.title("Sentiment Analysis with Hugging Face") # Text input user_input = st.text_area("Enter text for sentiment analysis:", "I love this product!") if st.button("Analyze Sentiment"): # Perform sentiment analysis result = sentiment_pipeline(user_input)[0] # Display results st.write(f"Sentiment: {result['label']}") st.write(f"Confidence: {result['score']:.4f}") # Visualize the sentiment if result['label'] == 'POSITIVE': st.success(f"Positive Sentiment (Score: {result['score']:.4f})") else: st.error(f"Negative Sentiment (Score: {result['score']:.4f})") # Add some information about the model st.info("This app uses the default sentiment analysis model from Hugging Face Transformers.")