FaizaRiaz commited on
Commit
6473b64
·
verified ·
1 Parent(s): d1d89af

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +33 -0
app.py ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+
3
+ # Set up page
4
+ st.title("💬 Sentiment Analysis App (Rule-based)")
5
+ st.write("This app predicts the sentiment of your text using simple Python logic (no ML model).")
6
+
7
+ # Input text
8
+ user_input = st.text_area("Enter your text here:")
9
+
10
+ # Basic keyword lists
11
+ positive_words = ["good", "great", "happy", "excellent", "amazing", "love", "awesome", "fantastic", "positive", "nice"]
12
+ negative_words = ["bad", "sad", "terrible", "horrible", "hate", "awful", "worst", "angry", "negative", "poor"]
13
+
14
+ def analyze_sentiment(text):
15
+ text = text.lower()
16
+ pos_count = sum(word in text for word in positive_words)
17
+ neg_count = sum(word in text for word in negative_words)
18
+
19
+ if pos_count > neg_count:
20
+ return "😊 Positive"
21
+ elif neg_count > pos_count:
22
+ return "☹️ Negative"
23
+ else:
24
+ return "😐 Neutral"
25
+
26
+ # Analyze button
27
+ if st.button("Analyze"):
28
+ if user_input.strip():
29
+ result = analyze_sentiment(user_input)
30
+ st.subheader("Sentiment Result:")
31
+ st.success(result)
32
+ else:
33
+ st.warning("Please enter some text.")