faiqyy's picture
Update app.py
5b9aed3 verified
Raw History Blame Contribute Delete
1.17 kB
import streamlit as st
from textblob import TextBlob
# Streamlit UI
st.set_page_config(page_title="Text Sentiment Analyzer", layout="centered")
st.title("🧠 Sentiment Analyzer with Polarity & Subjectivity")
st.write("Enter your text to see sentiment label, polarity, and subjectivity.")
# Input
user_input = st.text_area("Enter your text here:", height=150)
# Analysis Function
def analyze_text(text):
blob = TextBlob(text)
polarity = blob.sentiment.polarity # -1 to +1
subjectivity = blob.sentiment.subjectivity # 0 to 1
if polarity > 0:
sentiment = "Positive 😊"
elif polarity < 0:
sentiment = "Negative 😞"
else:
sentiment = "Neutral 😐"
return sentiment, polarity, subjectivity
# Output
if st.button("Analyze Sentiment"):
if user_input.strip():
sentiment, polarity, subjectivity = analyze_text(user_input)
st.success(f"Sentiment: **{sentiment}**")
st.info(f"Polarity: `{polarity:.2f}` (βˆ’1 = Negative, +1 = Positive)")
st.info(f"Subjectivity: `{subjectivity:.2f}` (0 = Objective, 1 = Subjective)")
else:
st.warning("Please enter some text.")