Spaces:
Build error
Build error
Download app.py from Dazzler007/SentimentDetector: direct link, hf CLI and curl.
- Browser
- Download file 1.92 kB
-
https://huggingface.co/spaces/Dazzler007/SentimentDetector/resolve/main/app.py
- Command line
-
hf download hf://spaces/Dazzler007/SentimentDetector/app.py
-
curl -L -o app.py https://huggingface.co/spaces/Dazzler007/SentimentDetector/resolve/main/app.py
1.92 kB
| import streamlit as st | |
| from transformers import pipeline, AutoConfig | |
| # Initialize the sentiment analysis pipeline | |
| pipe = pipeline('sentiment-analysis') | |
| # App Title | |
| st.title("Text to Sentiment") | |
| #st.text("Enter your text and click the 'Analyze Sentiment' button to submit.") | |
| # Display final score and quiz progress | |
| st.sidebar.write("About") | |
| st.sidebar.write(f"Sentiment Detector is a text to Sentiment Analysis app by Darren Field.") | |
| st.sidebar.write(f"Examples:") | |
| st.sidebar.write(f"The fish in the restaurant was not fresh") | |
| st.sidebar.write(f"The fish in the restaurant was very fresh") | |
| st.sidebar.write(f"The product's design feels cheap and lacks durability") | |
| st.sidebar.write(f"The product's design feels expensive and durable") | |
| st.sidebar.write(f"Customer service has been unresponsive, making it difficult to resolve issues.") | |
| st.sidebar.write(f"Customer service has been fast, making it easy to resolve issues.") | |
| st.sidebar.write(f"This simple app leverages AI to detect positive and negative sentiment in text. The text is scored and classified as either Positive or Negative sentiment.") | |
| st.sidebar.write(f"The concept can be extended or modifed to solve many requirements.") | |
| # 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. Postitive sentiments will be rewared with balloons') | |
| # 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.") | |