AneelaFatima commited on
Commit
65d390d
Β·
verified Β·
1 Parent(s): 9609015

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +32 -0
app.py ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from textblob import TextBlob
3
+
4
+ # Streamlit page settings
5
+ st.set_page_config(page_title="Sentimental App", layout="centered")
6
+
7
+ # Title
8
+ st.title("😊 Sentimental App")
9
+ st.write("Analyze the sentiment of your text β€” positive, negative or neutral.")
10
+
11
+ # Input from user
12
+ user_input = st.text_area("Enter your text here:", height=150)
13
+
14
+ # Sentiment analysis function
15
+ def analyze_sentiment(text):
16
+ blob = TextBlob(text)
17
+ sentiment = blob.sentiment.polarity
18
+ if sentiment > 0:
19
+ return "Positive 😊"
20
+ elif sentiment < 0:
21
+ return "Negative 😠"
22
+ else:
23
+ return "Neutral 😐"
24
+
25
+ # Analyze button
26
+ if st.button("Analyze"):
27
+ if user_input.strip() == "":
28
+ st.warning("Please enter some text.")
29
+ else:
30
+ result = analyze_sentiment(user_input)
31
+ st.subheader("Sentiment Result:")
32
+ st.success(result)