Spaces:
Build error
Build error
Download app1.py from Dazzler007/SentimentDetector: direct link, hf CLI and curl.
- Browser
- Download file 1.02 kB
-
https://huggingface.co/spaces/Dazzler007/SentimentDetector/resolve/main/app1.py
- Command line
-
hf download hf://spaces/Dazzler007/SentimentDetector/app1.py
-
curl -L -o app1.py https://huggingface.co/spaces/Dazzler007/SentimentDetector/resolve/main/app1.py
1.02 kB
| import streamlit as st | |
| from transformers import pipeline, AutoConfig | |
| # Initialize the sentiment analysis pipeline | |
| pipe = pipeline('sentiment-analysis') | |
| # App Title | |
| st.title("AI in Marketing | AI Driven | Text to Sentiment Analysis App | by Darren Field") | |
| #st.text("Enter your text and click the 'Analyze Sentiment' button to submit.") | |
| # Get the model name | |
| model_name = pipe.model.name_or_path | |
| # Get more detailed information about the model | |
| config = AutoConfig.from_pretrained(model_name) | |
| # Text input area | |
| text = st.text_area('Enter text including your sentiment.') | |
| # Submit button | |
| if st.button('Analyze Sentiment'): | |
| if text: | |
| out = pipe(text) | |
| st.json(out) | |
| # Check if sentiment is positive and display balloons | |
| if out[0]['label'] == 'POSITIVE': | |
| st.balloons() | |
| st.success("Positive sentiment detected! 🎉") | |
| else: | |
| st.info("Sentiment is not positive.") | |
| else: | |
| st.warning("Please enter some text before analyzing.") | |