File size: 1,258 Bytes
7036414
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import streamlit as st

# --- Define lists of positive and negative words ---
positive_words = [
    "good", "great", "awesome", "fantastic", "amazing", "love", "nice", "happy", "excellent", "positive", "wonderful"
]

negative_words = [
    "bad", "terrible", "awful", "worst", "hate", "horrible", "sad", "angry", "disappointing", "negative", "poor"
]

# --- Streamlit UI ---
st.set_page_config(page_title="Sentiment Analyzer", layout="centered")
st.title("🧠 Rule-based Sentiment Analyzer")
st.markdown("This app performs sentiment analysis **without any machine learning model**, based on keywords.")

text = st.text_area("✍️ Enter your sentence here:", height=150)

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"
    elif neg_count > pos_count:
        return "😠 Negative"
    else:
        return "😐 Neutral"

if st.button("🔍 Analyze Sentiment"):
    if text.strip() == "":
        st.warning("Please enter some text.")
    else:
        result = analyze_sentiment(text)
        st.subheader("📊 Sentiment Result:")
        st.success(result)