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)