Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
|
| 3 |
+
# --- Define lists of positive and negative words ---
|
| 4 |
+
positive_words = [
|
| 5 |
+
"good", "great", "awesome", "fantastic", "amazing", "love", "nice", "happy", "excellent", "positive", "wonderful"
|
| 6 |
+
]
|
| 7 |
+
|
| 8 |
+
negative_words = [
|
| 9 |
+
"bad", "terrible", "awful", "worst", "hate", "horrible", "sad", "angry", "disappointing", "negative", "poor"
|
| 10 |
+
]
|
| 11 |
+
|
| 12 |
+
# --- Streamlit UI ---
|
| 13 |
+
st.set_page_config(page_title="Sentiment Analyzer", layout="centered")
|
| 14 |
+
st.title("🧠 Rule-based Sentiment Analyzer")
|
| 15 |
+
st.markdown("This app performs sentiment analysis **without any machine learning model**, based on keywords.")
|
| 16 |
+
|
| 17 |
+
text = st.text_area("✍️ Enter your sentence here:", height=150)
|
| 18 |
+
|
| 19 |
+
def analyze_sentiment(text):
|
| 20 |
+
text = text.lower()
|
| 21 |
+
pos_count = sum(word in text for word in positive_words)
|
| 22 |
+
neg_count = sum(word in text for word in negative_words)
|
| 23 |
+
|
| 24 |
+
if pos_count > neg_count:
|
| 25 |
+
return "😄 Positive"
|
| 26 |
+
elif neg_count > pos_count:
|
| 27 |
+
return "😠 Negative"
|
| 28 |
+
else:
|
| 29 |
+
return "😐 Neutral"
|
| 30 |
+
|
| 31 |
+
if st.button("🔍 Analyze Sentiment"):
|
| 32 |
+
if text.strip() == "":
|
| 33 |
+
st.warning("Please enter some text.")
|
| 34 |
+
else:
|
| 35 |
+
result = analyze_sentiment(text)
|
| 36 |
+
st.subheader("📊 Sentiment Result:")
|
| 37 |
+
st.success(result)
|