Spaces:
Sleeping
Sleeping
File size: 1,020 Bytes
d449cbe | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | 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}`")
|