Spaces:
Sleeping
Sleeping
Download app.py from nassimzaari/testingspaces: direct link, hf CLI and curl.
- Browser
- Download file 920 Bytes
-
https://huggingface.co/spaces/nassimzaari/testingspaces/resolve/main/app.py
- Command line
-
hf download hf://spaces/nassimzaari/testingspaces/app.py
-
curl -L -o app.py https://huggingface.co/spaces/nassimzaari/testingspaces/resolve/main/app.py
920 Bytes
| 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.") | |