JaveriaZia's picture
Create app.py
449e145 verified
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("<h1 style='color: #6A1B9A; text-align: center;'>Simple Sentiment Analyzer</h1>", unsafe_allow_html=True)
st.markdown("<p style='text-align: center;'>Analyze your text without using any ML model β€” just Python!</p>", 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}")