import streamlit as st # Simple lists of positive and negative words positive_words = ["happy", "great", "excellent", "good", "nice", "love", "awesome", "fantastic", "amazing", "joy"] negative_words = ["sad", "bad", "terrible", "worst", "angry", "hate", "awful", "poor", "depressed", "upset"] # Title and description st.markdown("
Analyze your text without using any ML model — just Python!
", unsafe_allow_html=True) # Input text user_input = st.text_area("Enter your sentence:", height=150) # Function to count sentiment words def analyze_sentiment(text): words = text.lower().split() pos_count = sum(1 for word in words if word in positive_words) neg_count = sum(1 for word in words if word in negative_words) if pos_count > neg_count: return "Positive 😊", pos_count, neg_count elif neg_count > pos_count: return "Negative 😞", pos_count, neg_count else: return "Neutral 😐", pos_count, neg_count # Button and result if st.button("Analyze Sentiment"): if user_input.strip() == "": st.warning("Please enter some text.") else: sentiment, pos, neg = analyze_sentiment(user_input) st.markdown(f"**Sentiment:** {sentiment}") st.markdown(f"**Positive words found:** {pos}") st.markdown(f"**Negative words found:** {neg}")