Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
|
| 3 |
+
# Sample positive and negative word lists
|
| 4 |
+
positive_words = ["good", "great", "happy", "excellent", "love", "wonderful", "amazing", "nice", "awesome"]
|
| 5 |
+
negative_words = ["bad", "terrible", "sad", "hate", "horrible", "awful", "worst", "angry", "disappointed"]
|
| 6 |
+
|
| 7 |
+
def analyze_sentiment(text):
|
| 8 |
+
text = text.lower()
|
| 9 |
+
pos_count = sum(word in text for word in positive_words)
|
| 10 |
+
neg_count = sum(word in text for word in negative_words)
|
| 11 |
+
|
| 12 |
+
if pos_count > neg_count:
|
| 13 |
+
return "Positive 😊", pos_count, neg_count
|
| 14 |
+
elif neg_count > pos_count:
|
| 15 |
+
return "Negative 😞", pos_count, neg_count
|
| 16 |
+
else:
|
| 17 |
+
return "Neutral 😐", pos_count, neg_count
|
| 18 |
+
|
| 19 |
+
# Streamlit UI
|
| 20 |
+
st.title("Simple Sentiment Analyzer (No ML) 🧠")
|
| 21 |
+
st.write("This app detects sentiment using rule-based logic (no ML model).")
|
| 22 |
+
|
| 23 |
+
text_input = st.text_area("Enter your sentence here:")
|
| 24 |
+
|
| 25 |
+
if st.button("Analyze"):
|
| 26 |
+
if text_input.strip() == "":
|
| 27 |
+
st.warning("Please enter some text!")
|
| 28 |
+
else:
|
| 29 |
+
sentiment, pos, neg = analyze_sentiment(text_input)
|
| 30 |
+
st.subheader("Result:")
|
| 31 |
+
st.write(f"**Sentiment:** {sentiment}")
|
| 32 |
+
st.write(f"Positive Words: {pos}, Negative Words: {neg}")
|