Spaces:
Sleeping
Sleeping
| import streamlit as st | |
| from textblob import TextBlob | |
| # Function to analyze sentiment using TextBlob | |
| def analyze_sentiment(text): | |
| blob = TextBlob(text) | |
| polarity = blob.sentiment.polarity | |
| subjectivity = blob.sentiment.subjectivity | |
| if polarity > 0: | |
| sentiment = "Positive π" | |
| elif polarity < 0: | |
| sentiment = "Negative π" | |
| else: | |
| sentiment = "Neutral π" | |
| return sentiment, polarity, subjectivity | |
| # Streamlit UI | |
| st.title("π§ Sentiment Analysis App (TextBlob)") | |
| st.write("Analyze the sentiment of your text using the TextBlob library.") | |
| # Input text | |
| user_input = st.text_area("βοΈ Enter your text here:") | |
| if st.button("Analyze Sentiment"): | |
| if not user_input.strip(): | |
| st.warning("β οΈ Please enter some text.") | |
| else: | |
| sentiment, polarity, subjectivity = analyze_sentiment(user_input) | |
| st.success(f"**Sentiment:** {sentiment}") | |
| st.info(f"π Polarity: `{polarity:.2f}` | π§ Subjectivity: `{subjectivity:.2f}`") | |