FaizaRiaz's picture
Update app.py
591cd36 verified
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")