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}`")