File size: 2,060 Bytes
6473b64
 
acfdc08
 
 
 
 
 
6473b64
acfdc08
 
 
 
0919a68
acfdc08
 
591cd36
acfdc08
591cd36
acfdc08
 
 
 
 
 
 
 
6473b64
acfdc08
 
 
 
 
 
 
 
 
6473b64
 
 
acfdc08
6473b64
 
 
 
 
 
acfdc08
6473b64
acfdc08
6473b64
acfdc08
6473b64
acfdc08
 
6473b64
acfdc08
 
6473b64
acfdc08
 
 
 
 
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import streamlit as st

# Page config
st.set_page_config(
    page_title="Sentiment Analysis",
    page_icon="πŸ’¬",
    layout="centered"
)

# Custom styles
st.markdown("""
    <style>
        .stTextArea textarea {
            height: 50px;
        }
        .result-box {
            padding: 0.5rem;
            border-radius: 0.5rem;
            margin-top: 0.5rem;
            text-align: center;
            font-size: 1.3rem;
        }
        .positive { background-color: #d4edda; color: #155724; }
        .negative { background-color: #f8d7da; color: #721c24; }
        .neutral { background-color: #fff3cd; color: #856404; }
    </style>
""", unsafe_allow_html=True)

# App title and intro
st.title("πŸ’¬ Sentiment Analysis App")
st.markdown("Predict sentiment using simple Python logic β€” no ML, just rule-based 😎")

# Input section
st.subheader("πŸ“ Enter your text")
user_input = st.text_area("", placeholder="Type or paste your sentence here...")

# Keywords
positive_words = ["good", "great", "happy", "excellent", "amazing", "love", "awesome", "fantastic", "positive", "nice"]
negative_words = ["bad", "sad", "terrible", "horrible", "hate", "awful", "worst", "angry", "negative", "poor"]

# Sentiment analysis function
def analyze_sentiment(text):
    text = text.lower()
    pos_count = sum(word in text for word in positive_words)
    neg_count = sum(word in text for word in negative_words)

    if pos_count > neg_count:
        return "😊 Positive", "positive"
    elif neg_count > pos_count:
        return "☹️ Negative", "negative"
    else:
        return "😐 Neutral", "neutral"

# Button & result
if st.button("πŸ” Analyze Sentiment"):
    if user_input.strip():
        sentiment, sentiment_class = analyze_sentiment(user_input)
        st.markdown(f'<div class="result-box {sentiment_class}">{sentiment}</div>', unsafe_allow_html=True)
    else:
        st.warning("⚠️ Please enter some text before analyzing.")

# Footer
st.markdown("---")
st.markdown("Made with ❀️ using Streamlit | Rule-based approach")