BilalCode's picture
Create app.py
d449cbe verified
Raw
History Blame Contribute Delete
1.02 kB
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}`")