Spaces:
Sleeping
Sleeping
| import streamlit as st | |
| from transformers import pipeline | |
| # Load the sentiment analysis pipeline | |
| sentiment_pipeline = pipeline("sentiment-analysis") | |
| # Streamlit interface | |
| st.title("Sentiment Analysis with Hugging Face Transformers") | |
| # Input text box | |
| user_input = st.text_area("Enter text to analyze sentiment:", "I love using Hugging Face transformers!") | |
| # Analyze sentiment button | |
| if st.button("Analyze Sentiment"): | |
| # Perform sentiment analysis | |
| result = sentiment_pipeline(user_input) | |
| # Display the result | |
| sentiment = result[0]['label'] | |
| confidence = result[0]['score'] | |
| st.write(f"Sentiment: **{sentiment}**") | |
| st.write(f"Confidence: **{confidence:.4f}**") | |
| # To run the Streamlit app, use the command: | |
| # streamlit run your_script_name.py | |